Created
April 9, 2024 10:35
-
-
Save makwanadeepam/6443464ec2fffef828479c8a486cae0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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