Created
August 28, 2018 13:50
-
-
Save 7tg/32cc3b4927734e3f1809b5da0fb9da6d 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
from statistics import mean | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import style | |
style.use('fivethirtyeight') | |
xs = np.array([1, 2, 3, 4, 5, 6], dtype=np.float64) | |
ys = np.array([5, 4, 6, 5, 6, 7], dtype=np.float64) | |
def regresyon(xs, ys): | |
m = ((mean(xs) * mean(ys)) - mean((xs * ys))) / (mean(xs)**2 - mean(xs**2)) | |
b = mean(ys) - (m * mean(xs)) | |
return m, b | |
m, b = regresyon(xs, ys) | |
line = [(m * x) + b for x in range(0, 8)] | |
plt.scatter(xs, ys) | |
plt.plot(line, color='r') | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment