Skip to content

Commit

Permalink
Add Linear Regression
Browse files Browse the repository at this point in the history
  • Loading branch information
avs8687 committed Jan 15, 2019
1 parent 2f1c5ed commit 8a73b8f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Binary file added Data Analytics/Linear Regression/Ass1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions Data Analytics/Linear Regression/LR.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pandas as pd
from matplotlib import pyplot as plt

def train(X,y):
mean_X = X.mean()
mean_y = y.mean()

numerator = 0
denominator = 0

for i in range(0,len(X)):
numerator += (X[i] - mean_X)*(y[i] - mean_y)
denominator += (X[i] - mean_X)**2

m = numerator/denominator
b = mean_y - (m*mean_X)

return m,b

def plot(X,y,predicted):
plt.xlabel("Number of hours spent driving")
plt.ylabel("Risk Score")
plt.scatter(X,y)
plt.plot(X,predicted,color="green")
plt.savefig("Ass1.jpg")
plt.show()


data = pd.read_csv("data.csv")
X = data.iloc[:,0]
y = data.iloc[:,1]

m,b = train(X,y)
predicted = []

for i in range(0,len(X)):
temp = (m*X[i])+b
predicted.append(temp)
print(temp,y[i])

11 changes: 11 additions & 0 deletions Data Analytics/Linear Regression/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
X,Y
8,3
2,10
11,3
6,6
5,8
4,12
12,1
9,4
6,9
1,14

0 comments on commit 8a73b8f

Please sign in to comment.