Professional Documents
Culture Documents
Experiment No. 2
STEPS:
Let’s try to implement the linear regression in both scikit-learn and statsmodel.
Scikit-learn Statsmodels
Intercept Includes intercept by default. We need to add the intercept.
Model The score method in scikit-learn gives It shows many statistical results like
Evaluation us the accuracy of the model p-value, F-test, Confidential Interval
Regularization It uses “L2” by default; We can also set It does not use any regularization
the parameter to “None” if we want. parameter.
Advantage It has a lot of parameters and is easy to It has a lot of parameters and is easy to
use. use.
DATASET: x = np.random.rand(50,1)
y = 3+3 * x + np.random.rand(50,1)
IMPLEMENTATION:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(10)
x = np.random.rand(50, 1)
y = 3 + 3 * x + np.random.rand(50, 1)
Name:TANISHQ UID:19BCS2158
Course Name: Deep Learning Lab Course Code: CSA-412
plt.scatter(x,y,s=10)
plt.xlabel('x_dummy')
plt.ylabel('y_dummy')
plt.show()
regressor = LinearRegression()
regressor.fit(x, y)
pred = regressor.predict(x)
R-Squared : 0.9068822972556425
Y-intercept : [3.41354381]
Slope : [[3.11024701]]
Implementation of Linear Regression using Statsmodel,
import statsmodels.api as sm
X = sm.add_constant(x)
print(result.summary())
Name:TANISHQ UID:19BCS2158
Course Name: Deep Learning Lab Course Code: CSA-412
OUTPUT:
Name:TANISHQ UID:19BCS2158