Sklearn Linear Regression Tutorial with Boston House Dataset

importing dataset from sklearn
Description of the dataset
Top 5 rows of the dataset
bos.isnull().sum()
No null values in the dataset
print(bos.describe())
All the variables are Numerical including the target
sns.set(rc={'figure.figsize':(11.7,8.27)})
plt.hist(bos['PRICE'], bins=30)
plt.xlabel("House prices in $1000")
plt.show()
Correlation matrix of the variables
Distribution of housing prices w.r.t. ‘LTSTAT’ and ‘RM’
X_rooms = bos.RM
y_price = bos.PRICE


X_rooms = np.array(X_rooms).reshape(-1,1)
y_price = np.array(y_price).reshape(-1,1)

print(X_rooms.shape)
print(y_price.shape)
model performance on train data for 1 variable
model performance on test data for 1 variable
prediction_space = np.linspace(min(X_rooms), max(X_rooms)).reshape(-1,1) 
plt.scatter(X_rooms,y_price)
plt.plot(prediction_space, reg_1.predict(prediction_space), color = 'black', linewidth = 3)
plt.ylabel('value of house/1000($)')
plt.xlabel('number of rooms')
plt.show()
Fitted line on the output variable
model performance on train data for all variables
model performance on test data for all variables

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store