{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-05-14T21:28:19.780120Z","iopub.execute_input":"2023-05-14T21:28:19.780550Z","iopub.status.idle":"2023-05-14T21:28:20.036698Z","shell.execute_reply.started":"2023-05-14T21:28:19.780516Z","shell.execute_reply":"2023-05-14T21:28:20.035687Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport plotly.express as px\nfrom sklearn.decomposition import PCA\nimport plotly.graph_objects as go\nimport matplotlib.pyplot as plt\nimport multiprocessing\nfrom sklearn.model_selection import learning_curve","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:28:20.038423Z","iopub.execute_input":"2023-05-14T21:28:20.038956Z","iopub.status.idle":"2023-05-14T21:28:21.924548Z","shell.execute_reply.started":"2023-05-14T21:28:20.038923Z","shell.execute_reply":"2023-05-14T21:28:21.923538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_meta = pd.read_parquet('/kaggle/input/icecube-neutrinos-in-deep-ice/train_meta.parquet')\ntrain_meta.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:28:21.927002Z","iopub.execute_input":"2023-05-14T21:28:21.927493Z","iopub.status.idle":"2023-05-14T21:29:08.559664Z","shell.execute_reply.started":"2023-05-14T21:28:21.927458Z","shell.execute_reply":"2023-05-14T21:29:08.558505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Total number of events: ' + str(len(train_meta)))","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:08.561033Z","iopub.execute_input":"2023-05-14T21:29:08.561413Z","iopub.status.idle":"2023-05-14T21:29:08.568906Z","shell.execute_reply.started":"2023-05-14T21:29:08.561380Z","shell.execute_reply":"2023-05-14T21:29:08.567423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_batch_1 = pd.read_parquet('/kaggle/input/icecube-neutrinos-in-deep-ice/train/batch_1.parquet')\ntrain_batch_1.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:08.572747Z","iopub.execute_input":"2023-05-14T21:29:08.573624Z","iopub.status.idle":"2023-05-14T21:29:12.250820Z","shell.execute_reply.started":"2023-05-14T21:29:08.573585Z","shell.execute_reply":"2023-05-14T21:29:12.249761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print('Number of pulses: ' + str(len(train_batch_1)))\nprint('Number of events: ' + str(len(train_batch_1.index.unique())))","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:12.252805Z","iopub.execute_input":"2023-05-14T21:29:12.253638Z","iopub.status.idle":"2023-05-14T21:29:12.878394Z","shell.execute_reply.started":"2023-05-14T21:29:12.253597Z","shell.execute_reply":"2023-05-14T21:29:12.877282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sensor_geometry = pd.read_csv('/kaggle/input/icecube-neutrinos-in-deep-ice/sensor_geometry.csv')\nsensor_geometry.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:12.879890Z","iopub.execute_input":"2023-05-14T21:29:12.880273Z","iopub.status.idle":"2023-05-14T21:29:12.917763Z","shell.execute_reply.started":"2023-05-14T21:29:12.880240Z","shell.execute_reply":"2023-05-14T21:29:12.916480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.scatter(sensor_geometry.x, sensor_geometry.y)","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:12.919578Z","iopub.execute_input":"2023-05-14T21:29:12.919920Z","iopub.status.idle":"2023-05-14T21:29:13.247069Z","shell.execute_reply.started":"2023-05-14T21:29:12.919891Z","shell.execute_reply":"2023-05-14T21:29:13.245058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = px.scatter_3d(sensor_geometry, x='x', y='y', z='z', opacity=0.5)\nfig.update_traces(marker_size=2)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:13.250198Z","iopub.execute_input":"2023-05-14T21:29:13.250889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_meta = pd.read_parquet('/kaggle/input/icecube-neutrinos-in-deep-ice/test_meta.parquet')\ntest_meta = pd.read_parquet('/kaggle/input/icecube-neutrinos-in-deep-ice/test_meta.parquet')\ntest_meta.head()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(test_meta))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"case_event_idx = 3\ncase_event_pulses = train_batch_1.iloc[train_meta.iloc[case_event_idx].first_pulse_index.astype(int) : \n                                         train_meta.iloc[case_event_idx].last_pulse_index.astype(int)+1].copy()\nprint(len(case_event_pulses))\ncase_event_pulses.tail()","metadata":{"execution":{"iopub.execute_input":"2023-05-14T21:29:15.680304Z","iopub.status.idle":"2023-05-14T21:29:15.707680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"case_event_pulses = case_event_pulses.reset_index()\ncase_event_pulses[['x', 'y', 'z']] = sensor_geometry.loc[case_event_pulses.sensor_id].reset_index()[['x', 'y', 'z']]\n\ncase_event_pulses.x = case_event_pulses.x - case_event_pulses.x.mean()\ncase_event_pulses.y = case_event_pulses.y - case_event_pulses.y.mean()\ncase_event_pulses.z = case_event_pulses.z - case_event_pulses.z.mean()\ncase_event_pulses.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:15.710867Z","iopub.execute_input":"2023-05-14T21:29:15.711259Z","iopub.status.idle":"2023-05-14T21:29:15.742907Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zenith_target = train_meta.iloc[case_event_idx].zenith\nazimuth_target = train_meta.iloc[case_event_idx].azimuth\n\nvector_target = [np.cos(azimuth_target) * np.sin(zenith_target), np.sin(azimuth_target) * np.sin(zenith_target),\n                 np.cos(zenith_target)]\n\nvector_base = np.array([-500, 500])\nx = vector_base*vector_target[0]\ny = vector_base*vector_target[1]\nz = vector_base*vector_target[2]\nvector_target_df = pd.DataFrame({'x': x, 'y': y, 'z': z})\nvector_target_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:15.744650Z","iopub.execute_input":"2023-05-14T21:29:15.744998Z","iopub.status.idle":"2023-05-14T21:29:15.765331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig_auxiliary = px.scatter_3d(case_event_pulses.loc[case_event_pulses.auxiliary],\n                              x='x', y='y', z='z', opacity=0.5, color_discrete_sequence=['red'])\nfig_non_auxiliary = px.scatter_3d(case_event_pulses.loc[~case_event_pulses.auxiliary],\n                              x='x', y='y', z='z', opacity=0.5, color_discrete_sequence=['blue'])\nfig_line = px.line_3d(vector_target_df, x=\"x\", y=\"y\", z=\"z\")\n\n\nfig_auxiliary.update_traces(marker_size=2)\nfig_non_auxiliary.update_traces(marker_size=2)\n\nfig = go.Figure(data = fig_auxiliary.data + fig_non_auxiliary.data + fig_line.data)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:15.767088Z","iopub.execute_input":"2023-05-14T21:29:15.768133Z","iopub.status.idle":"2023-05-14T21:29:16.008582Z","shell.execute_reply.started":"2023-05-14T21:29:15.768095Z","shell.execute_reply":"2023-05-14T21:29:16.007445Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=1).fit(case_event_pulses[['x', 'y', 'z']])\nvector = pca.components_[0]\nvector_base = np.array([-500, 500])\nx = vector_base*vector[0]\ny = vector_base*vector[1]\nz = vector_base*vector[2]\nvector_df = pd.DataFrame({'x': x, 'y': y, 'z': z})\n\nfig_auxiliary = px.scatter_3d(case_event_pulses.loc[case_event_pulses.auxiliary],\n                              x='x', y='y', z='z', opacity=0.5, color_discrete_sequence=['red'])\nfig_non_auxiliary = px.scatter_3d(case_event_pulses.loc[~case_event_pulses.auxiliary],\n                              x='x', y='y', z='z', opacity=0.5, color_discrete_sequence=['blue'])\nfig_line = px.line_3d(vector_target_df, x=\"x\", y=\"y\", z=\"z\")\nfig_fit_line = px.line_3d(vector_df, x=\"x\", y=\"y\", z=\"z\", color_discrete_sequence=['magenta'])\n\nfig_auxiliary.update_traces(marker_size=2)\nfig_non_auxiliary.update_traces(marker_size=2)\n\nfig = go.Figure(data = fig_auxiliary.data + fig_non_auxiliary.data + fig_line.data + fig_fit_line.data)\nfig.show()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:16.010115Z","iopub.execute_input":"2023-05-14T21:29:16.011377Z","iopub.status.idle":"2023-05-14T21:29:16.313527Z","shell.execute_reply.started":"2023-05-14T21:29:16.011340Z","shell.execute_reply":"2023-05-14T21:29:16.312174Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def angular_dist_score(az_true, zen_true, az_pred, zen_pred):\n    '''\n    calculate the MAE of the angular distance between two directions.\n    The two vectors are first converted to cartesian unit vectors,\n    and then their scalar product is computed, which is equal to\n    the cosine of the angle between the two vectors. The inverse \n    cosine (arccos) thereof is then the angle between the two input vectors\n    \n    Parameters:\n    -----------\n    \n    az_true : float (or array thereof)\n        true azimuth value(s) in radian\n    zen_true : float (or array thereof)\n        true zenith value(s) in radian\n    az_pred : float (or array thereof)\n        predicted azimuth value(s) in radian\n    zen_pred : float (or array thereof)\n        predicted zenith value(s) in radian\n    \n    Returns:\n    --------\n    \n    dist : float\n        mean over the angular distance(s) in radian\n    '''\n    \n    if not (np.all(np.isfinite(az_true)) and\n            np.all(np.isfinite(zen_true)) and\n            np.all(np.isfinite(az_pred)) and\n            np.all(np.isfinite(zen_pred))):\n        raise ValueError(\"All arguments must be finite\")\n    \n    # pre-compute all sine and cosine values\n    sa1 = np.sin(az_true)\n    ca1 = np.cos(az_true)\n    sz1 = np.sin(zen_true)\n    cz1 = np.cos(zen_true)\n    \n    sa2 = np.sin(az_pred)\n    ca2 = np.cos(az_pred)\n    sz2 = np.sin(zen_pred)\n    cz2 = np.cos(zen_pred)\n    \n    # scalar product of the two cartesian vectors (x = sz*ca, y = sz*sa, z = cz)\n    scalar_prod = sz1*sz2*(ca1*ca2 + sa1*sa2) + (cz1*cz2)\n    \n    # scalar product of two unit vectors is always between -1 and 1, this is against nummerical instability\n    # that might otherwise occure from the finite precision of the sine and cosine functions\n    scalar_prod =  np.clip(scalar_prod, -1, 1)\n    \n    # convert back to an angle (in radian)\n    return np.average(np.abs(np.arccos(scalar_prod)))","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:16.315104Z","iopub.execute_input":"2023-05-14T21:29:16.315464Z","iopub.status.idle":"2023-05-14T21:29:16.328283Z","shell.execute_reply.started":"2023-05-14T21:29:16.315433Z","shell.execute_reply":"2023-05-14T21:29:16.326698Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"zenith = np.arccos(vector[2])\nazimuth = np.arctan2(vector[1], vector[0])\nif azimuth<0:\n    azimuth = 2*np.pi + azimuth\n\nprint('Predictions:')\nprint(f'zenith: {zenith}')\nprint(f'azimuth: {azimuth}')\nprint('Target:')\nprint(f'zenith: {zenith_target}')\nprint(f'azimuth: {azimuth_target}')\nprint('Error:')\nprint(angular_dist_score(azimuth_target, zenith_target, azimuth, zenith))","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:16.330320Z","iopub.execute_input":"2023-05-14T21:29:16.330684Z","iopub.status.idle":"2023-05-14T21:29:16.350351Z","shell.execute_reply.started":"2023-05-14T21:29:16.330655Z","shell.execute_reply":"2023-05-14T21:29:16.348618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_batches = train_meta.batch_id.unique()\ntrain_meta_baseline = train_meta.loc[train_meta.batch_id == train_batches[0]].iloc[:10000].copy()\ntrain_meta_baseline.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:16.352401Z","iopub.execute_input":"2023-05-14T21:29:16.353033Z","iopub.status.idle":"2023-05-14T21:29:18.201223Z","shell.execute_reply.started":"2023-05-14T21:29:16.352989Z","shell.execute_reply":"2023-05-14T21:29:18.199983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_baseline = pd.read_parquet(f'/kaggle/input/icecube-neutrinos-in-deep-ice/train/batch_{str(train_batches[0])}.parquet')\ntrain_baseline = train_baseline.iloc[:train_meta_baseline.iloc[-1].last_pulse_index.astype(int)]\ntrain_baseline = train_baseline.reset_index()\ntrain_baseline[['x', 'y', 'z']] = sensor_geometry.loc[train_baseline.sensor_id].reset_index()[['x', 'y', 'z']]\n\ntrain_baseline['x'] = train_baseline['x'] - train_baseline.groupby('event_id').x.transform('mean')\ntrain_baseline['y'] = train_baseline['y'] - train_baseline.groupby('event_id').y.transform('mean')\ntrain_baseline['z'] = train_baseline['z'] - train_baseline.groupby('event_id').z.transform('mean')\n\nprint(len(train_baseline))\ntrain_baseline.head()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:18.202747Z","iopub.execute_input":"2023-05-14T21:29:18.203167Z","iopub.status.idle":"2023-05-14T21:29:24.406220Z","shell.execute_reply.started":"2023-05-14T21:29:18.203136Z","shell.execute_reply":"2023-05-14T21:29:24.405250Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import gc\ngc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:24.407437Z","iopub.execute_input":"2023-05-14T21:29:24.408390Z","iopub.status.idle":"2023-05-14T21:29:24.637434Z","shell.execute_reply.started":"2023-05-14T21:29:24.408354Z","shell.execute_reply":"2023-05-14T21:29:24.635835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_angles(event_df):\n\n    try:\n        pca = PCA(n_components=2).fit(event_df.loc[~event_df.auxiliary][['x', 'y', 'z']])\n        vector = pca.components_[0]\n\n        # In order to perform time direction analysis on the non-auxiliary ('true') pulses, we neeed to mean-normalize them separately\n        event_df_non_auxiliary = event_df.loc[~event_df.auxiliary].copy()\n        event_df_non_auxiliary.x = event_df_non_auxiliary.x - event_df_non_auxiliary.x.mean()\n        event_df_non_auxiliary.y = event_df_non_auxiliary.y - event_df_non_auxiliary.y.mean()\n        event_df_non_auxiliary.z = event_df_non_auxiliary.z - event_df_non_auxiliary.z.mean()\n\n        # This is the formula for calculating a distance of a point from a plane. The plane direction is the first principal component, and it goes through the origin.\n        event_df_non_auxiliary['distance'] = (event_df_non_auxiliary.x*vector[0]+\n                                              event_df_non_auxiliary.y*vector[1]+\n                                              event_df_non_auxiliary.z*vector[2])/np.linalg.norm(vector)\n\n        # Flip the vector direction if it points away from the neutrino origin\n        if (event_df_non_auxiliary.loc[(~event_df_non_auxiliary.auxiliary)&(event_df_non_auxiliary.distance>0)].time.mean() >\n            event_df_non_auxiliary.loc[(~event_df_non_auxiliary.auxiliary)&(event_df_non_auxiliary.distance<0)].time.mean()):\n            vector = -1*vector\n\n        # This is important since minor numerical deviations can give a vector component like 1.00001, and then arccos fail.\n        vector = np.clip(vector, -1, 1)\n\n        zenith = np.arccos(vector[2])\n        azimuth = np.arctan2(vector[1], vector[0])\n        if azimuth<0:\n            azimuth = 2*np.pi + azimuth\n    except:\n        zenith, azimuth = 0., 0.\n        \n    return zenith, azimuth","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:24.639495Z","iopub.execute_input":"2023-05-14T21:29:24.640075Z","iopub.status.idle":"2023-05-14T21:29:24.686597Z","shell.execute_reply.started":"2023-05-14T21:29:24.640028Z","shell.execute_reply":"2023-05-14T21:29:24.680887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.auto import tqdm\n\ndef transform_batch(path_batch_parquet, nb_sensors=5160):\n    df = pd.read_parquet(path_batch_parquet)\n    # df[df['auxiliary']]['charge'] /= 10.\n    data = np.zeros((len(df.index.unique()), nb_sensors), dtype=np.float16)\n    event_ids = []\n    for i, (idx, dfg) in tqdm(enumerate(df.groupby(level=0))):\n        event_ids.append(idx)\n        data[i, dfg['sensor_id']] = dfg['charge']\n    # df = pd.DataFrame(data, index=event_ids, columns=[f\"sid-{i}\" for i in range(nb_sensors)])\n    return event_ids, data","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:29:24.693674Z","iopub.execute_input":"2023-05-14T21:29:24.699378Z","iopub.status.idle":"2023-05-14T21:29:25.035481Z","shell.execute_reply.started":"2023-05-14T21:29:24.699149Z","shell.execute_reply":"2023-05-14T21:29:25.032728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"PATH_DATASET = \"/kaggle/input/icecube-neutrinos-in-deep-ice\"\nmeta_train = pd.read_parquet(os.path.join(PATH_DATASET, \"train_meta.parquet\"))\n\nevent_ids, data = transform_batch(os.path.join(PATH_DATASET, \"train/batch_10.parquet\"))\nprint(f\"data size: {data.shape}\")\n\nmeta_train_ = meta_train[meta_train['event_id'].isin(event_ids)]\nmeta_train_ = dict(zip(meta_train_['event_id'].values, meta_train_[[\"azimuth\", \"zenith\"]].values.tolist()))\nprint(f\"LUT size: {len(meta_train_)}\")\nangles = np.array([meta_train_[eid] for eid in event_ids], dtype=np.float16)\nprint(f\"angles size: {angles.shape}\")","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:46:52.096102Z","iopub.execute_input":"2023-05-14T21:46:52.097238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\n\nX_train, X_test, y_train, y_test = train_test_split(data, angles, train_size=0.8)\ndel data, angles","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.preprocessing import StandardScaler\nfrom xgboost import XGBRegressor\n\npreprocess = Pipeline([\n    ('scaler', StandardScaler()),\n    # https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html\n    (\"PCA\", PCA(\n        n_components=510,\n        copy=False,\n    )),\n])\n\nX_train = preprocess.fit_transform(X_train)\nX_test = preprocess.transform(X_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# https://xgboost.readthedocs.io/en/stable/parameter.html\n\nregressor = XGBRegressor(\n     tree_method=\"hist\",\n    n_estimators=256,\n    learning_rate=0.02,\n     grow_policy=\"lossguide\",\n    num_target=y_train.shape[1],\n    verbosity=2,  # 0 (silent), 1 (warning), 2 (info), 3 (debug)\n)\n\nregressor.fit(\n    X_train, y_train,\n     extra arguments: https://stackoverflow.com/a/35634198/4521646\n    eval_set=[(X_test, y_test)], \n    verbose=True,\n    early_stopping_rounds=5,\n)\n\ndel X_train, y_train\n","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.100577Z","iopub.status.idle":"2023-05-14T21:30:37.101301Z","shell.execute_reply.started":"2023-05-14T21:30:37.101068Z","shell.execute_reply":"2023-05-14T21:30:37.101090Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"results = regressor.evals_result()\ndf_res = pd.DataFrame(results['validation_0'])\ndf_res.plot()\nplt.xlabel('progress'), plt.grid()","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.102570Z","iopub.status.idle":"2023-05-14T21:30:37.103279Z","shell.execute_reply.started":"2023-05-14T21:30:37.103040Z","shell.execute_reply":"2023-05-14T21:30:37.103061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"r2 = regressor.score(X_test, y_test)\nprint(f\"XGBoost regressor r2: {r2}\")\ndel X_test, y_test","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.104537Z","iopub.status.idle":"2023-05-14T21:30:37.105261Z","shell.execute_reply.started":"2023-05-14T21:30:37.105033Z","shell.execute_reply":"2023-05-14T21:30:37.105053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_train","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.108451Z","iopub.status.idle":"2023-05-14T21:30:37.109140Z","shell.execute_reply.started":"2023-05-14T21:30:37.108932Z","shell.execute_reply":"2023-05-14T21:30:37.108953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nfrom sklearn.svm import SVR\nfrom sklearn.multioutput import MultiOutputRegressor\n\nsvr = SVR(epsilon=0.2)\nmor = MultiOutputRegressor(svr)\n# Train the regressor\nmor = mor.fit(X_train, y_train)\n\n# Generate predictions for testing data\ny_pred = mor.predict(X_test)\n\n# Evaluate the regressor\nmse_one = mean_squared_error(y_test[:,0], y_pred[:,0])\nmse_two = mean_squared_error(y_test[:,1], y_pred[:,1])\nprint(f'MSE for first regressor: {mse_one} - second regressor: {mse_two}')\nmae_one = mean_absolute_error(y_test[:,0], y_pred[:,0])\nmae_two = mean_absolute_error(y_test[:,1], y_pred[:,1])\nprint(f'MAE for first regressor: {mae_one} - second regressor: {mae_two}')\n","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.114498Z","iopub.status.idle":"2023-05-14T21:30:37.115207Z","shell.execute_reply.started":"2023-05-14T21:30:37.114978Z","shell.execute_reply":"2023-05-14T21:30:37.114999Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nmax_depth = 30\nregr_multirf = MultiOutputRegressor(\n    RandomForestRegressor(n_estimators=100, max_depth=max_depth, random_state=0)\n)\nregr_multirf.fit(X_train, y_train)\ny_multirf = regr_multirf.predict(X_test)\n","metadata":{"execution":{"iopub.status.busy":"2023-05-14T21:30:37.116543Z","iopub.status.idle":"2023-05-14T21:30:37.117240Z","shell.execute_reply.started":"2023-05-14T21:30:37.117017Z","shell.execute_reply":"2023-05-14T21:30:37.117038Z"},"trusted":true},"execution_count":null,"outputs":[]}]}