Skip to content

Instantly share code, notes, and snippets.

@7tg
Created August 28, 2018 13:50
Show Gist options
  • Save 7tg/32cc3b4927734e3f1809b5da0fb9da6d to your computer and use it in GitHub Desktop.
Save 7tg/32cc3b4927734e3f1809b5da0fb9da6d to your computer and use it in GitHub Desktop.
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