image_output_1.png
from sklearn.linear_model import LinearRegression

from sklearn.metrics import mean_squared_error

from sklearn.metrics import mean_squared_error, r2_score, make_scorer

from sklearn.preprocessing import RobustScaler

rs = RobustScaler()
X_train_rs = rs.fit_transform(X_train)
X_test_rs = rs.transform(X_test)

from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error
lg = LinearRegression()
lg.fit(X_train, y_train)
lg_rs = LinearRegression()
lg_rs.fit(X_train_rs, y_train)
y_est = lg.predict(X_test)
y_est_rs = lg_rs.predict(X_test_rs)
MSE_tst = mean_squared_error(y_test, y_est)
R2_coeff = lg.score(X_test, y_test)
MSE_tst_rs = mean_squared_error(y_test, y_est_rs)
R2_coeff_rs = lg_rs.score(X_test_rs, y_test)
MSE_train = mean_squared_error(y_train, lg.predict(X_train))
R2_train_coeff = lg.score(X_train, y_train)
print('TESTING METRICS')
print('Metrics without scaling:')
print('MSE : ' + str(MSE_tst))
print('R2 score: ' + str(R2_coeff))
print('\nMetrics with RobustScaler:')
print('MSE : ' + str(MSE_tst_rs))
print('R2 score: ' + str(R2_coeff_rs))
print('\nTRAINING METRICS')
print('Metrics without scaling:')
print('MSE : ' + str(MSE_train))
print('R2 score: ' + str(R2_train_coeff))