{"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 pandas as pd \nimport matplotlib.pyplot as plt \nimport numpy as np \nimport seaborn as sns\nfrom tqdm.notebook import tqdm\n\nimport matplotlib\nfrom matplotlib import rc\n\nrc(\"font\", **{\"family\": \"sans-serif\", \"sans-serif\": \"DejaVu Sans\"})\nrc(\"figure\", **{\"dpi\": 200})\nrc(\n    \"axes\",\n    **{\"spines.right\": False, \"spines.top\": False, \"xmargin\": 0.0, \"ymargin\": 0.05}\n)","metadata":{"_uuid":"349a1362-e369-49ae-906d-1b5f8a48475d","_cell_guid":"994dad23-6226-4b87-a0be-56f9a378ac40","collapsed":false,"jupyter":{"outputs_hidden":false},"execution":{"iopub.status.busy":"2022-05-10T17:38:55.316797Z","iopub.execute_input":"2022-05-10T17:38:55.317576Z","iopub.status.idle":"2022-05-10T17:38:56.683744Z","shell.execute_reply.started":"2022-05-10T17:38:55.317385Z","shell.execute_reply":"2022-05-10T17:38:56.682569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load the Dataset","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv('../input/eurecom-aml-2022-challenge-1/public/train.csv', low_memory=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:38:57.13189Z","iopub.execute_input":"2022-05-10T17:38:57.132837Z","iopub.status.idle":"2022-05-10T17:40:40.066727Z","shell.execute_reply.started":"2022-05-10T17:38:57.132783Z","shell.execute_reply":"2022-05-10T17:40:40.065623Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv('../input/eurecom-aml-2022-challenge-1/public/test_feat.csv', low_memory=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:40:40.068488Z","iopub.execute_input":"2022-05-10T17:40:40.06877Z","iopub.status.idle":"2022-05-10T17:41:06.984923Z","shell.execute_reply.started":"2022-05-10T17:40:40.068731Z","shell.execute_reply":"2022-05-10T17:41:06.983704Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Data Analysis\n\n","metadata":{}},{"cell_type":"code","source":"df.plot(\n    kind=\"scatter\",\n    x=\"fact_longitude\",\n    y=\"fact_latitude\",\n    alpha=0.4,\n    c=\"fact_temperature\",\n    cmap=plt.get_cmap(\"jet\"), colorbar=True, figsize=(15,8))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:18:24.384884Z","iopub.execute_input":"2022-05-10T17:18:24.385249Z","iopub.status.idle":"2022-05-10T17:19:22.571677Z","shell.execute_reply.started":"2022-05-10T17:18:24.385221Z","shell.execute_reply":"2022-05-10T17:19:22.57105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.plot(\n    kind=\"scatter\",\n    x=\"fact_longitude\",\n    y=\"fact_latitude\",\n    alpha=0.4,\n    c=\"climate_pressure\",\n    cmap=plt.get_cmap(\"jet\"), colorbar=True, figsize=(15,8))\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:19:22.976774Z","iopub.execute_input":"2022-05-10T17:19:22.977386Z","iopub.status.idle":"2022-05-10T17:20:23.60477Z","shell.execute_reply.started":"2022-05-10T17:19:22.977344Z","shell.execute_reply":"2022-05-10T17:20:23.604108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.info()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:20:23.606258Z","iopub.execute_input":"2022-05-10T17:20:23.606599Z","iopub.status.idle":"2022-05-10T17:20:23.629103Z","shell.execute_reply.started":"2022-05-10T17:20:23.606567Z","shell.execute_reply":"2022-05-10T17:20:23.628164Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:20:23.630147Z","iopub.execute_input":"2022-05-10T17:20:23.630439Z","iopub.status.idle":"2022-05-10T17:20:30.085029Z","shell.execute_reply.started":"2022-05-10T17:20:23.630411Z","shell.execute_reply":"2022-05-10T17:20:30.084325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nans = df.isna().sum()\nnans","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:20:30.086921Z","iopub.execute_input":"2022-05-10T17:20:30.087142Z","iopub.status.idle":"2022-05-10T17:20:30.359968Z","shell.execute_reply.started":"2022-05-10T17:20:30.087113Z","shell.execute_reply":"2022-05-10T17:20:30.359284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Outliers Analysis","metadata":{}},{"cell_type":"code","source":"Q1 = df.quantile(0.25)\nQ3 = df.quantile(0.75)\nIQR = Q3 - Q1\nprint(IQR)\ndf_train_out = df[~((df < (Q1 - 1.5 * IQR)) |(df > (Q3 + 1.5 * IQR))).any(axis=1)] # ~ ==> Not Operator\nprint(f\"Outliers count: {df.shape[0]-df_train_out.shape[0]}\")","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:21:26.489738Z","iopub.execute_input":"2022-05-10T17:21:26.489941Z","iopub.status.idle":"2022-05-10T17:21:32.825929Z","shell.execute_reply.started":"2022-05-10T17:21:26.48992Z","shell.execute_reply":"2022-05-10T17:21:32.825111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Remove Index\nunnorm_df = df.iloc[:,1:]\n#SORTED BY MAX for each column\n#df = df.loc[:, df.max().sort_values(ascending=False).index]\nunnorm_df = df","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:21:55.50757Z","iopub.execute_input":"2022-05-10T17:21:55.507842Z","iopub.status.idle":"2022-05-10T17:21:55.7593Z","shell.execute_reply.started":"2022-05-10T17:21:55.507812Z","shell.execute_reply":"2022-05-10T17:21:55.758538Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Availability df","metadata":{}},{"cell_type":"code","source":"avail_col = unnorm_df.loc[:,[col for col in unnorm_df.columns if \"available\" in col]]\navail_col.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:22:25.220261Z","iopub.execute_input":"2022-05-10T17:22:25.220543Z","iopub.status.idle":"2022-05-10T17:22:25.393275Z","shell.execute_reply.started":"2022-05-10T17:22:25.220515Z","shell.execute_reply":"2022-05-10T17:22:25.392629Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### cmc df","metadata":{}},{"cell_type":"code","source":"cmc_col = unnorm_df.loc[:,[col for col in unnorm_df.columns if \"cmc\" in col and \"available\" not in col]]\nprint(cmc_col.columns.shape)\ndf=cmc_col\ndf=df.dropna()\ndf.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:22:40.933323Z","iopub.execute_input":"2022-05-10T17:22:40.933727Z","iopub.status.idle":"2022-05-10T17:22:44.009083Z","shell.execute_reply.started":"2022-05-10T17:22:40.933686Z","shell.execute_reply":"2022-05-10T17:22:44.008301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(4, 3, figsize=(35,30))\ndf = df.loc[:, df.max().sort_values(ascending=False).index]\n#Min-Max Normalization\ndf=(df-df.min())/(df.max()-df.min())\ndf = df.reindex(sorted(df.columns), axis=1)\nsns.boxplot(ax=axes[0,0],data=df.iloc[:, :4], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[0,1],data=df.iloc[:, 4:8], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[0,2],data=df.iloc[:, 8:12], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,0],data=df.iloc[:, 12:16], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,1],data=df.iloc[:, 16:20], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,2],data=df.iloc[:, 20:24], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,0],data=df.iloc[:, 24:28], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,1],data=df.iloc[:, 28:32], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,2],data=df.iloc[:, 32:36], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,0],data=df.iloc[:, 36:40], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,1],data=df.iloc[:, 40:43], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,2],data=df.iloc[:, 43:], orient=\"v\", palette=\"Set2\")","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:22:53.390605Z","iopub.execute_input":"2022-05-10T17:22:53.390866Z","iopub.status.idle":"2022-05-10T17:24:23.497787Z","shell.execute_reply.started":"2022-05-10T17:22:53.390836Z","shell.execute_reply":"2022-05-10T17:24:23.497086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### gfs df","metadata":{}},{"cell_type":"code","source":"gfs_col = unnorm_df.loc[:,[col for col in unnorm_df.columns if \"gfs\" in col and \"available\" not in col]]\nprint(gfs_col.columns.shape)\ndf=gfs_col\ndf=df.dropna()\ndf.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:24:23.499448Z","iopub.execute_input":"2022-05-10T17:24:23.499723Z","iopub.status.idle":"2022-05-10T17:24:26.726201Z","shell.execute_reply.started":"2022-05-10T17:24:23.499686Z","shell.execute_reply":"2022-05-10T17:24:26.725422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(4, 3, figsize=(35, 30))\ndf = df.loc[:, df.max().sort_values(ascending=False).index]\ndf=(df-df.min())/(df.max()-df.min())\ndf.rename(columns = {'gfs_total_clouds_cover_middle':'t_clouds_cover_mid','gfs_total_clouds_cover_high':'t_clouds_cover_high',}, inplace = True)\ndf = df.reindex(sorted(df.columns), axis=1)\nsns.boxplot(ax=axes[0,0],data=df.iloc[:, :4], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[0,1],data=df.iloc[:, 4:8], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[0,2],data=df.iloc[:, 8:12], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,0],data=df.iloc[:, 12:16], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,1],data=df.iloc[:, 16:20], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1,2],data=df.iloc[:, 20:24], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,0],data=df.iloc[:, 24:28], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,1],data=df.iloc[:, 28:32], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2,2],data=df.iloc[:, 32:35], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,0],data=df.iloc[:, 35:38], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,1],data=df.iloc[:, 38:41], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[3,2],data=df.iloc[:, 41:], orient=\"v\", palette=\"Set2\")","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:24:26.727179Z","iopub.execute_input":"2022-05-10T17:24:26.727391Z","iopub.status.idle":"2022-05-10T17:25:38.071009Z","shell.execute_reply.started":"2022-05-10T17:24:26.727341Z","shell.execute_reply":"2022-05-10T17:25:38.070429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### wrf df","metadata":{}},{"cell_type":"code","source":"wrf_col = unnorm_df.loc[:,[col for col in unnorm_df .columns if \"wrf\" in col and \"available\" not in col]]\nprint(wrf_col.columns.shape)\ndf=wrf_col\ndf=df.dropna()\ndf.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:25:38.072477Z","iopub.execute_input":"2022-05-10T17:25:38.073133Z","iopub.status.idle":"2022-05-10T17:25:38.756126Z","shell.execute_reply.started":"2022-05-10T17:25:38.073103Z","shell.execute_reply":"2022-05-10T17:25:38.755418Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, axes = plt.subplots(1, 3, figsize=(18, 10))\ndf = df.loc[:, df.max().sort_values(ascending=False).index]\ndf=(df-df.min())/(df.max()-df.min())\ndf = df.reindex(sorted(df.columns), axis=1)\nsns.boxplot(ax=axes[0],data=df.iloc[:, :4], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[1],data=df.iloc[:, 4:7], orient=\"v\", palette=\"Set2\")\nsns.boxplot(ax=axes[2],data=df.iloc[:, 7:], orient=\"v\", palette=\"Set2\")","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:25:38.75716Z","iopub.execute_input":"2022-05-10T17:25:38.757348Z","iopub.status.idle":"2022-05-10T17:25:58.953942Z","shell.execute_reply.started":"2022-05-10T17:25:38.757322Z","shell.execute_reply":"2022-05-10T17:25:58.953222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### other features df","metadata":{}},{"cell_type":"code","source":"other_col = unnorm_df.drop(columns=[col for col in unnorm_df.columns if \"wrf\" in col or \"gfs\" in col or \"cmc\" in col or \"available\" in col])\nprint(other_col.columns.shape)\ndf=other_col\ndf=df.dropna()\ndf.describe().T","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:25:58.95495Z","iopub.execute_input":"2022-05-10T17:25:58.955143Z","iopub.status.idle":"2022-05-10T17:25:59.669558Z","shell.execute_reply.started":"2022-05-10T17:25:58.955118Z","shell.execute_reply":"2022-05-10T17:25:59.668875Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Further experiments","metadata":{}},{"cell_type":"code","source":"\"\"\"\nfrom sklearn.ensemble import IsolationForest\n\n#1 identify outliers in the training dataset\niso = IsolationForest(contamination=0.1)\nyhat = iso.fit_predict(X_train)\n\nfrom sklearn.svm import OneClassSVM\n\n#2 identify outliers in the training dataset\nee = OneClassSVM(nu=0.01)\nyhat = ee.fit_predict(X_train)\n\nfrom sklearn.neighbors import LocalOutlierFactor\n\n#3 identify outliers in the training dataset\nlof = LocalOutlierFactor()\nyhat = lof.fit_predict(X_train)\n\n#Needed for each of the above methods: select all rows that are not outliers\nmask = yhat != -1\nX_train, y_train = X_train[mask, :], y_train[mask]\n\"\"\"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Correlation analysis","metadata":{}},{"cell_type":"code","source":"df = unnorm_df","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:32:28.21108Z","iopub.execute_input":"2022-05-10T17:32:28.211466Z","iopub.status.idle":"2022-05-10T17:32:28.216254Z","shell.execute_reply.started":"2022-05-10T17:32:28.211434Z","shell.execute_reply":"2022-05-10T17:32:28.215187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target = df['fact_temperature']\ncorr_feats = df.corrwith(target)\ncorr_feats","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:32:30.430803Z","iopub.execute_input":"2022-05-10T17:32:30.431866Z","iopub.status.idle":"2022-05-10T17:32:32.97395Z","shell.execute_reply.started":"2022-05-10T17:32:30.431799Z","shell.execute_reply":"2022-05-10T17:32:32.973196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.corr().abs()","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:32:51.54594Z","iopub.execute_input":"2022-05-10T17:32:51.546215Z","iopub.status.idle":"2022-05-10T17:33:39.135022Z","shell.execute_reply.started":"2022-05-10T17:32:51.546186Z","shell.execute_reply":"2022-05-10T17:33:39.134152Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Feature Importances (Random Forest)","metadata":{}},{"cell_type":"code","source":"# Fill mean value with NaNs\nfor col in df.columns:\n    df[col].fillna(df[col].mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:42:26.615241Z","iopub.execute_input":"2022-05-10T17:42:26.615878Z","iopub.status.idle":"2022-05-10T17:42:27.798354Z","shell.execute_reply.started":"2022-05-10T17:42:26.615824Z","shell.execute_reply":"2022-05-10T17:42:27.797469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.pipeline import Pipeline\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.preprocessing import RobustScaler\n\npipeline = Pipeline([\n                     ('scaler', RobustScaler()),\n                     ('model',RandomForestRegressor(n_estimators=10, max_depth=30,\n                                                    n_jobs=-1)\n                     )\n])\n\nsearch = GridSearchCV(pipeline,\n                      {'model__n_estimators':[10]},\n                      cv = 5, \n                      scoring=\"neg_mean_squared_error\",\n                      verbose=1\n                      )\n\nsearch.fit(\n    df.iloc[:,:-1],\n    df['fact_temperature']\n)\n\ncoefficients = search.best_estimator_.named_steps['model'].feature_importances_","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:38:19.297857Z","iopub.execute_input":"2022-05-10T17:38:19.298139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(pd.Series(coefficients, index=df.iloc[:,:-1].columns)\n   .nlargest(20)\n   .plot(kind='barh'))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"(pd.Series(coefficients, index=df.iloc[:,:-1].columns)\n   .nlargest(20)\n)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## wasserstein_dist","metadata":{}},{"cell_type":"code","source":"def wasserstein_dist(feat1, feat2):\n    counts1, bin_edges1 = np.histogram(feat1,bins=100,density=True)\n    counts2, bin_edges2 = np.histogram(feat2,bins=100,density=True)\n    pdf1 = counts1/sum(counts1)\n    pdf2 = counts2/sum(counts2)\n    cdf1 = np.cumsum(pdf1)\n    cdf2 = np.cumsum(pdf2)\n    return np.sum(np.abs(cdf1-cdf2))\n\nfeat_dict = {col: wasserstein_dist(df[col], df_test[col]) for col in df.drop(columns=['fact_temperature']).columns}\nfeat_dict = dict(sorted(feat_dict.items(), key=lambda item: item[1]))\nfeat_sel = [item[0] for item in feat_dict.items() if item[1] < 7]\nfor item in feat_dict.items():\n    print(item)","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:43:25.447847Z","iopub.execute_input":"2022-05-10T17:43:25.448539Z","iopub.status.idle":"2022-05-10T17:43:32.842517Z","shell.execute_reply.started":"2022-05-10T17:43:25.4485Z","shell.execute_reply":"2022-05-10T17:43:32.841483Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## ","metadata":{}},{"cell_type":"markdown","source":"# Model Selection","metadata":{}},{"cell_type":"code","source":"from sklearn.pipeline import Pipeline\nfrom sklearn.ensemble import RandomForestRegressor\nfrom sklearn.model_selection import GridSearchCV, train_test_split\nfrom sklearn.preprocessing import StandardScaler, RobustScaler\nfrom sklearn.decomposition import PCA\n\ndef run_experiment(df, col_selection, pca=None, scaler=None, \n                   model=None, model_parameters=None, cv=None):\n    \n    if col_selection:\n        df_train = df.loc[:, col_selection].copy()\n    else:\n        df_train = df.iloc[:, :-1].copy()\n    \n\n    \n    if pca is not None:\n        pipeline =  Pipeline([\n                        ('scaler', scaler),\n                        ('pca', pca),\n                        ('model', model),\n                        ])\n    else:\n        pipeline = Pipeline([\n                ('scaler', scaler),\n                ('model', model),\n            ])\n\n    search = GridSearchCV(pipeline,\n                        model_parameters,\n                        cv = cv, \n                        scoring='neg_root_mean_squared_error',\n                        verbose=1\n                        )\n    \n    return search, df_train, df.iloc[:,-1]","metadata":{"execution":{"iopub.status.busy":"2022-05-10T17:44:06.836679Z","iopub.execute_input":"2022-05-10T17:44:06.839464Z","iopub.status.idle":"2022-05-10T17:44:07.214546Z","shell.execute_reply.started":"2022-05-10T17:44:06.839417Z","shell.execute_reply":"2022-05-10T17:44:07.213855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Ridge HyperParameters Tuning","metadata":{}},{"cell_type":"code","source":"from sklearn.linear_model import Ridge\n\ncol_selection = None\npca = PCA()\nscaler = StandardScaler()\nmodel = Ridge()\nmodel_parameters = {'model__alpha': [.1, .03, .01]}\n\ncv = 5\n\nsearch, X, y = run_experiment(df, col_selection, pca, scaler, model, model_parameters, cv)\n\nsearch.fit(X, y)\n\nsearch.best_score_, search.best_params_","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Random Forest HyperParameters tuning","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\n\ncol_selection = ['wrf_t2_interpolated', 'topography_bathymetry', 'sun_elevation',\n 'wrf_t2_next', 'gfs_pressure', 'gfs_soil_temperature', 'climate_pressure',\n 'cmc_0_3_0_0_next', 'wrf_rh2', 'cmc_0_3_0_0']\n\npca = None\nscaler = StandardScaler()\nmodel = RandomForestRegressor(n_jobs=-1)\nmodel_parameters = {\n    'model__n_estimators': [2, 3, 5, 7, 10],\n    'model__max_depth': [15, 20, 40, 60]\n}\n\ncv = 5\n\nsearch, X, y = run_experiment(df, col_selection, pca, scaler, model, model_parameters, cv)\n\nsearch.fit(X,y)\n\nprint(search.best_score_, search.best_params_)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# CatBoost HyperParameters Tuning","metadata":{}},{"cell_type":"code","source":"!pip install catboost","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\nfrom catboost import CatBoostRegressor\n\nmodel = CatBoostRegressor(task_type=\"GPU\", \n                          devices='0:1',\n                          loss_function='RMSE',\n                          learning_rate=.1)\n\ncol_selection=None\npca = None\nscaler = StandardScaler()\nmodel_parameters = {\n    'model__learning_rate': [.1, .01],\n    'model__iterations': [1000, 10000],\n    'model__depth': [8, 10]\n    }\n\ncv = 5\n\nsearch, X, y = run_experiment(df, col_selection, pca, scaler, model, model_parameters, cv)\nsearch.fit(X, y)\n\nsearch.best_score_, search.best_params_","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Submission","metadata":{}},{"cell_type":"code","source":"y_pred = search.best_estimator_.predict(df_test)\n\nsubmission_df = pd.DataFrame(data={'index': df_test['index'].values,\n                                   'fact_temperature': y_pred.squeeze()})\n\n# Save the predictions into a csv file\n# Notice that this file should be saved under the directory `/kaggle/working` \n# so that you can download it later\nsubmission_df.to_csv('/kaggle/working/submission.csv', index=False)","metadata":{},"execution_count":null,"outputs":[]}]}