Professional Documents
Culture Documents
November 4, 2018
X = bos.drop('PRICE', axis = 1)
Y = bos['PRICE']
sgd = SGDRegressor(max_iter=1000,eta0=0.000001)
sgd.fit(X_train, Y_train)
pred_sgd=sgd.predict(X_test)
1
from sklearn.metrics import median_absolute_error,r2_score
In [44]: # http://zetcode.com/python/prettytable/
from prettytable import PrettyTable
x = PrettyTable()
x.field_names = ["Model","Explained variance score", "Mean absolute error", "Median Ab.
x.add_row(["Linear Regression",lm_evs,lm_mae,lm_med,lm_r2])
x.add_row(["Sgd",sgd_evs,sgd_mae,sgd_med,sgd_r2])
print('\tTable 2 - Comparing Value of alpha, Train error and test error')
print('\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
print(x)
In [41]: #https://pythonspot.com/matplotlib-bar-chart/
import numpy as np
import matplotlib.pyplot as plt
# data to plot
n_groups = 4
lm = (lm_evs,lm_mae,lm_med,lm_r2)
sgd = (sgd_evs,sgd_mae,sgd_med,sgd_r2)
# create plot
fig, ax = plt.subplots()
index = np.arange(n_groups)
bar_width = 0.35
2
opacity = 0.8
plt.xlabel('Error matrices')
plt.ylabel('error')
plt.title('Comparision b/w LR and SGD')
plt.xticks(index + bar_width, ('ExVarScore', 'MeanAbEr', 'MedAbEr', 'R2Sc'))
plt.legend()
# plt.tight_layout()
plt.show()
3
1.3.1 Conclusion
1.3.2 __ Linear Regression is better than SGD regression __