Ridge Regression

CODE:


import pandas as pd 
from sklearn import datasets
from sklearn.model_selection import train_test_split 
from sklearn.linear_model import LinearRegression  
import numpy as np  
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.linear_model import Ridge

dataset = pd.read_csv('Total.csv',names = ['alpha','PIR', 'ptt', 'bpmax' ,'bpmin', 'hrfinal', 'ih', 'il', 'meu'])

X = dataset[['alpha','PIR', 'ptt']]

y = dataset[['bpmin']]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0) 

from sklearn.preprocessing import StandardScaler
sc_X=StandardScaler()
x_train=sc_X.fit_transform(X_train)
x_test=sc_X.transform(X_test)


regressor = Ridge(normalize=True)
#regressor = LinearRegression() 
#print dataset.isnull().any()
regressor.fit(X_train, y_train)
y_pred = regressor.predict(X_test)


#print('Coefficients: \n', regressor.coef_)
# The mean squared error
from sklearn import metrics  

print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))  
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))  
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))



# # Explained variance score: 1 is perfect prediction
print('Variance score: %.2f' % r2_score(y_test, y_pred))


3 features:

  • bpmin:
  • ('Mean Absolute Error:', 21.912456888770073)
  • ('Mean Squared Error:', 731.42864008317667)
  • ('Root Mean Squared Error:', 27.044937420581633)
  • Variance score: 0.01


bpmax:

  • ('Mean Absolute Error:', 23.028892166575584)
  • ('Mean Squared Error:', 791.02754353976911)
  • ('Root Mean Squared Error:', 28.12521188435332)
  • Variance score: 0.16


avg:

  • ('Mean Absolute Error:', 22.470674527672831)
  • ('Mean Squared Error:', 761.22809181147397)
  • ('Root Mean Squared Error:', 27.590362299387696)
  • Variance score: 0.08

7 features:

avg:

  • ('Mean Absolute Error:', 15.691699869468799)
  • ('Mean Squared Error:', 476.19053440909857)
  • ('Root Mean Squared Error:', 21.821790357555418)
  • Variance score: 0.47


bpmax:

  • ('Mean Absolute Error:', 23.012045249153179)
  • ('Mean Squared Error:', 790.56758619399386)
  • ('Root Mean Squared Error:', 28.117033737469423)
  • Variance score: 0.16


bpmin:

  • ('Mean Absolute Error:', 8.3713544897843963)
  • ('Mean Squared Error:', 161.81348262420218)
  • ('Root Mean Squared Error:', 12.720592856632202)
  • Variance score: 0.78