You are on page 1of 5

“CSE18R212-Machine Learning”

LAB:-2
Name:M.Chethan kumar
Reg.no:9920004660
Section:N
Aim:-
Find the parameters of the Simple Linear Regression
using the given data.

code and Output:

import pandas as pd
import numpy as np

df=pd.read_csv("HtWt.csv",encoding='windows-
1252') df.head()
len(df["Height"])

np.arange(1,50)

a=np.arange(1,51) df.set_index(a)

#visualization
from matplotlib import pyplot as plt

x=df['Height'].values.reshap
e((-1,1)) y=df['Weight']
x.ndim

plt.scatter(x,y)
plt.title("height and weight
index") plt.xlabel("Height")
plt.ylabel("Weight")
from sklearn.linear_model import LinearRegression

linmodel=LinearRegression()
linmodel.fit(x,y)

#fetching intercept(b0)
print('intercept(b0):',linmodel.intercept_)

#fetching slope(b1)
print("slope(b1):",linmodel.c
oef_)

Result:-
Found parameters of simple linear regression using
given data and visualised the data.

*****The End*****

You might also like