{"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":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom pylab import rcParams\nimport seaborn as sns\nimport os\nfrom tqdm import tqdm\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import classification_report, average_precision_score\nfrom sklearn.preprocessing import RobustScaler, StandardScaler\nfrom statsmodels.tsa.seasonal import seasonal_decompose\nfrom statsmodels.tsa.stattools import adfuller\nfrom statsmodels.graphics.tsaplots import plot_acf\nfrom statsmodels.tsa.stattools import acf\nfrom scipy.signal import stft","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:53:33.671569Z","iopub.execute_input":"2023-06-13T06:53:33.672189Z","iopub.status.idle":"2023-06-13T06:53:36.041443Z","shell.execute_reply.started":"2023-06-13T06:53:33.672146Z","shell.execute_reply":"2023-06-13T06:53:36.040335Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Импортируем датасет. Тк мы работаем с временными рядами, нам необходимо рассматривать каждый случай по отдельности","metadata":{}},{"cell_type":"code","source":"# Set the directory path to the folder containing the CSV files.\ntdcsfog_path = '/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/train/tdcsfog'\n\n# Initialize an empty list to store the dataframes.\ntdcsfog_list = []\n\n# Loop through each file in the directory and read it into a dataframe.\nfor file_name in tqdm(os.listdir(tdcsfog_path)):\n    if file_name.endswith('.csv'):\n        file_path = os.path.join(tdcsfog_path, file_name)\n        file = pd.read_csv(file_path)\n        tdcsfog_list.append(file)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:54:14.804692Z","iopub.execute_input":"2023-06-13T06:54:14.805211Z","iopub.status.idle":"2023-06-13T06:54:35.926550Z","shell.execute_reply.started":"2023-06-13T06:54:14.805169Z","shell.execute_reply":"2023-06-13T06:54:35.925509Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Стационарность\n\nСтационарность (stationarity) временного ряда как раз означает, что такие компоненты как тренд и сезонность отсутствуют. Говоря более точно, среднее значение и дисперсия не меняются со смещением во времени.\n\nДля более точной оценки стационарности можно применить тест Дики-Фуллера (Dickey-Fuller test). О том, что такое статистический вывод мы с вами уже говорили.\n\nВ данном случае гипотезы звучат следующим образом.\n\n- Нулевая гипотеза предполагает, что процесс нестационарный\n- Альтернативная гипотеза соответственно говорит об обратном\n","metadata":{}},{"cell_type":"code","source":"i = 0\n\nadf_test = adfuller(tdcsfog_list[i].AccV.values)\n \n# выведем p-value\nprint('p-value = ' + str(adf_test[1]))","metadata":{"execution":{"iopub.status.busy":"2023-06-09T08:47:56.092676Z","iopub.execute_input":"2023-06-09T08:47:56.093086Z","iopub.status.idle":"2023-06-09T08:47:56.649989Z","shell.execute_reply.started":"2023-06-09T08:47:56.093035Z","shell.execute_reply":"2023-06-09T08:47:56.636953Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Найдем p-value для всех примеров","metadata":{}},{"cell_type":"code","source":"p_valuesV = []\np_valuesML = []\np_valuesAP = []\n\nfor df in tqdm(tdcsfog_list[:15]):\n    p_valuesV.append(adfuller(df.AccV.values)[1])\n    p_valuesML.append(adfuller(df.AccML.values)[1])\n    p_valuesAP.append(adfuller(df.AccAP.values)[1])","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:54:46.643786Z","iopub.execute_input":"2023-06-13T06:54:46.644558Z","iopub.status.idle":"2023-06-13T06:55:11.952903Z","shell.execute_reply.started":"2023-06-13T06:54:46.644513Z","shell.execute_reply":"2023-06-13T06:55:11.951503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Построим графики p-value от индекса примера","metadata":{}},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 9\n\nfig, (ax0, ax1, ax2) = plt.subplots(3, 1)\nax0.set_yscale('log')\nax0.plot(p_valuesV)\nax1.set_yscale('log')\nax1.plot(p_valuesML)\nax2.set_yscale('linear')\nax2.plot(p_valuesAP)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:17.665561Z","iopub.execute_input":"2023-06-13T06:55:17.665973Z","iopub.status.idle":"2023-06-13T06:55:18.842704Z","shell.execute_reply.started":"2023-06-13T06:55:17.665941Z","shell.execute_reply":"2023-06-13T06:55:18.841579Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"У V и ML p-value очень маленькое, но у AP есть значения где p-value > 0.05.","metadata":{}},{"cell_type":"markdown","source":"------------------------------------------------------------------------------------------------\n Например, индекс 14","metadata":{}},{"cell_type":"code","source":"p_valuesAP[14]","metadata":{"execution":{"iopub.status.busy":"2023-06-09T08:48:10.166962Z","iopub.execute_input":"2023-06-09T08:48:10.167338Z","iopub.status.idle":"2023-06-09T08:48:10.175702Z","shell.execute_reply.started":"2023-06-09T08:48:10.167311Z","shell.execute_reply":"2023-06-09T08:48:10.174032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Построим график AP от времени","metadata":{}},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 2\nplt.plot(tdcsfog_list[14].AccAP.values)","metadata":{"execution":{"iopub.status.busy":"2023-06-09T08:48:10.176706Z","iopub.execute_input":"2023-06-09T08:48:10.177086Z","iopub.status.idle":"2023-06-09T08:48:10.354686Z","shell.execute_reply.started":"2023-06-09T08:48:10.177060Z","shell.execute_reply":"2023-06-09T08:48:10.353362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Построим автокорреляционную функцию","metadata":{}},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 3\nplt.plot(acf(tdcsfog_list[14].AccAP.values, nlags=300))","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:31.199246Z","iopub.execute_input":"2023-06-13T06:55:31.199608Z","iopub.status.idle":"2023-06-13T06:55:31.483531Z","shell.execute_reply.started":"2023-06-13T06:55:31.199581Z","shell.execute_reply":"2023-06-13T06:55:31.482453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"На ней нет никаких периодов","metadata":{}},{"cell_type":"markdown","source":"Рассмотрим только значимый промежуток. Построим график AP от времени промежутке времени [6000:9000]","metadata":{}},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 2\nplt.plot(tdcsfog_list[14].AccAP.values[6000:9000])","metadata":{"execution":{"iopub.status.busy":"2023-06-09T08:48:10.556314Z","iopub.execute_input":"2023-06-09T08:48:10.556647Z","iopub.status.idle":"2023-06-09T08:48:10.730356Z","shell.execute_reply.started":"2023-06-09T08:48:10.556622Z","shell.execute_reply":"2023-06-09T08:48:10.728664Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Построим автокорреляционную функцию на этом промежутке","metadata":{}},{"cell_type":"code","source":"i = 14\n\nrcParams['figure.figsize'] = 11, 3\nplt.plot(acf(tdcsfog_list[i].AccAP.values[6000:9000], nlags=300))","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:44.883071Z","iopub.execute_input":"2023-06-13T06:55:44.883458Z","iopub.status.idle":"2023-06-13T06:55:45.165840Z","shell.execute_reply.started":"2023-06-13T06:55:44.883430Z","shell.execute_reply":"2023-06-13T06:55:45.164925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Можно заметить некоторую преиодичность периодом ~ 75. Однако p-value на таком промежутке низкое\n","metadata":{}},{"cell_type":"code","source":"adfuller(tdcsfog_list[14].AccAP.values[6000:9000])[1]","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:49.192913Z","iopub.execute_input":"2023-06-13T06:55:49.193378Z","iopub.status.idle":"2023-06-13T06:55:49.417005Z","shell.execute_reply.started":"2023-06-13T06:55:49.193342Z","shell.execute_reply":"2023-06-13T06:55:49.415535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = tdcsfog_list[i].AccAP.values[6000:9000]\nrcParams['figure.figsize'] = 11, 9\ndecompose = seasonal_decompose(x, period=70)\ndecompose.plot()\nplt.plot(tdcsfog_list[i].Turn.values)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:51.090197Z","iopub.execute_input":"2023-06-13T06:55:51.090612Z","iopub.status.idle":"2023-06-13T06:55:52.062674Z","shell.execute_reply.started":"2023-06-13T06:55:51.090578Z","shell.execute_reply":"2023-06-13T06:55:52.061551Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Выражена нестационарность. Сезонные колебания ~ 10%-20% от всех колебаний","metadata":{}},{"cell_type":"markdown","source":"----------------------------------------------------------------------------------------------","metadata":{}},{"cell_type":"markdown","source":"## Идея: выделить промежуток ","metadata":{}},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 2\nplt.plot(tdcsfog_list[14].AccML.values)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:56.915368Z","iopub.execute_input":"2023-06-13T06:55:56.916487Z","iopub.status.idle":"2023-06-13T06:55:57.192966Z","shell.execute_reply.started":"2023-06-13T06:55:56.916437Z","shell.execute_reply":"2023-06-13T06:55:57.191882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"j = 14\n\ndef get_window(x, threshhold = 0.2, winsize = 100):\n    f, t, Zxx = stft(x, nperseg=winsize)\n    tmp = np.zeros_like(t)\n    tmp[np.sum(np.abs(Zxx)[2:-10, :], axis=0) > threshhold] = 1\n    tmp[0] = 0\n    tmp[-1] = 0\n    tmp[-2] = 0\n    ind = np.arange(len(x))\n    window = tmp[ind // int(t[1] - t[0])]\n    return window.astype(bool)\n\nwindow = get_window(tdcsfog_list[j].AccAP.values, threshhold=1.5, winsize=200)\nrcParams['figure.figsize'] = 11, 3\nplt.plot(window*5)\nplt.plot(tdcsfog_list[j].AccML.values)\n","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:55:59.636929Z","iopub.execute_input":"2023-06-13T06:55:59.637470Z","iopub.status.idle":"2023-06-13T06:56:00.038042Z","shell.execute_reply.started":"2023-06-13T06:55:59.637427Z","shell.execute_reply":"2023-06-13T06:56:00.036858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rcParams['figure.figsize'] = 11, 3\nplt.plot(acf(tdcsfog_list[j].AccAP.values[window], nlags=300))","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:56:02.749305Z","iopub.execute_input":"2023-06-13T06:56:02.749722Z","iopub.status.idle":"2023-06-13T06:56:03.041377Z","shell.execute_reply.started":"2023-06-13T06:56:02.749693Z","shell.execute_reply":"2023-06-13T06:56:03.040208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Можно заметить, что в этом окне компонента Seasonal намного больше, чем если бы мы не выбирали окно","metadata":{}},{"cell_type":"code","source":"x = tdcsfog_list[j].AccAP.values[window]\nrcParams['figure.figsize'] = 11, 9\ndecompose = seasonal_decompose(x, period=140)\ndecompose.plot()\nplt.plot(tdcsfog_list[j].Turn.values[window])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:56:05.351532Z","iopub.execute_input":"2023-06-13T06:56:05.352051Z","iopub.status.idle":"2023-06-13T06:56:06.351259Z","shell.execute_reply.started":"2023-06-13T06:56:05.352007Z","shell.execute_reply":"2023-06-13T06:56:06.349971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = tdcsfog_list[j].AccAP.values\nrcParams['figure.figsize'] = 11, 9\ndecompose = seasonal_decompose(x, period=140)\ndecompose.plot()\nplt.plot(tdcsfog_list[j].Turn.values)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:56:09.647606Z","iopub.execute_input":"2023-06-13T06:56:09.648662Z","iopub.status.idle":"2023-06-13T06:56:10.553382Z","shell.execute_reply.started":"2023-06-13T06:56:09.648623Z","shell.execute_reply":"2023-06-13T06:56:10.552093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Внутри промежутка observed = trend + seasonal + residual. А вне residual = seasonal = 0.","metadata":{}},{"cell_type":"code","source":"def get_decomposition(x, threshhold=1.5, winsize=200, period=140):\n    window = get_window(x, threshhold=threshhold, winsize=winsize)\n    new_window = np.where(window)[0][period//2:-period//1]\n    decompose = seasonal_decompose(x[window], period=period)\n    trend = x.copy()\n    seasonal = np.zeros_like(trend)\n    resid = np.zeros_like(trend)\n    trend[new_window] = decompose.trend[period//2:-period//1]\n    seasonal[new_window] = decompose.seasonal[period//2:-period//1]\n    resid[new_window] = decompose.resid[period//2:-period//1]\n    return trend, seasonal, resid\n\nx = tdcsfog_list[j].AccAP.values\nget_decomposition(x)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:56:14.049583Z","iopub.execute_input":"2023-06-13T06:56:14.050635Z","iopub.status.idle":"2023-06-13T06:56:14.077991Z","shell.execute_reply.started":"2023-06-13T06:56:14.050590Z","shell.execute_reply":"2023-06-13T06:56:14.076789Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"period = 150\n\nfor i in tqdm(range(len(tdcsfog_list))):\n    x = tdcsfog_list[i].AccV.values\n    tdcsfog_list[i]['AccV_trend'], tdcsfog_list[i]['AccV_seasonal'], tdcsfog_list[i]['AccV_resid'] = get_decomposition(x, period=period)\n    x = tdcsfog_list[i].AccML.values\n    tdcsfog_list[i]['AccML_trend'], tdcsfog_list[i]['AccML_seasonal'], tdcsfog_list[i]['AccML_resid'] = get_decomposition(x, period=period)\n    x = tdcsfog_list[i].AccAP.values\n    tdcsfog_list[i]['AccAP_trend'], tdcsfog_list[i]['AccAP_seasonal'], tdcsfog_list[i]['AccAP_resid'] = get_decomposition(x, period=period)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:56:29.366365Z","iopub.execute_input":"2023-06-13T06:56:29.366772Z","iopub.status.idle":"2023-06-13T06:57:01.818683Z","shell.execute_reply.started":"2023-06-13T06:56:29.366740Z","shell.execute_reply":"2023-06-13T06:57:01.817566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"i = 4\n\nrcParams['figure.figsize'] = 11, 9\n\nfig, (ax0, ax1, ax2, ax3) = plt.subplots(4, 1)\nax0.plot(tdcsfog_list[i]['AccML'])\nax1.plot(tdcsfog_list[i]['AccML_trend'])\nax1.plot(tdcsfog_list[i]['Turn'])\nax2.plot(tdcsfog_list[i]['AccML_seasonal'])\nax3.plot(tdcsfog_list[i]['AccML_resid'])","metadata":{"execution":{"iopub.status.busy":"2023-06-13T06:57:26.888685Z","iopub.execute_input":"2023-06-13T06:57:26.889101Z","iopub.status.idle":"2023-06-13T06:57:27.752901Z","shell.execute_reply.started":"2023-06-13T06:57:26.889067Z","shell.execute_reply":"2023-06-13T06:57:27.751679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"----------------------------------------------------------------------------------------\n","metadata":{}},{"cell_type":"markdown","source":"### H2o- просто добавь воды","metadata":{}},{"cell_type":"code","source":"import h2o\nfrom h2o.automl import H2OAutoML\nh2o.init()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T07:10:17.436983Z","iopub.execute_input":"2023-06-13T07:10:17.437376Z","iopub.status.idle":"2023-06-13T07:10:25.835235Z","shell.execute_reply.started":"2023-06-13T07:10:17.437347Z","shell.execute_reply":"2023-06-13T07:10:25.833922Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#train = pd.concat(tdcsfog_list[:666], axis = 0)\n#test = pd.concat(tdcsfog_list[666:], axis = 0)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T07:10:30.519048Z","iopub.execute_input":"2023-06-13T07:10:30.519498Z","iopub.status.idle":"2023-06-13T07:10:31.754461Z","shell.execute_reply.started":"2023-06-13T07:10:30.519459Z","shell.execute_reply":"2023-06-13T07:10:31.753481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from random import shuffle\nshuffle(tdcsfog_list)\ntrain = pd.concat(tdcsfog_list[:666], axis = 0)\ntest = pd.concat(tdcsfog_list[666:], axis = 0)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:42:49.411566Z","iopub.execute_input":"2023-06-13T10:42:49.411982Z","iopub.status.idle":"2023-06-13T10:42:50.749274Z","shell.execute_reply.started":"2023-06-13T10:42:49.411954Z","shell.execute_reply":"2023-06-13T10:42:50.748149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=train[['AccV', 'AccML', 'AccAP', 'AccV_trend','AccML_trend','AccAP_trend', 'AccV_seasonal','AccML_seasonal','AccAP_seasonal', 'AccV_resid','AccML_resid','AccAP_resid','Turn']].values[:1000000]\ntrain_h20 = h2o.H2OFrame(train)\ntest=test[['AccV', 'AccML', 'AccAP', 'AccV_trend','AccML_trend','AccAP_trend', 'AccV_seasonal','AccML_seasonal','AccAP_seasonal', 'AccV_resid','AccML_resid','AccAP_resid','Turn']].values[:1000000]\ntest_h20 = h2o.H2OFrame(test)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T09:17:47.359279Z","iopub.execute_input":"2023-06-13T09:17:47.360124Z","iopub.status.idle":"2023-06-13T09:18:47.788542Z","shell.execute_reply.started":"2023-06-13T09:17:47.360091Z","shell.execute_reply":"2023-06-13T09:18:47.787458Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_h20['C13'] = train_h20['C13'].asfactor()\ntest_h20['C13'] = test_h20['C13'].asfactor()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T09:19:04.755535Z","iopub.execute_input":"2023-06-13T09:19:04.755929Z","iopub.status.idle":"2023-06-13T09:19:04.762055Z","shell.execute_reply.started":"2023-06-13T09:19:04.755901Z","shell.execute_reply":"2023-06-13T09:19:04.760610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = \"C13\"\nx_train_h20 = train_h20.columns\nx_train_h20.remove(y)\naml = H2OAutoML(max_runtime_secs=3600, seed = 1)\naml.train(x = x_train_h20, y = y, training_frame = train_h20)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T09:19:13.611744Z","iopub.execute_input":"2023-06-13T09:19:13.612504Z","iopub.status.idle":"2023-06-13T10:19:17.430832Z","shell.execute_reply.started":"2023-06-13T09:19:13.612449Z","shell.execute_reply":"2023-06-13T10:19:17.429667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lb = aml.leaderboard\nlb.head()","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:19:17.433382Z","iopub.execute_input":"2023-06-13T10:19:17.434356Z","iopub.status.idle":"2023-06-13T10:19:17.530094Z","shell.execute_reply.started":"2023-06-13T10:19:17.434307Z","shell.execute_reply":"2023-06-13T10:19:17.528946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%matplotlib inline\nh2o.explain(aml, test_h20)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:19:17.531760Z","iopub.execute_input":"2023-06-13T10:19:17.532127Z","iopub.status.idle":"2023-06-13T10:42:16.848796Z","shell.execute_reply.started":"2023-06-13T10:19:17.532097Z","shell.execute_reply":"2023-06-13T10:42:16.846185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'AccV', 'AccML', 'AccAP', 'AccV_trend','AccML_trend','AccAP_trend', 'AccV_seasonal','AccML_seasonal','AccAP_seasonal', 'AccV_resid','AccML_resid','AccAP_resid'","metadata":{"execution":{"iopub.status.busy":"2023-06-09T11:11:12.024412Z","iopub.execute_input":"2023-06-09T11:11:12.025227Z","iopub.status.idle":"2023-06-09T11:11:12.039357Z","shell.execute_reply.started":"2023-06-09T11:11:12.025187Z","shell.execute_reply":"2023-06-09T11:11:12.037668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Catboost","metadata":{}},{"cell_type":"code","source":"X_train = train[['AccV', 'AccML', 'AccAP', 'AccV_trend','AccML_trend','AccAP_trend', 'AccV_seasonal','AccML_seasonal','AccAP_seasonal', 'AccV_resid','AccML_resid','AccAP_resid']]\ny_train = train['Turn']\nX_test = test[['AccV', 'AccML', 'AccAP', 'AccV_trend','AccML_trend','AccAP_trend', 'AccV_seasonal','AccML_seasonal','AccAP_seasonal', 'AccV_resid','AccML_resid','AccAP_resid']]\ny_test = test['Turn']","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:43:04.052656Z","iopub.execute_input":"2023-06-13T10:43:04.053051Z","iopub.status.idle":"2023-06-13T10:43:05.372274Z","shell.execute_reply.started":"2023-06-13T10:43:04.053023Z","shell.execute_reply":"2023-06-13T10:43:05.371222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import catboost as cat\n#X_cat=cat.Pool(X_train,y_train)\n#test_cat=cat.Pool(X_test,y_test)\nmodel = cat.CatBoostClassifier(iterations=10,\n                           depth=3,\n                           learning_rate=0.1,\n                           loss_function='Logloss',\n                           verbose=False)\nmodel.fit(X_train, y_train)\npreds_proba = model.predict_proba(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:43:10.310713Z","iopub.execute_input":"2023-06-13T10:43:10.311098Z","iopub.status.idle":"2023-06-13T10:43:15.772854Z","shell.execute_reply.started":"2023-06-13T10:43:10.311069Z","shell.execute_reply":"2023-06-13T10:43:15.771811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import roc_auc_score\nroc_auc_score(y_test, preds_proba[:, 1])","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:43:20.513284Z","iopub.execute_input":"2023-06-13T10:43:20.513726Z","iopub.status.idle":"2023-06-13T10:43:20.869201Z","shell.execute_reply.started":"2023-06-13T10:43:20.513691Z","shell.execute_reply":"2023-06-13T10:43:20.867146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = cat.CatBoostClassifier()\ngrid = {'learning_rate': [0.05, 0.1,0.15],\n        'depth': [3, 5]}\n\ngrid_search_result = model.grid_search(grid, \n                                       X=X_train, \n                                       y=y_train, \n                                       plot=True)","metadata":{"execution":{"iopub.status.busy":"2023-06-13T10:42:16.856852Z","iopub.status.idle":"2023-06-13T10:42:16.857374Z","shell.execute_reply.started":"2023-06-13T10:42:16.857091Z","shell.execute_reply":"2023-06-13T10:42:16.857114Z"},"trusted":true},"execution_count":null,"outputs":[]}]}