You are on page 1of 4

DEEP LEARNING

Puran Kumar
Student Name: Peacon Pramanik UID:19BCS2056
19BCS2059

Branch: CSE Section/Group CSE-19


Semester: 7th Date of Performance:18-08-2022
Subject Name: DEEP LEARNING

1. Aim/Overview of the practical: Linear Regression With Python Implementation

2. Objective : To find a relationship between one or more features(independent variables) and


a continuous target variable(dependent variable).

3. Apparatus used: Datasets

4. Algorithm/Flowchart: Steps for the algorithm:

a) Import the packages and classes that you need.


b) Provide data to work with, and eventually do appropriate transformations.
c) Create a regression model and fit it with existing data.
d) Check the results of model fitting to know whether the model is satisfactory.
e) Apply the model for predictions.
CODE:-

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# creating a dummy dataset


np.random.seed(10)
x = np.random.rand(50, 1)
y = 3 + 3 * x + np.random.rand(50, 1)

#scatterplot

plt.scatter(x,y,s=10)
plt.xlabel('x_dummy')
plt.ylabel('y_dummy')
plt.show()

#creating a model
from sklearn.linear_model import LinearRegression

# creating a object
regressor = LinearRegression()

#training the model


regressor.fit(x, y)

#using the training dataset for the prediction


pred = regressor.predict(x)

#model performance
from sklearn.metrics import r2_score, mean_squared_error
mse = mean_squared_error(y, pred)
r2 = r2_score(y, pred)#Best fit lineplt.scatter(x, y)
plt.plot(x, pred, color = 'Black', marker = 'o')
#Results
print("Mean Squared Error : ", mse)
print("R-Squared :" , r2)

print("Y-intercept :" , regressor.intercept_)


print("Slope :" , regressor.coef_)

import statsmodels.api as sm

#adding a constant
X = sm.add_constant(x)

#performing the regression


result = sm.OLS(y, x).fit()

# Result of statsmodels
print(result.summary())

5. OUTPUT:-

You might also like