text_plain_output_1.png
from sklearn.metrics import mean_squared_error,mean_absolute_error

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

def Model_Comparision_Train_Test(AllModels, x_train, y_train, x_test, y_test):
    return_df = pd.DataFrame(columns=['Model', 'MSE', 'RMSE', 'MAE'])
    for myModel in AllModels:
        myModel.fit(x_train, y_train)
        y_pred_train = myModel.predict(x_train)
        mse_train, rmse_train, mae_train = extract_metrics_from_predicted(y_train, y_pred_train)
        y_pred_test = myModel.predict(x_test)
        mse_test, rmse_test, mae_test = extract_metrics_from_predicted(y_test, y_pred_test)
        summary = pd.DataFrame([[type(myModel).__name__, ''.join([str(round(mse_test, 3)), '(', str(round(mse_train, 3)), ')']), ''.join([str(round(rmse_test, 3)), '(', str(round(rmse_train, 3)), ')']), ''.join([str(round(mae_test, 3)), '(', str(round(mae_test, 3)), ')'])]], columns=['Model', 'MSE', 'RMSE', 'MAE'])
        return_df = pd.concat([return_df, summary], axis=0)
    return_df.set_index('Model', inplace=True)
    return return_df
def extract_metrics_from_predicted(y_true, y_pred):
    from sklearn.metrics import mean_squared_error, mean_absolute_error
    mse = mean_squared_error(y_true, y_pred)
    rmse = np.sqrt(mse)
    mae = mean_absolute_error(y_true, y_pred)
    return (mse, rmse, mae)

train_data = pd.read_csv('../input/Train-1555063579947.csv')
test_data = pd.read_csv('../input/Test-1555063594850.csv')

train_data.dtypes

test_data.dtypes

train_data = train_data.drop(['HadGrievance', 'Promoted_InLast3Yrs', 'EmployeeID'], axis=1)

train_data.head()