{"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":"! pip install scikit-learn\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 sklearn.model_selection import GridSearchCV\nfrom hypopt import GridSearch\nfrom matplotlib import rc \nfrom sklearn.pipeline import make_pipeline\n\nif not sys.warnoptions:\n    warnings.simplefilter(\"ignore\")\n\nrc('figure', **{'dpi': 300})\n\n\nfrom geopy.geocoders import Nominatim\nfrom sklearn.preprocessing import OneHotEncoder\nfrom sklearn.model_selection import cross_validate\nfrom tqdm.notebook import tqdm","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_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}","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"First we load Airport CSV, then we fill the missing airports manually with longitute and latitude after some breef reserches on google. The we use *geopy.geocoders* api to augument such dataset with information about the State of each airport","metadata":{}},{"cell_type":"code","source":"airports = pd.read_csv('/kaggle/input/eurecom-aml-2021-challenge-1/data/airports.csv',\n                       usecols=['IATA_CODE', 'AIRPORT', 'LATITUDE', 'LONGITUDE']).rename({'AIRPORT': 'NAME'}, axis='columns')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"airports['LATITUDE'][96] = 30.35487990060177\nairports['LONGITUDE'][96] = -85.80029074040878\nairports['LATITUDE'][234] = 44.652067311464805\nairports['LONGITUDE'][234] = -73.46788811537634\nairports['LATITUDE'][313] = 29.954510826098844\nairports['LONGITUDE'][313] = -81.34199038002613","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"geolocator = Nominatim(user_agent=\"http\")\ndef find_state(lat, long, geolocator):\n    #print(f\"{lat}, {long}\")\n    location = geolocator.reverse(f\"{lat}, {long}\")\n    try:\n        return location.raw['address']['state']\n    except:\n        return \"None\"\n# r  = find_state(\"40.65236\", \"-75.44040\", geolocator)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"airports['State'] = airports.apply(lambda row : find_state(row['LATITUDE'], row['LONGITUDE'], geolocator), axis = 1)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The function *preprocessX* is used first merge the feature train dataset with the airport dataset and add for each IATA code of destination airport its longitude and latitude and regarding the destination airposts it is also added the State.","metadata":{}},{"cell_type":"code","source":"def preprocessX(X_df, airports_df, mean_dep, mean_dest,  mean_dealy_airline, mean_dealy_day):\n    def parseTime(x):\n        try:\n            a = str(x)\n            h = int(a[:2])\n            m = int(a[2:])\n            return h * 60 + m\n        except:\n            return np.NaN\n    def cast_float(x):\n        try: return float(x)\n        except: return np.NaN\n        \n        \n    X_df.SCHEDULED_DEPARTURE = X_df.SCHEDULED_DEPARTURE.apply(parseTime)\n    X_df.TAXI_OUT = X_df.TAXI_OUT.apply(cast_float)\n    \n\n    \n    X_df = pd.merge(X_df, airports_df.rename({'LATITUDE':'LATITUDE_ORIGIN', 'LONGITUDE':'LONGITUDE_ORIGIN', 'State':'State_ORIGIN'}, axis='columns', errors = 'raise'), how='left', left_on='ORIGIN_AIRPORT', right_on = 'IATA_CODE')\n    X_df = pd.merge(X_df, airports_df.rename({'LATITUDE':'LATITUDE_DESTINATION', 'LONGITUDE':'LONGITUDE_DESTINATION', 'State':'State_DESTINATION'}, axis='columns', errors = 'raise'), how='left', left_on='DESTINATION_AIRPORT', right_on = 'IATA_CODE')\n    X_df = X_df.drop(['IATA_CODE_x', 'IATA_CODE_y', 'NAME_x', 'NAME_y'], axis=1)\n    \n    \n    \n    X_df = pd.merge(X_df, mean_dep, how='left', on='ORIGIN_AIRPORT')\n    X_df = pd.merge(X_df, mean_dest, how='left', on='DESTINATION_AIRPORT')\n    X_df = pd.merge(X_df, mean_dealy_airline, how='left', on='AIRLINE')\n    X_df = pd.merge(X_df, mean_dealy_day, how='left', on='DAY_OF_WEEK')\n    X_df['SCHEDULED_DEPARTURE_SQ'] = X_df['SCHEDULED_DEPARTURE']**2\n    \n    numericalf = ['State_DESTINATION', 'SCHEDULED_TIME', 'DISTANCE', 'AIR_TIME','SCHEDULED_DEPARTURE', 'SCHEDULED_DEPARTURE_SQ','TAXI_OUT',\n                  'LATITUDE_ORIGIN', 'LONGITUDE_ORIGIN', 'LONGITUDE_DESTINATION', 'LATITUDE_DESTINATION', 'MEAN_DELAY_DESTINATION', \n                  'MEAN_DELAY_DEPARTURE', 'DEPARTURE_DELAY', 'MEAN_DELAY_DAY', 'MEAN_DELAY_AIRLINE' ]\n\n    categof = ['AIRLINE',  'MONTH', 'DAY', 'DAY_OF_WEEK']#'State_ORIGIN', 'State_DESTINATION',\n    \n    return X_df[numericalf+categof]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_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)\n# Load the test data\nX_test_df = pd.read_csv(\"/kaggle/input/eurecom-aml-2021-challenge-1/data/test_features.csv\", dtype=X_dtype)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We compute the outliers as the instances having an arrival delay greater than the mean plus three times the variance for each airline (havin as result 98% of the initial dataset)","metadata":{}},{"cell_type":"code","source":"df = pd.merge(X_train_df, y_train_df, on='ID')\n\ndef get_stats(group):\n    return {'min': group.min(), 'max': group.max(),\n            'count': group.count(), 'mean': group.mean(),\n           'var': group.std()}\n\nglobal_stats = df['ARRIVAL_DELAY'].groupby(df['AIRLINE']).apply(get_stats).unstack()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def filter_per_delay(row):\n    return abs(row['ARRIVAL_DELAY']) < (abs(global_stats.loc[row['AIRLINE']]['mean'])+3*global_stats.loc[row['AIRLINE']]['var'])\n\n_query = df[df.apply(filter_per_delay, axis=1)]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Then we add for each Destination Airport, Airline, Day of the Week the mean arival delay and mean departure delay for Origin Airport as additional features.","metadata":{}},{"cell_type":"code","source":"# merged = pd.merge(X_train_df, y_train_df, on=\"ID\")\nmean_dealy_dest = _query.groupby('DESTINATION_AIRPORT')['ARRIVAL_DELAY'].mean().reset_index(name='MEAN_DELAY_DESTINATION')\nmean_dealy_dep = _query.groupby('ORIGIN_AIRPORT')['DEPARTURE_DELAY'].mean().reset_index(name='MEAN_DELAY_DEPARTURE')\nmean_dealy_airline =  _query.groupby('AIRLINE')['ARRIVAL_DELAY'].mean().reset_index(name='MEAN_DELAY_AIRLINE')\nmean_dealy_day =  _query.groupby('DAY_OF_WEEK')['ARRIVAL_DELAY'].mean().reset_index(name='MEAN_DELAY_DAY')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_df = _query\ny_train_df = _query['ARRIVAL_DELAY']","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = preprocessX(X_train_df, airports, mean_dealy_dep,mean_dealy_dest, mean_dealy_airline, mean_dealy_day)\nX_test = preprocessX(X_test_df, airports, mean_dealy_dep, mean_dealy_dest,  mean_dealy_airline, mean_dealy_day)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We then filled the missing data with mean values and \"None\" for the States.","metadata":{}},{"cell_type":"code","source":"na_cols = ['LATITUDE_ORIGIN','LONGITUDE_ORIGIN','LONGITUDE_DESTINATION','LATITUDE_DESTINATION']\nfor col in na_cols:\n    val = X_train[col].mean()\n    X_train[col] = X_train[col].fillna(val)\n    X_test[col] = X_test[col].fillna(val)\nX_train['State_DESTINATION'] = X_train['State_DESTINATION'].fillna('None')\nX_test['State_DESTINATION'] = X_test['State_DESTINATION'].fillna('None')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Nan train: {X_train.isna().sum().sum()}\")\nprint(f\"Nan test: {X_test.isna().sum().sum()}\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Stats used for graphs","metadata":{}},{"cell_type":"code","source":"merged = pd.merge(X_train, y_train_df, left_index=True, right_index=True)\nres = merged.groupby('State_DESTINATION')['ARRIVAL_DELAY'].mean()\nglobal_mean = merged['ARRIVAL_DELAY'].mean()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Take the states of arrival for train and test","metadata":{}},{"cell_type":"code","source":"indices_per_dest_state = {}\nfor sigla in set(X_train['State_DESTINATION']):\n    indices_per_dest_state[sigla] = (X_train['State_DESTINATION'] == sigla)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"indices_per_dest_state_test = {}\nfor sigla in set(X_test['State_DESTINATION']):\n    indices_per_dest_state_test[sigla] = (X_test['State_DESTINATION'] == sigla)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"One Hot encode the airline","metadata":{}},{"cell_type":"code","source":"enc = OneHotEncoder(handle_unknown='ignore')\none_hot_features= ['AIRLINE']\nenc.fit(X_train[one_hot_features])\nX_train_one_hot = enc.transform(X_train[one_hot_features]).toarray()\nX_test_one_hot = enc.transform(X_test[one_hot_features]).toarray()\nX_train = X_train.drop(one_hot_features, axis=1)\nX_test = X_test.drop(one_hot_features, axis=1)\nX_train = X_train.drop(['State_DESTINATION'], axis=1)\nX_test = X_test.drop(['State_DESTINATION'], axis=1)\nX_train = np.hstack([X_train.values, X_train_one_hot])\nX_test = np.hstack([X_test.values, X_test_one_hot])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_All = X_train.copy()\ny_train_All =  y_train_df.copy()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_states = set(indices_per_dest_state.keys())\ntrest_states = set(indices_per_dest_state_test.keys())","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tqdm.notebook import tqdm","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### General Test","metadata":{}},{"cell_type":"code","source":"trian_scores_all = None\nX_train, X_val, y_train, y_val= train_test_split(X_train_All, y_train_All, random_state=1, test_size=0.2)\n# Standardize the features by removing the mean and scaling to unit variance\n# Similarly to the preivous step, the statistics used for standardization\n# should be computed across the training set only\nX_scaler = StandardScaler()\nX_scaler.fit(X_train)\n\nX_train = X_scaler.transform(X_train)\nX_val = X_scaler.transform(X_val)\n# We should also standardize the targets.\ny_scaler = StandardScaler()\ny_scaler.fit(y_train.values[:, np.newaxis])\n\n\ny_train = y_scaler.transform(y_train.values[:, np.newaxis])\ny_val =  y_scaler.transform(y_val.values[:, np.newaxis])\n\nbest_alpha = 0\nbest_score = 1000000000\nfor alpha in [0, 0.0001, 0.001, 0.01, 0.1]:\n    model = Ridge(alpha = alpha)\n    cv_results = cross_validate(model, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n    temp_score = np.mean(cv_results['test_score'])\n    if temp_score < best_score:\n        best_alpha = alpha\n        best_score = temp_score\n\nmodel = Ridge(alpha = best_alpha)\nmodel.fit(X_train, y_train)\n\n# results on validation set\nresult = model.predict(X_val)    \nresult_val = y_scaler.inverse_transform(result)\nscore = np.sqrt(mean_squared_error(y_scaler.inverse_transform(result_val),y_scaler.inverse_transform(y_val)))\nval_RMSE_all = score\nprint(f\"RMSE Result on valdiation set: {val_RMSE_all} [alpha = {best_alpha}]\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Train an whole dataset with best param to submit \nX_train = X_train_All.copy()\nX_submit = X_test.copy()\ny_train = y_train_All.copy()\n\nX_scaler = StandardScaler()\nX_scaler.fit(X_train)\n\nX_train = X_scaler.transform(X_train)\nX_submit = X_scaler.transform(X_submit)\n# We should also standardize the targets.\ny_scaler = StandardScaler()\ny_scaler.fit(y_train.values[:, np.newaxis])\ny_train = y_scaler.transform(y_train.values[:, np.newaxis])\n\nmodel = Ridge(alpha = best_alpha)\nmodel.fit(X_train, y_train)\n\n\nresult_train = model.predict(X_train)\nscore = np.sqrt(mean_squared_error(y_scaler.inverse_transform(result_train),y_scaler.inverse_transform( y_train)))\ntrian_scores_all = score\nprint(f\"Train Score {trian_scores_all} [alpha: {best_alpha}]\")\nprediction_y = y_scaler.inverse_transform(model.predict(X_submit))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame(data={'ID': X_test_df.ID.values,\n                                   'ARRIVAL_DELAY': prediction_y.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(f\"/kaggle/working/submission_general_alpha_.csv\", index=False)\n# Check the submission file\n! head -5 \"/kaggle/working/submission_general_alpha_.csv\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Run CV for each state","metadata":{}},{"cell_type":"code","source":"different_val_scores = {}\n\nfor k in tqdm(indices_per_dest_state.keys()):\n    X_state = X_train_All[indices_per_dest_state[k]]\n    y_state = y_train_All.values[:,np.newaxis][indices_per_dest_state[k]]\n    X_train, X_val, y_train, y_val = train_test_split(X_state, y_state, random_state=42, test_size=0.2)\n   \n    # Standardize the features by removing the mean and scaling to unit variance\n    # Similarly to the preivous step, the statistics used for standardization\n    # should be computed across the training set only\n    X_scaler = StandardScaler()\n    X_scaler.fit(X_train)\n\n    X_train = X_scaler.transform(X_train)\n    X_val = X_scaler.transform(X_val)\n    # We should also standardize the targets.\n    y_scaler = StandardScaler()\n    y_scaler.fit(y_train)\n\n    y_train = y_scaler.transform(y_train)\n    y_val = y_scaler.transform(y_val)\n    best_alpha = 0\n    best_score = 1000000000\n    for alpha in [0, 0.0001, 0.001, 0.01, 0.1]:\n        model = Ridge(alpha = alpha)\n        cv_results = cross_validate(model, X_train, y_train, cv=5, scoring='neg_mean_squared_error')\n        temp_score = np.mean(cv_results['test_score'])\n        if temp_score < best_score:\n            best_alpha = alpha\n            best_score = temp_score\n\n    model = Ridge(alpha = best_alpha)\n    model.fit(X_train, y_train)\n\n    result_val  = model.predict(X_val)\n    score_val = np.sqrt(mean_squared_error(y_scaler.inverse_transform(result_val),y_scaler.inverse_transform( y_val)))\n    different_val_scores[k] = (best_alpha, score_val, len(result_val))\nval_score_weighted = [v[1] * v[2] for v in different_val_scores.values()]\ntotal_flights = np.sum([v[2] for v in different_val_scores.values()])\nvalidation_weithed_score = np.sum(val_score_weighted)/total_flights\nprint(f\"Weighted average Validation Score {validation_weithed_score}\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Retrain Models with best params to submit ","metadata":{}},{"cell_type":"code","source":"trian_scores = {}\nprediction_y = np.zeros((X_test.shape[0], 1))\ndifferent_train_scores = {}\nfor k, v in tqdm(different_val_scores.items()):\n    best_alpha = v[0]\n    X_train, y_train  = X_train_All[indices_per_dest_state[k]], y_train_All.values[:,np.newaxis][indices_per_dest_state[k]]\n    X_submit = X_test[indices_per_dest_state_test[k]].copy()\n    \n    X_scaler = StandardScaler()\n    X_scaler.fit(X_train)\n\n    X_train = X_scaler.transform(X_train)\n    X_submit = X_scaler.transform(X_submit)\n    \n    # We should also standardize the targets.\n    y_scaler = StandardScaler()\n    y_scaler.fit(y_train)\n\n    y_train = y_scaler.transform(y_train)\n    \n    \n    model = Ridge(alpha = best_alpha)\n    model.fit(X_train, y_train)\n    \n    result_train = model.predict(X_train)\n    score = np.sqrt(mean_squared_error(y_scaler.inverse_transform(result_train),y_scaler.inverse_transform(y_train)))\n    trian_scores[k] = (score, len(X_train))\n    prediction_y[indices_per_dest_state_test[k]] = y_scaler.inverse_transform(model.predict(X_submit))\n\ntrain_score_weighted = [v[0] * v[1] for v in trian_scores.values()]\ntotal_flights = np.sum([v[1] for v in trian_scores.values()])\ntrain_score_weighted = np.sum(train_score_weighted)/total_flights\nprint(f\"Weighted average Train Score {train_score_weighted}\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission_df = pd.DataFrame(data={'ID': X_test_df.ID.values,\n                                   'ARRIVAL_DELAY': prediction_y.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)\n# Check the submission file\n! head -5 \"/kaggle/working/submission.csv\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Preprocess to plot","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.style.use('ggplot')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.arange(len(trian_scores))\n\ntrainRMSE_per_state = [trian_scores[state][0] for state in train_states]\ntrainRMSE = np.ones(len(trian_scores)) * trian_scores_all\navg_trainRMSE_per_state = np.ones(len(trian_scores)) * train_score_weighted\n\nvalRMSE_per_state = [different_val_scores[state][1] for state in train_states]\nvalRMSE = np.ones(len(different_val_scores)) * val_RMSE_all\navg_valRMSE_per_state = np.ones(len(different_val_scores)) * validation_weithed_score\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_alpha = [v[0] for v in  different_val_scores.values()]\nkeys = [0, 0.0001, 0.001, 0.01, 0.1]\nalphas_dict = {k:0 for k in keys}\nfor a in all_alpha:\n    alphas_dict[a] += 1","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Alphas","metadata":{}},{"cell_type":"code","source":"na = len(alphas_dict)\nka = [k for k in alphas_dict.keys()]\nvk = [alphas_dict[k] for k in ka]\nfiugre = plt.figure(figsize=(7,3))\nplt.bar(np.arange(na), vk, label=\"# States with Alpha\")\nplt.legend()\nplt.title(\"Alpha\")\n_ = plt.xticks( np.arange(na), ka,  rotation='0')\nplt.xlabel(\"Value of Alpha\")\nplt.ylabel(\"Number of States\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Validation Scores","metadata":{}},{"cell_type":"code","source":"fiugre = plt.figure(figsize=(25,10))\nplt.bar(x, valRMSE_per_state, label=\"Validation RMSE per State\")\n# plt.plot(x, valRMSE, label=\"Validation RMSE General\", color='blue')\nplt.plot(x, avg_valRMSE_per_state, label=\"Validation RMSE per State Weighted AVG\", color='green')\nplt.legend()\nplt.title(\"Validation Scores\")\n_ = plt.xticks( x, train_states,  rotation='-90')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train Scores","metadata":{}},{"cell_type":"code","source":"fiugre = plt.figure(figsize=(25,10))\nplt.bar(x, trainRMSE_per_state, label=\"Train RMSE per State\")\nplt.plot(x, trainRMSE, label=\"Train RMSE General\", color='blue')\nplt.plot(x, avg_trainRMSE_per_state, label=\"Train RMSE per State Weighted AVG\", color='green')\nplt.legend()\nplt.title(\"Train Scores\")\n_ = plt.xticks( x, train_states,  rotation='-90')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fiugre = plt.figure(figsize=(25,10))\nmm = np.ones(len(res.index)) * global_mean\nplt.bar(np.arange(len(res.index)), res.values, label=\"Average delay per State\")\nplt.plot(np.arange(len(res.index)), mm, label=\"Global Average dealy\", color='blue')\n\nplt.legend()\nplt.title(\"Average delay\")\n_ = plt.xticks(np.arange(len(res.index)), res.index,  rotation='-90')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Sound to notice the completation of the notebook execution","metadata":{}},{"cell_type":"code","source":"import IPython.display as ipd\nbeep = np.sin(2*np.pi*400*np.arange(10000*2)/10000)\nipd.Audio(beep, rate=10000, autoplay=True)","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}