{"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 os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-02-03T04:44:52.548654Z","iopub.execute_input":"2023-02-03T04:44:52.549150Z","iopub.status.idle":"2023-02-03T04:45:09.575099Z","shell.execute_reply.started":"2023-02-03T04:44:52.549054Z","shell.execute_reply":"2023-02-03T04:45:09.574036Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport os\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nplt.style.use('seaborn-white')\n%matplotlib inline\n\nfrom sklearn.model_selection import train_test_split, GridSearchCV\nimport lightgbm as lgbm\nfrom lightgbm import LGBMRegressor\nfrom xgboost import XGBRegressor\nfrom tqdm import tqdm\n\nfile_list = []\nfile_list_train = []\nfile_list_test = []\n\n\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        file_list.append(os.path.join(dirname, filename))\n        \nPATH = '/kaggle/input/predict-volcanic-eruptions-ingv-oe/'\n\nfor dirname, _, filenames in os.walk('/kaggle/input/predict-volcanic-eruptions-ingv-oe/train'):\n    for filename in filenames:\n        file_list_train.append(os.path.join(dirname, filename))\n        \nfor dirname, _, filenames in os.walk('/kaggle/input/predict-volcanic-eruptions-ingv-oe/test'):\n    for filename in filenames:\n        file_list_test.append(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:09.576943Z","iopub.execute_input":"2023-02-03T04:45:09.577265Z","iopub.status.idle":"2023-02-03T04:45:13.585112Z","shell.execute_reply.started":"2023-02-03T04:45:09.577236Z","shell.execute_reply":"2023-02-03T04:45:13.583916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(file_list[0])\nprint(pd.read_csv(file_list[0]))\nprint(pd.read_csv(file_list[0]).isna().sum())","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:13.586927Z","iopub.execute_input":"2023-02-03T04:45:13.587384Z","iopub.status.idle":"2023-02-03T04:45:13.623013Z","shell.execute_reply.started":"2023-02-03T04:45:13.587337Z","shell.execute_reply":"2023-02-03T04:45:13.621768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(file_list_train[0])\nprint(pd.read_csv(file_list_train[0]))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:13.626447Z","iopub.execute_input":"2023-02-03T04:45:13.626937Z","iopub.status.idle":"2023-02-03T04:45:13.797279Z","shell.execute_reply.started":"2023-02-03T04:45:13.626884Z","shell.execute_reply":"2023-02-03T04:45:13.796082Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(file_list[1])\nprint(pd.read_csv(file_list[1]))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:13.799048Z","iopub.execute_input":"2023-02-03T04:45:13.799678Z","iopub.status.idle":"2023-02-03T04:45:13.819554Z","shell.execute_reply.started":"2023-02-03T04:45:13.799607Z","shell.execute_reply":"2023-02-03T04:45:13.817910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(file_list_test[0])\nprint(pd.read_csv(file_list_test[0]))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:13.821146Z","iopub.execute_input":"2023-02-03T04:45:13.821610Z","iopub.status.idle":"2023-02-03T04:45:13.971462Z","shell.execute_reply.started":"2023-02-03T04:45:13.821553Z","shell.execute_reply":"2023-02-03T04:45:13.970562Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(file_list_test)) \nkeys = list(pd.read_csv(file_list_test[0]).keys()) \nprint(keys)\nnanC = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\nfor index in range(len(file_list_test)):\n    if(index % 200 == 0): \n        print(index)\n    df = pd.read_csv(file_list_test[index]) \n    for key in df.keys():\n        if df[key].isna().sum() == len(pd.read_csv(file_list_train[0])):            \n            nanC[keys.index(key)] += 1\n\nprint(nanC)\ndata={'sensors': keys, 'count': nanC}\nNaNDF = pd.DataFrame(data)\nprint(NaNDF)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T04:45:13.972872Z","iopub.execute_input":"2023-02-03T04:45:13.973225Z","iopub.status.idle":"2023-02-03T05:38:55.521376Z","shell.execute_reply.started":"2023-02-03T04:45:13.973193Z","shell.execute_reply":"2023-02-03T05:38:55.519348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NaNDF.plot(figsize =(20, 20), x=\"sensors\", y=\"count\", kind=\"bar\",  rot=5, fontsize=14 )","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.524442Z","iopub.execute_input":"2023-02-03T05:38:55.525360Z","iopub.status.idle":"2023-02-03T05:38:55.937402Z","shell.execute_reply.started":"2023-02-03T05:38:55.525296Z","shell.execute_reply":"2023-02-03T05:38:55.936253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(file_list_test))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.938935Z","iopub.execute_input":"2023-02-03T05:38:55.939279Z","iopub.status.idle":"2023-02-03T05:38:55.945262Z","shell.execute_reply.started":"2023-02-03T05:38:55.939248Z","shell.execute_reply":"2023-02-03T05:38:55.944080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(file_list_train))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.950249Z","iopub.execute_input":"2023-02-03T05:38:55.950692Z","iopub.status.idle":"2023-02-03T05:38:55.957549Z","shell.execute_reply.started":"2023-02-03T05:38:55.950632Z","shell.execute_reply":"2023-02-03T05:38:55.956266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files_train = [file.split('/')[-1].split('.')[-2] for file in file_list_train]\nfiles_test = [file.split('/')[-1].split('.')[-2] for file in file_list_test]","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.959351Z","iopub.execute_input":"2023-02-03T05:38:55.959755Z","iopub.status.idle":"2023-02-03T05:38:55.976313Z","shell.execute_reply.started":"2023-02-03T05:38:55.959710Z","shell.execute_reply":"2023-02-03T05:38:55.974759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(files_train[0:10])","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.978011Z","iopub.execute_input":"2023-02-03T05:38:55.978408Z","iopub.status.idle":"2023-02-03T05:38:55.990933Z","shell.execute_reply.started":"2023-02-03T05:38:55.978372Z","shell.execute_reply":"2023-02-03T05:38:55.989359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(files_test[0:10])","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:55.992504Z","iopub.execute_input":"2023-02-03T05:38:55.992886Z","iopub.status.idle":"2023-02-03T05:38:55.999591Z","shell.execute_reply.started":"2023-02-03T05:38:55.992854Z","shell.execute_reply":"2023-02-03T05:38:55.998668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set = set(files_test)\ntrain_set = set(files_train)\ninter = test_set.intersection(train_set)\nprint(inter)\nset()","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:56.000727Z","iopub.execute_input":"2023-02-03T05:38:56.001095Z","iopub.status.idle":"2023-02-03T05:38:56.015088Z","shell.execute_reply.started":"2023-02-03T05:38:56.001046Z","shell.execute_reply":"2023-02-03T05:38:56.013790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(PATH+'train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:56.017058Z","iopub.execute_input":"2023-02-03T05:38:56.017531Z","iopub.status.idle":"2023-02-03T05:38:56.032295Z","shell.execute_reply.started":"2023-02-03T05:38:56.017494Z","shell.execute_reply":"2023-02-03T05:38:56.030842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(train['time_to_eruption'],\n            hist=True,\n            kde=True,\n            bins=100,\n            color='blue',\n            hist_kws={'edgecolor':'black'})","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:56.034284Z","iopub.execute_input":"2023-02-03T05:38:56.034769Z","iopub.status.idle":"2023-02-03T05:38:56.448372Z","shell.execute_reply.started":"2023-02-03T05:38:56.034723Z","shell.execute_reply":"2023-02-03T05:38:56.447139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['time_to_eruption'].describe()","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:56.450421Z","iopub.execute_input":"2023-02-03T05:38:56.450800Z","iopub.status.idle":"2023-02-03T05:38:56.464061Z","shell.execute_reply.started":"2023-02-03T05:38:56.450765Z","shell.execute_reply":"2023-02-03T05:38:56.462975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_segment_id = pd.read_csv(PATH+'train/800654756.csv')\n\ndf_segment_id.plot(figsize=(20,20),\n                  subplots=True,\n                  layout=(10,1),\n                  rot=0,\n                  lw=1,\n                  title='sergment_id #800654756')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:56.465672Z","iopub.execute_input":"2023-02-03T05:38:56.466478Z","iopub.status.idle":"2023-02-03T05:38:59.203114Z","shell.execute_reply.started":"2023-02-03T05:38:56.466437Z","shell.execute_reply":"2023-02-03T05:38:59.201720Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(train.sort_values('time_to_eruption', axis=0, ascending=True).iloc[[0,-1],:])\n\nsegment_id_min = 601524801\nsegment_id_max = 1923243961\n\ndf_segment_id_min = pd.read_csv(PATH+'train/'+str(segment_id_min)+'.csv')\ndf_segment_id_max = pd.read_csv(PATH+'train/'+str(segment_id_max)+'.csv')","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:59.204640Z","iopub.execute_input":"2023-02-03T05:38:59.205005Z","iopub.status.idle":"2023-02-03T05:38:59.465316Z","shell.execute_reply.started":"2023-02-03T05:38:59.204972Z","shell.execute_reply":"2023-02-03T05:38:59.464144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ndf_segment_id_min.plot(figsize=(20,20), subplots=True, layout=(10,1), rot=0, lw=1, title='segment_id #601524801 (min)')\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:38:59.467202Z","iopub.execute_input":"2023-02-03T05:38:59.468255Z","iopub.status.idle":"2023-02-03T05:39:01.999659Z","shell.execute_reply.started":"2023-02-03T05:38:59.468201Z","shell.execute_reply":"2023-02-03T05:39:01.998525Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_segment_id_max.plot(figsize=(20,20), subplots=True, layout=(10,1), rot=0, lw=1, title='segment_id #1923243961 (max)')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:39:02.001237Z","iopub.execute_input":"2023-02-03T05:39:02.001832Z","iopub.status.idle":"2023-02-03T05:39:04.870388Z","shell.execute_reply.started":"2023-02-03T05:39:02.001797Z","shell.execute_reply":"2023-02-03T05:39:04.868984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def build_features(signal, ts, sensor_id):\n    X = pd.DataFrame()\n    f = np.fft.fft(signal)\n    f_real = np.real(f)\n    X.loc[ts, f'{sensor_id}_sum'] = signal.sum()\n    X.loc[ts, f'{sensor_id}_mean'] = signal.mean()\n    X.loc[ts, f'{sensor_id}_std'] = signal.std()\n    X.loc[ts, f'{sensor_id}_var'] = signal.var()\n    X.loc[ts, f'{sensor_id}_max'] = signal.max()\n    X.loc[ts, f'{sensor_id}_min'] = signal.min()\n    X.loc[ts, f'{sensor_id}_skew'] = signal.skew()\n    X.loc[ts, f'{sensor_id}_mad'] = signal.mad()\n    X.loc[ts, f'{sensor_id}_kurtosis'] = signal.kurtosis()\n    X.loc[ts, f'{sensor_id}_quantile99'] = np.quantile(signal, 0.99)\n    X.loc[ts, f'{sensor_id}_quantile95'] = np.quantile(signal, 0.95)\n    X.loc[ts, f'{sensor_id}_quantile85'] = np.quantile(signal, 0.85)\n    X.loc[ts, f'{sensor_id}_quantile75'] = np.quantile(signal, 0.75)\n    X.loc[ts, f'{sensor_id}_quantile55'] = np.quantile(signal, 0.55)\n    X.loc[ts, f'{sensor_id}_quantile45'] = np.quantile(signal, 0.45)\n    X.loc[ts, f'{sensor_id}_quantile25'] = np.quantile(signal, 0.25)\n    X.loc[ts, f'{sensor_id}_quantile15'] = np.quantile(signal, 0.15)\n    X.loc[ts, f'{sensor_id}_quantile05'] = np.quantile(signal, 0.05)\n    X.loc[ts, f'{sensor_id}_quantile01'] = np.quantile(signal, 0.01)\n    X.loc[ts, f'{sensor_id}_fft_real_mean'] = f_real.mean()\n    X.loc[ts, f'{sensor_id}_fft_real_std'] = f_real.std()\n    X.loc[ts, f'{sensor_id}_fft_real_max'] = f_real.max()\n    X.loc[ts, f'{sensor_id}_fft_real_min'] = f_real.min()\n    \n    return X","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:39:04.871995Z","iopub.execute_input":"2023-02-03T05:39:04.872346Z","iopub.status.idle":"2023-02-03T05:39:04.887595Z","shell.execute_reply.started":"2023-02-03T05:39:04.872314Z","shell.execute_reply":"2023-02-03T05:39:04.886033Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_set = list()\nseg = 0\n\nfor seg, segment_id in enumerate(train.segment_id):\n    signals = pd.read_csv(PATH+'train/'+str(segment_id)+'.csv')\n    train_row = []\n    \n    if seg%200 == 0:\n        print('Processing segment_id={}'.format(seg))\n        \n    for sensor in range(0, 10):\n        sensor_id = f'sensor_{sensor+1}'\n        train_row.append(build_features(signals[sensor_id].fillna(0), segment_id, sensor_id))\n        \n    train_row = pd.concat(train_row, axis=1)\n    train_set.append(train_row)\n    seg+=1\n    \ntrain_set = pd.concat(train_set)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T05:39:04.889653Z","iopub.execute_input":"2023-02-03T05:39:04.890453Z","iopub.status.idle":"2023-02-03T06:22:13.397884Z","shell.execute_reply.started":"2023-02-03T05:39:04.890402Z","shell.execute_reply":"2023-02-03T06:22:13.396890Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ntrain_set = train_set.reset_index()\ntrain_set = train_set.rename(columns={'index':  'segment_id'})\n\ntrain_set = pd.merge(train_set, train, on='segment_id')\n\n","metadata":{"execution":{"iopub.status.busy":"2023-02-03T06:22:13.399512Z","iopub.execute_input":"2023-02-03T06:22:13.399978Z","iopub.status.idle":"2023-02-03T06:22:13.436434Z","shell.execute_reply.started":"2023-02-03T06:22:13.399936Z","shell.execute_reply":"2023-02-03T06:22:13.435366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_set.head(3))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T06:22:13.438070Z","iopub.execute_input":"2023-02-03T06:22:13.438490Z","iopub.status.idle":"2023-02-03T06:22:13.454558Z","shell.execute_reply.started":"2023-02-03T06:22:13.438448Z","shell.execute_reply":"2023-02-03T06:22:13.453431Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_files = []\nfor dirname, _, filenames in os.walk(PATH+'test/'):\n    for filename in filenames:\n        test_files.append(filename[:-4])\n        \ntest = pd.DataFrame(test_files, columns=['segment_id'])","metadata":{"execution":{"iopub.status.busy":"2023-02-03T06:22:13.456252Z","iopub.execute_input":"2023-02-03T06:22:13.456551Z","iopub.status.idle":"2023-02-03T06:22:15.536554Z","shell.execute_reply.started":"2023-02-03T06:22:13.456522Z","shell.execute_reply":"2023-02-03T06:22:15.535388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set = list()\nseg = 0\n\nfor seg, segment_id in enumerate(test.segment_id):\n    signals = pd.read_csv(PATH+'test/'+str(segment_id)+'.csv')\n    test_row = []\n    \n    if seg%200 == 0:\n        print('Processing segment_id={}'.format(seg))\n        \n    for sensor in range(0, 10):\n        sensor_id = f'sensor_{sensor+1}'\n        test_row.append(build_features(signals[sensor_id].fillna(0), segment_id, sensor_id))\n        \n    test_row = pd.concat(test_row, axis=1)\n    test_set.append(test_row)\n    seg+=1\n    \ntest_set = pd.concat(test_set)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T06:22:15.538303Z","iopub.execute_input":"2023-02-03T06:22:15.538683Z","iopub.status.idle":"2023-02-03T07:05:14.354028Z","shell.execute_reply.started":"2023-02-03T06:22:15.538641Z","shell.execute_reply":"2023-02-03T07:05:14.352426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_set = test_set.reset_index()\ntest_set = test_set.rename(columns={'index':  'segment_id'})\n\ntest_set = pd.merge(test_set, test, on='segment_id')","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.360949Z","iopub.execute_input":"2023-02-03T07:05:14.361357Z","iopub.status.idle":"2023-02-03T07:05:14.418851Z","shell.execute_reply.started":"2023-02-03T07:05:14.361318Z","shell.execute_reply":"2023-02-03T07:05:14.417699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(test_set.head(3))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.420749Z","iopub.execute_input":"2023-02-03T07:05:14.421216Z","iopub.status.idle":"2023-02-03T07:05:14.441185Z","shell.execute_reply.started":"2023-02-03T07:05:14.421171Z","shell.execute_reply":"2023-02-03T07:05:14.439708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_set.drop(['segment_id', 'time_to_eruption'], axis=1)\ny = train_set['time_to_eruption']\n\nX_train, X_valid, y_train, y_valid = train_test_split(X, y, \n                                                      test_size=0.2,\n                                                      random_state=42)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.442782Z","iopub.execute_input":"2023-02-03T07:05:14.443119Z","iopub.status.idle":"2023-02-03T07:05:14.475981Z","shell.execute_reply.started":"2023-02-03T07:05:14.443090Z","shell.execute_reply":"2023-02-03T07:05:14.474805Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.head(3))\nprint('np.shape(X_train) = ', np.shape(X_train))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.477534Z","iopub.execute_input":"2023-02-03T07:05:14.477876Z","iopub.status.idle":"2023-02-03T07:05:14.496467Z","shell.execute_reply.started":"2023-02-03T07:05:14.477845Z","shell.execute_reply":"2023-02-03T07:05:14.495496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(y_train.head(3))\nprint('np.shape(y_train) = ', np.shape(y_train))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.497869Z","iopub.execute_input":"2023-02-03T07:05:14.498861Z","iopub.status.idle":"2023-02-03T07:05:14.513680Z","shell.execute_reply.started":"2023-02-03T07:05:14.498825Z","shell.execute_reply":"2023-02-03T07:05:14.512516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\n\nmodel = RandomForestRegressor(max_depth=20, random_state=0)\nmodel.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:05:14.515078Z","iopub.execute_input":"2023-02-03T07:05:14.515475Z","iopub.status.idle":"2023-02-03T07:06:04.661627Z","shell.execute_reply.started":"2023-02-03T07:05:14.515423Z","shell.execute_reply":"2023-02-03T07:06:04.660699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_valid)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:06:04.663127Z","iopub.execute_input":"2023-02-03T07:06:04.663852Z","iopub.status.idle":"2023-02-03T07:06:04.717322Z","shell.execute_reply.started":"2023-02-03T07:06:04.663813Z","shell.execute_reply":"2023-02-03T07:06:04.715944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import mean_squared_error\n\nmse = mean_squared_error(y_valid, y_pred)\nfig = plt.figure()\nmulreg = fig.add_subplot(1, 1, 1)\nmulreg.scatter(y_valid, y_pred, color='r')\nmulreg.set_title('Nonlinear Regression')","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:06:04.718961Z","iopub.execute_input":"2023-02-03T07:06:04.719300Z","iopub.status.idle":"2023-02-03T07:06:04.943818Z","shell.execute_reply.started":"2023-02-03T07:06:04.719270Z","shell.execute_reply":"2023-02-03T07:06:04.942674Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction = model.predict(test_set.drop(columns=['segment_id']))","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:06:04.945270Z","iopub.execute_input":"2023-02-03T07:06:04.945637Z","iopub.status.idle":"2023-02-03T07:06:05.108172Z","shell.execute_reply.started":"2023-02-03T07:06:04.945585Z","shell.execute_reply":"2023-02-03T07:06:05.106939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame()  \nsubmission['segment_id'] = test_set['segment_id']\nsubmission['time_to_eruption'] = prediction\nsubmission.to_csv('submission.csv', header=True, index=False)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:06:05.109720Z","iopub.execute_input":"2023-02-03T07:06:05.110871Z","iopub.status.idle":"2023-02-03T07:06:05.134827Z","shell.execute_reply.started":"2023-02-03T07:06:05.110830Z","shell.execute_reply":"2023-02-03T07:06:05.133564Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"keys = list(pd.read_csv(file_list_test[0]).keys()) \nprint(keys)\nnanC = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\nfor index in range(len(file_list_test)):\n    df = pd.read_csv(file_list_test[index]) \n    for key in df.keys():\n        if df[key].isna().sum() == len(pd.read_csv(file_list_train[0])):      \n            nanC[keys.index(key)] += 1\n\nprint(nanC)\ndata={'sensors': keys, 'count': nanC}\nNaNDF = pd.DataFrame(data)\nprint(NaNDF)","metadata":{"execution":{"iopub.status.busy":"2023-02-03T07:06:05.136179Z","iopub.execute_input":"2023-02-03T07:06:05.136959Z","iopub.status.idle":"2023-02-03T08:01:56.555094Z","shell.execute_reply.started":"2023-02-03T07:06:05.136921Z","shell.execute_reply":"2023-02-03T08:01:56.552577Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"NaNDF.plot(figsize =(20, 20), x=\"sensors\", y=\"count\", kind=\"bar\",  rot=5, fontsize=14 )","metadata":{"execution":{"iopub.status.busy":"2023-02-03T08:01:56.559057Z","iopub.execute_input":"2023-02-03T08:01:56.559650Z","iopub.status.idle":"2023-02-03T08:01:56.942161Z","shell.execute_reply.started":"2023-02-03T08:01:56.559553Z","shell.execute_reply":"2023-02-03T08:01:56.941296Z"},"trusted":true},"execution_count":null,"outputs":[]}]}