Created
August 4, 2020 15:50
-
-
Save vvksh/d9dfbd05690f1f8dfb955b11fe21f0ce to your computer and use it in GitHub Desktop.
Simple linear regression
This file contains hidden or 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
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html | |
import numpy as np | |
from scipy import stats | |
import matplotlib.pyplot as plt | |
x = np.array([1,2,3]) | |
linregress(np.arange(len(x)), x) | |
slope, intercept, r_value, p_value, std_err = stats.linregress(np.arange(len(x)), x) | |
#plot | |
plt.plot(x, y, 'o', label='original data') | |
plt.plot(x, intercept + slope*x, 'r', label='fitted line') | |
plt.legend() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment