Skip to content

Instantly share code, notes, and snippets.

@vvksh
Created August 4, 2020 15:50
Show Gist options
  • Save vvksh/d9dfbd05690f1f8dfb955b11fe21f0ce to your computer and use it in GitHub Desktop.
Save vvksh/d9dfbd05690f1f8dfb955b11fe21f0ce to your computer and use it in GitHub Desktop.
Simple linear regression
# 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