{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","execution":{"iopub.execute_input":"2020-10-13T14:08:30.451185Z","iopub.status.busy":"2020-10-13T14:08:30.450247Z","iopub.status.idle":"2020-10-13T14:08:31.687013Z","shell.execute_reply":"2020-10-13T14:08:31.685625Z"},"papermill":{"duration":1.261883,"end_time":"2020-10-13T14:08:31.687265","exception":false,"start_time":"2020-10-13T14:08:30.425382","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport glob\nfrom tqdm import tqdm\n# from sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\n# from sklearn.metrics import mean_absolute_error\nfrom sklearn.svm import SVR\nfrom sklearn.model_selection import KFold","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","execution":{"iopub.execute_input":"2020-10-13T14:08:31.719643Z","iopub.status.busy":"2020-10-13T14:08:31.718724Z","iopub.status.idle":"2020-10-13T14:08:31.891704Z","shell.execute_reply":"2020-10-13T14:08:31.890867Z"},"papermill":{"duration":0.191205,"end_time":"2020-10-13T14:08:31.891856","exception":false,"start_time":"2020-10-13T14:08:31.700651","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"train_file = glob.glob('../input/predict-volcanic-eruptions-ingv-oe/train/*')\ntest_file = glob.glob('../input/predict-volcanic-eruptions-ingv-oe/test/*')","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:08:31.929132Z","iopub.status.busy":"2020-10-13T14:08:31.928301Z","iopub.status.idle":"2020-10-13T14:16:34.427317Z","shell.execute_reply":"2020-10-13T14:16:34.428017Z"},"papermill":{"duration":482.523673,"end_time":"2020-10-13T14:16:34.428228","exception":false,"start_time":"2020-10-13T14:08:31.904555","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df = pd.read_csv(train_file[0])\ndf_mean = pd.DataFrame(df.mean()).T\ndf_mean['id'] = train_file[0].split('/')[-1].split('.')[0]\ntrain_file.remove(train_file[0])\nfor file in tqdm(train_file):\n    df = pd.read_csv(file)\n    df_ = pd.DataFrame(df.mean()).T\n    df_['id'] = file.split('/')[-1].split('.')[0]\n    df_mean = pd.concat([df_mean,df_])\n    del df\ndf_mean.head(3)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:37.59476Z","iopub.status.busy":"2020-10-13T14:16:37.593996Z","iopub.status.idle":"2020-10-13T14:16:37.619435Z","shell.execute_reply":"2020-10-13T14:16:37.618625Z"},"papermill":{"duration":1.635008,"end_time":"2020-10-13T14:16:37.619598","exception":false,"start_time":"2020-10-13T14:16:35.98459","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df_train = pd.read_csv('../input/predict-volcanic-eruptions-ingv-oe/train.csv')\ndf_train.head(2)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:40.846075Z","iopub.status.busy":"2020-10-13T14:16:40.845017Z","iopub.status.idle":"2020-10-13T14:16:40.848799Z","shell.execute_reply":"2020-10-13T14:16:40.848122Z"},"papermill":{"duration":1.644348,"end_time":"2020-10-13T14:16:40.848943","exception":false,"start_time":"2020-10-13T14:16:39.204595","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df_mean['id'] = df_mean['id'].astype('int64')","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:43.995001Z","iopub.status.busy":"2020-10-13T14:16:43.994205Z","iopub.status.idle":"2020-10-13T14:16:44.032316Z","shell.execute_reply":"2020-10-13T14:16:44.031549Z"},"papermill":{"duration":1.617342,"end_time":"2020-10-13T14:16:44.032458","exception":false,"start_time":"2020-10-13T14:16:42.415116","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df_mean = df_mean.join(df_train.set_index('segment_id'), on='id')\ndf_mean.head(3)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:47.264969Z","iopub.status.busy":"2020-10-13T14:16:47.262394Z","iopub.status.idle":"2020-10-13T14:16:47.274041Z","shell.execute_reply":"2020-10-13T14:16:47.273206Z"},"papermill":{"duration":1.635307,"end_time":"2020-10-13T14:16:47.274174","exception":false,"start_time":"2020-10-13T14:16:45.638867","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"X_train = df_mean.drop(['id','time_to_eruption'],axis=1)\ny_train = df_mean['time_to_eruption']\nX_train = X_train.fillna(X_train.mean())\ndel df_mean","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:50.466665Z","iopub.status.busy":"2020-10-13T14:16:50.465599Z","iopub.status.idle":"2020-10-13T14:16:50.469554Z","shell.execute_reply":"2020-10-13T14:16:50.468739Z"},"papermill":{"duration":1.636524,"end_time":"2020-10-13T14:16:50.469688","exception":false,"start_time":"2020-10-13T14:16:48.833164","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"# X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.15)\n# clf = LinearRegression().fit(X_train,y_train)\n# y_pred = clf.predict(X_test)\n# print('MAE:',mean_absolute_error(y_test,y_pred))","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:16:53.595768Z","iopub.status.busy":"2020-10-13T14:16:53.59008Z","iopub.status.idle":"2020-10-13T14:25:36.68728Z","shell.execute_reply":"2020-10-13T14:25:36.686453Z"},"papermill":{"duration":524.662604,"end_time":"2020-10-13T14:25:36.687417","exception":false,"start_time":"2020-10-13T14:16:52.024813","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"df = pd.read_csv(test_file[0])\ndf_mean_test = pd.DataFrame(df.mean()).T\ndf_mean_test['id'] = test_file[0].split('/')[-1].split('.')[0]\ntest_file.remove(test_file[0])\nfor file in tqdm(test_file):\n    df = pd.read_csv(file)\n    df_ = pd.DataFrame(df.mean()).T\n    df_['id'] = file.split('/')[-1].split('.')[0]\n    df_mean_test = pd.concat([df_mean_test,df_])\n    del df\ndf_mean_test.head(3)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:25:43.283845Z","iopub.status.busy":"2020-10-13T14:25:43.28304Z","iopub.status.idle":"2020-10-13T14:25:43.305576Z","shell.execute_reply":"2020-10-13T14:25:43.304817Z"},"papermill":{"duration":3.248447,"end_time":"2020-10-13T14:25:43.30571","exception":false,"start_time":"2020-10-13T14:25:40.057263","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"X_test = df_mean_test.fillna(df_mean_test.mean())\n# X_test = X_test.drop(['id'],axis=1)\ndel df_mean_test","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:25:49.903937Z","iopub.status.busy":"2020-10-13T14:25:49.903085Z","iopub.status.idle":"2020-10-13T14:25:50.129144Z","shell.execute_reply":"2020-10-13T14:25:50.128312Z"},"papermill":{"duration":3.58971,"end_time":"2020-10-13T14:25:50.129285","exception":false,"start_time":"2020-10-13T14:25:46.539575","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"clfsvrpoly = SVR(kernel='poly').fit(X_train,y_train)\nclfsvrrbf = SVR(kernel='rbf').fit(X_train,y_train)\n\ny_pred = clfsvrpoly.predict(X_test.drop(['id'],axis=1))\ny_pred += clfsvrrbf.predict(X_test.drop(['id'],axis=1))\nX_test['y_pred'] = y_pred / 2","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:25:56.718451Z","iopub.status.busy":"2020-10-13T14:25:56.717685Z","iopub.status.idle":"2020-10-13T14:25:57.4648Z","shell.execute_reply":"2020-10-13T14:25:57.465382Z"},"papermill":{"duration":4.019408,"end_time":"2020-10-13T14:25:57.465578","exception":false,"start_time":"2020-10-13T14:25:53.44617","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"submission = pd.read_csv('../input/predict-volcanic-eruptions-ingv-oe/sample_submission.csv')\nX_test['id'] = X_test['id'].astype('int64')\nsubmission = submission.join(X_test[['id','y_pred']].set_index('id'), on='segment_id')\ndel submission['time_to_eruption']\nsubmission.rename({'y_pred':'time_to_eruption'},axis=1,inplace=True)\nsubmission.to_csv('submission.csv',index=False)","execution_count":null,"outputs":[]},{"metadata":{"execution":{"iopub.execute_input":"2020-10-13T14:26:04.073578Z","iopub.status.busy":"2020-10-13T14:26:04.072567Z","iopub.status.idle":"2020-10-13T14:26:04.839358Z","shell.execute_reply":"2020-10-13T14:26:04.838708Z"},"papermill":{"duration":4.009422,"end_time":"2020-10-13T14:26:04.839545","exception":false,"start_time":"2020-10-13T14:26:00.830123","status":"completed"},"tags":[],"trusted":true},"cell_type":"code","source":"!head submission.csv","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}