Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
linear regression algo
  • Loading branch information
slashharsh committed Oct 31, 2019
commit d8c472989a33a9325eacc007ed66bf964d2c5cab
36 changes: 36 additions & 0 deletions machine-learning-algo/linear-regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
from sklearn.linear_model import LinearRegression
x = np.array([5, 15, 25, 35, 45, 55]).reshape((-1, 1))
y = np.array([5, 20, 14, 32, 22, 38])
print(x)

print(y)

model = LinearRegression()

model.fit(x, y)
model = LinearRegression().fit(x, y)
r_sq = model.score(x, y)
print('coefficient of determination:', r_sq)
print('intercept:', model.intercept_)

print('slope:', model.coef_)
new_model = LinearRegression().fit(x, y.reshape((-1, 1)))

print('intercept:', new_model.intercept_)

print('slope:', new_model.coef_)
y_pred = model.predict(x)

print('predicted response:', y_pred, sep='\n')
y_pred = model.intercept_ + model.coef_ * x

print('predicted response:', y_pred, sep='\n')

x_new = np.arange(5).reshape((-1, 1))

print(x_new)

y_new = model.predict(x_new)

print(y_new)