Experiment Number: 3: Aim:-Study of The Linear Regression in The Machine Learning Using The Boston Housing Dataset. 1)
Experiment Number: 3: Aim:-Study of The Linear Regression in The Machine Learning Using The Boston Housing Dataset. 1)
Experiment Number: 3: Aim:-Study of The Linear Regression in The Machine Learning Using The Boston Housing Dataset. 1)
Aim:- Study of the Linear Regression in the Machine Learning using the
Boston Housing Dataset.
1) MACHINE LEARNING: - Machine Learning is the field of study that gives
computers the capability to learn without being explicitly programmed.
ML is one of the most exciting technologies that one would have ever come
across. As it is evident from the name, it gives the computer that makes it more
similar to humans: The ability to learn.
Machine learning is actively being used today, perhaps in many more places
than one would expect.
CODE:-
target_feature = 'MEDV'
y = df[target_feature]
x = df.drop(target_feature, axis=1)
x.head()
y.head()
OUTPUT:-
regression.fit(x_train,y_train)
# train score
train_score= round(regression.score(x_train, y_train)*100,2)
print("train score of Linear Regression: ",train_score)
OUTPUT:-
ix. Printing the shape and size and datatypes of the testing set:-
CODE:-
y_pred = regression.predict(x_train)
print(y_pred.shape)
print(y_test.shape)
print(f"y_pred size: {y_pred.size}")
print(f"y_test size: {y_test.size}")
print(f"y_pred data type: {type(y_pred)}")
print(f"y_test data type: {type(y_test)}")
OUTPUT:-
OUTPUT:-
xiii. Creating a new Dataframe and get the linear coefficient :-
CODE:-
lr_coefficient = pd.DataFrame()
lr_coefficient["columns"]= x_train.columns
lr_coefficient["coefficient Estimate"]=pd.Series(regression.coef_)
print(lr_coefficient)
OUTPUT:-
xiv. Ploting the bar chart of coefficient using the matplotplotting library:-
CODE:-
fig, ax = plt.subplots(figsize = (20,10))
ax.bar(lr_coefficient["columns"],lr_coefficient["coefficient Estimate"])
ax.spines["bottom"].set_position("zero")
plt.style.use("ggplot")
plt.grid()
plt.show()
fig, ax = plt.subplots(figsize =(20,10))
x_ax = range(len(x_test))
plt.scatter(x_ax, y_test, s=30, color='green', label='original')
plt.scatter(x_ax, y_pred, s=30,color='red',label='predicated')
plt.legend()
#plt.grid()
plt.show()
OUTPUT:-
xv. Ploting the original and predicated value using the scatter and the
plot:-
CODE:-
fig, ax = plt.subplots(figsize =(20,10))
x_ax = range(len(x_test))
plt.scatter(x_ax, y_test, s=30, color='green', label='original')
plt.plot(x_ax, y_pred, lw=0.8,color='red',label='predicated')
plt.legend()
#plt.grid()
plt.show()
OUTPUT:-
xvi. Using scatter plot ,how the features are vary with the MEDV:-
CODE:-
plt.feature(figsize(20,5))
features = [‘LSTAT,’RM’]
target = df[‘MEDV’]
for i,col in enumerate(features):
plt.subplot(1, len(features), i+1)
x=df[col]
y=target
plt.scatter9x,y,marker=’0’)
plt.title(col)
plt.xlabel(col)
plt.ylabel(‘MEDV’)
output:-