{"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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center><h3>Work on the challenge 1 of the AML course :</h3> </br>\n <h4> Team 27  <br>\nWith Mirado Rabenasolo, Axel De Sinzoguan, Patrick Iversenc<br></h4></center> ","metadata":{}},{"cell_type":"markdown","source":"<center> <h2> Data Analysis </h2> \n    Here the point is to see what parameters would be pertinent to take into account when we try to predict the delay of an airport. Some hints would be the date/time in the year, the hour of departure, the country, the airline, etc...","metadata":{}},{"cell_type":"code","source":"! pip install scikit-learn==0.21\n! pip install hypopt","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nimport json\nimport warnings\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.dates as mdates\nimport seaborn as sns\nimport tensorflow as tf\nimport numpy as np\nimport tensorflow_probability as tfp\n\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import mean_squared_error\nfrom sklearn.linear_model import Ridge\nfrom sklearn.preprocessing import StandardScaler\nfrom hypopt import GridSearch\nfrom matplotlib import rc \n\nif not sys.warnoptions:\n    warnings.simplefilter(\"ignore\")\n\nrc('figure', **{'dpi': 200})","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Let's load all that we have here\nX_dtype = {\n    'ID'                   : int,\n    'YEAR'                 : int,  \n    'MONTH'                : int,  \n    'DAY'                  : int,  \n    'DAY_OF_WEEK'          : int,  \n    'AIRLINE'              : str, \n    'FLIGHT_NUMBER'        : str,  \n    'TAIL_NUMBER'          : str, \n    'ORIGIN_AIRPORT'       : str, \n    'DESTINATION_AIRPORT'  : str, \n    'SCHEDULED_DEPARTURE'  : str,  \n    'DEPARTURE_TIME'       : str, \n    'DEPARTURE_DELAY'      : float,\n    'TAXI_OUT'             : str, \n    'WHEELS_OFF'           : str,\n    'SCHEDULED_TIME'       : float,\n    'AIR_TIME'             : float,\n    'DISTANCE'             : int,\n    'SCHEDULED_ARRIVAL'    : str,\n    'DIVERTED'             : int,  \n    'CANCELLED'            : int,  \n    'CANCELLATION_REASON'  : str\n}\n\ny_dtype = {\n    'ID'                   : int,\n    \"ARRIVAL_DELAY\"        : float\n}\n\nimport pandas as pd\nairports_df = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/airports.csv')\nairlines_df = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/airlines.csv')\nX_train_df = pd.read_csv(\"/kaggle/input/eurecom-aml-2021-challenge-1/data/train_features.csv\", dtype=X_dtype)\nY_train_df = pd.read_csv(\"/kaggle/input/eurecom-aml-2021-challenge-1/data/train_targets.csv\", dtype=y_dtype)\ntest_df = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/test_features.csv')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Convert date-time features from str to datetime format\ndef parse_hhmm(x):\n    try: return pd.datetime.strptime(x, '%H%M')#.time()\n    except: return pd.NaT\n\nX_train_df.DEPARTURE_TIME = X_train_df.DEPARTURE_TIME.apply(parse_hhmm)\nX_train_df.SCHEDULED_ARRIVAL = X_train_df.SCHEDULED_ARRIVAL.apply(parse_hhmm)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Merging X and Y to get a complete overview of the data\ndf = pd.merge(X_train_df, Y_train_df, on='ID')\ndf.head(5)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Create new columns used for data exploration\ndf['DELAYED'] = (df.ARRIVAL_DELAY > 0).astype(str)\ndf['DATE'] = pd.to_datetime(df[['YEAR', 'MONTH', 'DAY']])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2> Graphs </h2>","metadata":{}},{"cell_type":"code","source":"# Unique origin airports\n_df1 = df.drop_duplicates(['ORIGIN_AIRPORT'])\nindex = _df1.index\nn_rows = len(index)\nprint(\"Number of unique origin airports: {:d}\".format(n_rows))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Unique destination airports\n_df1 = df.drop_duplicates(['DESTINATION_AIRPORT'])\nindex = _df1.index\nn_rows = len(index)\nprint(\"Number of unique destination airports: {:d}\".format(n_rows))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Remark: It is surprising to find a different number of airports.Here it seems like there is an airport which just swallows whatever airplane lands and doesnt let them take off after.","metadata":{}},{"cell_type":"code","source":"# How many airlines\n_df1 = df.drop_duplicates(['AIRLINE'])\nindex = _df1.index\nn_rows = len(index)\nprint(\"Number of airlines: {:d}\".format(n_rows))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Lets see which airport is more prone to have delayed flights\nIt can happen because of dense circulation so lets also see the correlation between flight delay and circulation.","metadata":{}},{"cell_type":"code","source":"# Counting all the flights grouped by airport\n_df1 = df\n_df1['ONE'] = 1 #Adding this to just count the occurences of the airports\n_df2 = df\n_df2['ONE'] = 1 #Adding this to just count the occurences of the airports\n\n_df1 = _df1.groupby('ORIGIN_AIRPORT').agg({'ONE':'sum'}).rename_axis('AIRPORT')\n_df2 = _df2.groupby('DESTINATION_AIRPORT').agg({'ONE':'sum'}).rename_axis('AIRPORT')\n\ntop_airports_circulation = _df1.join(_df2, rsuffix='_ORIGIN', lsuffix=\"_DEST\").sum(axis=1).sort_values(ascending=False)\ntop_airports_circulation.head(15)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Keeping only the delayed flights records\n_df_only_delayed = df[df[\"DELAYED\"] == 'True']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Top 15 airports (in term of arrival total arrival_delay)\n_df1 = _df_only_delayed.groupby('ORIGIN_AIRPORT').agg({'DELAYED':'count'}).rename(columns={'DELAYED': 'COUNT'}).rename_axis('AIRPORT')\n_df2 = _df_only_delayed.groupby('DESTINATION_AIRPORT').agg({'DELAYED':'count'}).rename(columns={'DELAYED': 'COUNT'}).rename_axis('AIRPORT')\ntop_airports = _df1.join(_df2, rsuffix='_ORIGIN', lsuffix='_DEST').sum(axis=1).sort_values(ascending=False)\ntop_airports.head(15)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Lets first merge the two data frames and recover each columns\ntop_airports_df = pd.DataFrame(top_airports)\ntop_airports_circulation_df = pd.DataFrame(top_airports_circulation)\ntop_airports_merged = pd.merge(top_airports_df, top_airports_circulation_df, on='AIRPORT')\ntop_airports_merged = top_airports_merged.rename(columns={'0_x':'DELAYED_COUNT', '0_y':'ALL_COUNT'}).sort_values(by=['DELAYED_COUNT'], ascending=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"values_list = top_airports_merged.values[:40].tolist() #Recover the numbers\nairport_names = top_airports_merged.index[:40].tolist() #Recover the names of the airports\n\n\n# Let's plot now ! We are going to do a stacked bar plot\nfor i in range(len(values_list)):\n    values_list[i][1] = values_list[i][1]-values_list[i][0]\n\n#Separating delayed and non delayed values\ndelayed_L = []\nnon_delayed_L = []\nfor sublist in values_list:\n    delayed_L.append(sublist[0])\n    non_delayed_L.append(sublist[1])\n    \nfig,ax = plt.subplots()\nax.bar(airport_names, delayed_L, 0.5, label='Delayed', color='orange')\nax.bar(airport_names, non_delayed_L, 0.5, bottom=delayed_L, label='Non_delayed', color='blue')\n\nax.set_ylabel('airplanes count')\nax.set_title('Effect of overall circulation on delay')\nax.legend()\nplt.xticks(rotation=90)\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Impact of airline on delay\nLet's do the same type of computation to see the impact of the airline on delay ","metadata":{}},{"cell_type":"code","source":"airlines_delayed = _df_only_delayed.groupby('AIRLINE').agg({'DELAYED':'count'}).rename(columns={'DELAYED': 'COUNT_DELAYED'}).rename_axis('AIRLINE').sort_values(by=['COUNT_DELAYED'], ascending=False)\nairlines_delayed","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"airlines_all = df\nairlines_all['ONE'] = 1 #Adding this to just count the occurences of the airports\nairlines_all = airlines_all.groupby('AIRLINE').agg({'ONE':'sum'}).rename_axis('AIRLINE').rename(columns={'ONE': 'COUNT_ALL'})\nairlines_all","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"airlines_all_df = pd.DataFrame(airlines_all)\nairlines_delayed_df = pd.DataFrame(airlines_delayed)\nairlines_merged = pd.merge(airlines_delayed_df, airlines_all_df, on='AIRLINE')\nairlines_merged","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"airlines_labels = airlines_merged.index.tolist()\nnumbers = airlines_merged.values.tolist()\n# Let's plot now ! We are going to do a stacked bar plot\nfor i in range(len(numbers)):\n    numbers[i][1] = numbers[i][1]-numbers[i][0]\n\n#Separating delayed and non delayed values\ndelayed_L = []\nnon_delayed_L = []\nfor sublist in numbers:\n    delayed_L.append(sublist[0])\n    non_delayed_L.append(sublist[1])\n    \nfig,ax = plt.subplots()\nax.bar(airlines_labels, delayed_L, 0.5, label='Delayed', color='orange')\nax.bar(airlines_labels, non_delayed_L, 0.5, bottom=delayed_L, label='Non_delayed', color='blue')\n\nax.set_ylabel('number of flights')\nax.set_title('Effect of airline on delay')\nax.legend()\nplt.xticks(rotation=90)\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Computing the graph of the percentage of delayed flights for each airline\nairlines_labels = airlines_merged.index.tolist()\nnumbers = airlines_merged.values.tolist()\n\n#Separating delayed and non delayed values\npercentage_L = []\nfor sublist in numbers:\n    percentage_L.append((sublist[0]/sublist[1])*100)\n    \nfig,ax = plt.subplots()\nax.bar(airlines_labels, percentage_L, 0.5, color='blue')\n\nax.set_ylabel('Percent')\nax.set_title('Percentage of delayed flights for each airline')\nax.legend()\nplt.xticks(rotation=90)\nplt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center> <h2> Data Gathering </h2> ","metadata":{}},{"cell_type":"code","source":"import pandas as pd\nairports = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/airports.csv')\nairlines = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/airlines.csv')\nX_train_df = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/train_features.csv')\ny_train_df = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/train_targets.csv')\ntest = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/test_features.csv')\ndisplay(test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<center> <h2> Data Cleaning </h2> </center>","metadata":{}},{"cell_type":"markdown","source":"Firstly we see that there are no information in the DIVERTED and CANCELLED fields.<br>\nThus we can ignore them.\n","metadata":{}},{"cell_type":"markdown","source":"We have to adapt the data to do our neural network. <br>\nIndeed we can replace the airports by their latitude and longitude.","metadata":{}},{"cell_type":"code","source":"y_train_df","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# First we have to merge X train and Y train in order to link each X to its Y\nX_Y_df = pd.merge(X_train_df, y_train_df, on='ID')\nX_Y_df\ndisplay(test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn import preprocessing\n\n# Functions to replace all airport/localisation information with longitude and latitude (data compression)\ndef add_Oairport(df):\n    df1 = df.merge(airports, left_on='ORIGIN_AIRPORT', right_on='IATA_CODE')\n    df2 = df1.drop(columns=[\"ORIGIN_AIRPORT\",\"IATA_CODE\",\"STATE\",\"AIRPORT\",\"COUNTRY\",\"CITY\"])\n    df2.rename(columns={'LONGITUDE':'O_LONG',\n                           'LATITUDE':'O_LAT'}, inplace=True)\n    return df2\n    \ndef add_Dairport(df):\n    df1 = df.merge(airports,left_on='DESTINATION_AIRPORT', right_on='IATA_CODE')\n    df2 = df1.drop(columns=[\"DESTINATION_AIRPORT\",\"IATA_CODE\",\"STATE\",\"AIRPORT\",\"COUNTRY\",\"CITY\"])\n    df2.rename(columns={'LONGITUDE':'D_LONG',\n                           'LATITUDE':'D_LAT'}, inplace=True)\n    return df2\n\n# 1 of K encoding for airlines so that it is fit to a neural network\ndef change_dummies(df):\n    return pd.get_dummies(df.drop(columns=[\"TAIL_NUMBER\"]))\n\n# We drop the columns that are not useful: Here Cancelled, cancellation reason and diverted have no values. Also Taxi_out would be useless here (data analysis)\ndef drop_CDRT(df):\n    return df.drop(columns=[\"ID\", \"FLIGHT_NUMBER\", \"CANCELLED\",\"DIVERTED\",\"CANCELLATION_REASON\",\n                            \"TAXI_OUT\", \"WHEELS_OFF\", \"SCHEDULED_TIME\"])\n\n# Applying all the changes to the df\n#X_Y_df = add_Oairport(X_Y_df)\n#test = add_Oairport(test)\n#X_Y_df = add_Dairport(X_Y_df)\n#test = add_Dairport(test)\nle = preprocessing.LabelEncoder()\nX_Y_df['DESTINATION_AIRPORT'] = le.fit_transform(X_Y_df.DESTINATION_AIRPORT.values)\ntest['DESTINATION_AIRPORT']=le.transform(test.DESTINATION_AIRPORT.values)\nX_Y_df['ORIGIN_AIRPORT'] = le.fit_transform(X_Y_df.ORIGIN_AIRPORT.values)\ntest['ORIGIN_AIRPORT']=le.transform(test.ORIGIN_AIRPORT.values)\nX_Y_df = drop_CDRT(X_Y_df)\ndisplay(test)\nId_test=test['ID']\ntest = drop_CDRT(test)\n\nX_Y_df_cleaned = change_dummies(X_Y_df)\ntest_cleaned = change_dummies(test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Now we have to change the times (houres) in number of minutes so that we don't have discontinuities.","metadata":{}},{"cell_type":"code","source":"import matplotlib.dates as mdates\n\n\n#we change dates into minutes so that we don't have discontinuities.\ndef time_minute(x):\n    return (x//100)*60 + x%100\n\ndef change_time(df):\n    df.DEPARTURE_TIME = df.DEPARTURE_TIME.apply(time_minute)\n    df.SCHEDULED_DEPARTURE = df.SCHEDULED_DEPARTURE.apply(time_minute)\n    df.SCHEDULED_ARRIVAL = df.SCHEDULED_ARRIVAL.apply(time_minute)\n    \nchange_time(X_Y_df_cleaned)\nchange_time(test_cleaned)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Finally, we get our cleaned training and testing data. <br>\nWe can verify that our data is clean with dtypes.","metadata":{}},{"cell_type":"code","source":"X_Y_df_cleaned.dtypes","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"I said that the tail number wasn't an important figure <br>\nWith pd.get_dummies() we perform 1 of K encoding on the categorical variable Airline. <br>\nSo [0,0,0,0,1,0,0,0] means that the airline is the fifth possible airline.","metadata":{}},{"cell_type":"code","source":"def change_type(df):\n    return df.astype('float32')\nX_Y_df_floats = change_type(X_Y_df_cleaned)\ntest_floats = change_type(test_cleaned)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_Y_df_floats.dtypes","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2> <center> Neurol Network Try </center> </h2>\n","metadata":{}},{"cell_type":"code","source":"# We would like to crop the dataset to lighten the memory use and fasten the training\nX_Y_df_croped = X_Y_df_floats[1500000:2000000] # crop the dataset\n\n# Test set of the data that we didn't use to train\nX_Y_df_verif = X_Y_df_floats[2500000:3000000]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Separation of X_Y_verif into X_verif and Y_verif\narray_Y_verif = np.array(X_Y_df_verif['ARRIVAL_DELAY'])\nX_verif = X_Y_df_verif.drop(columns=['ARRIVAL_DELAY'])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Getting the target array\narray_target = np.array(X_Y_df_croped['ARRIVAL_DELAY'])\n\n# Getting the rest into train_array\n# First drop the arrival_delay column\nX_Y_df_train_only = X_Y_df_croped.drop(columns=['ARRIVAL_DELAY'])\n# Now we clean up the train and test dataframes so that there is no more Nan values which are not supported by the models\nfrom sklearn.impute import SimpleImputer\nimp_mean = SimpleImputer(missing_values=np.nan, strategy='mean')\narray_train = imp_mean.fit_transform(X_Y_df_train_only)\narray_test = imp_mean.fit_transform(test_floats)\narray_X_verif = imp_mean.fit_transform(X_verif)\n\n#array_train = np.array(X_Y_df_train_only)\n#array_test = np.array(test_floats)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_floats.dtypes","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Checking the rows with NaN values in it\n### isnan = test_floats.isnull()\n#rows=isnan.any(axis=1)\n#rows2=test_floats[rows]\n\n#isnan =solution.isnull()\n#rows=isnan.any(axis=1)\n#rows2=solution[rows]\n#rows2","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# To check the number of records in the array\n#array_target.shape\n#array_train.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install scikit-neuralnetwork","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neural_network import MLPRegressor\n\nmlp = MLPRegressor(hidden_layer_sizes=(100,100,60,30), activation='relu', solver='adam', alpha=0,\n                   learning_rate='adaptive', learning_rate_init=0.005, max_iter=100, \n                   verbose=True, early_stopping=True, n_iter_no_change=6)\n\nmlp.fit(array_train, array_target)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mlp.score(array_train, array_target)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Verification of performance using the testing set\nmlp.score(array_X_verif, array_Y_verif)\n\n#verification = mlp.predict(array_X_verif)\n#dist = np.linalg.norm(verification-np.array(Y_verif))\n#print(dist)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This cell is for the submission of our results\nprediction = mlp.predict(array_test)\n\nsubmission_df = pd.DataFrame(data={'ID': Id_test,\n                                   'ARRIVAL_DELAY': prediction.squeeze()})\ndisplay(submission_df)\nsubmission_df.to_csv(\"/kaggle/working/submission_final.csv\", index=False)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Tuning hyperparameters with GridSearch","metadata":{}},{"cell_type":"code","source":"#from sklearn.model_selection import GridSearchCV\n\n#tuned_parameters = [{'n_iter_no_change':[3,4,5], 'learning_rate_init': [0.005, 0.001, 0.0005, 0.0001, 0.00005]}]\n#tuned_parameters = [{'n_iter_no_change':[5, 6, 7], 'learning_rate_init': [0.005]}]\n#mlp_tuned = GridSearchCV(MLPRegressor(hidden_layer_sizes=(100,100,60,30), activation='relu', solver='adam', alpha=0,\n#                   learning_rate='adaptive', max_iter=100, \n#                   verbose=False, early_stopping=True),\n#                    tuned_parameters)\n#mlp_tuned.fit(array_train, array_target)\n\n#print(\"Best parameter found:\")\n#print(mlp_tuned.best_params_)\n#means = mlp_tuned.cv_results_['mean_test_score']\n#print(\"Grid scores:\")\n#print(means)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Cross validation on MLP","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscores = cross_val_score(mlp, array_train, array_target, cv=5)\nscores","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<h2> <center> Random Forest Try </center> </h2>","metadata":{}},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestRegressor\nfrom sklearn.datasets import make_regression","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"rf = RandomForestRegressor(n_estimators = 100, random_state = 2020)\nrf.fit(array_train,array_target)\nprediction = rf.predict(array_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Verification of performance using the testing set\nrf.score(array_X_verif, array_Y_verif)\n\n#verification_RF = rf.predict(array_X_verif)\n#dist = np.linalg.norm(verification_RF-np.array(Y_verif))\n#print(dist)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nsubmission2_df = pd.DataFrame(data={'ID': Id_test,\n                                   'ARRIVAL_DELAY': prediction.squeeze()})\ndisplay(submission2_df)\nsubmission_df.to_csv(\"/kaggle/working/submission_final.csv\", index=False)\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}