Skip to content

Instantly share code, notes, and snippets.

@makwanadeepam
Created April 9, 2024 10:35
Show Gist options
  • Save makwanadeepam/6443464ec2fffef828479c8a486cae0a to your computer and use it in GitHub Desktop.
Save makwanadeepam/6443464ec2fffef828479c8a486cae0a to your computer and use it in GitHub Desktop.
# Linear Regression
# Model
from sklearn.linear_model import LinearRegression
reg=LinearRegression()
# Data
X=[[1], [2], [3], [4], [5], [6]]
Y=[2+1,4+1,6+1,8+1,10+1,12+1]
# Fitting
reg.fit(X,Y)
# Predict
print(reg.predict([[8]]))
# Coefficients
m,c=reg.coef_, reg.intercept_
print(f"m={m}, c={c}")
# Plotting
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 100)
plt.plot(x, m*x+c)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment