Calcula la regresion lineal para un conjunto de 60 datos
import numpy as np import pandas as pd import matplotlib.pyplot as plt def regre(x,y): x = np.array(x) y = np.array(y) def m_b(x, y): m = (((np.mean(x) * np.mean(y)) - np.mean(x * y)) / ((np.mean(x)**2) - np.mean(x**2))) b = np.mean(y) - np.mean(m * x) return m, b m, b = m_b(x, y) #print("m={}".format(round(m,2))) #print("b={}".format(round(b,2))) regression_line = [(m*x)+b for x in x] plt.scatter(x,y) plt.plot(x, regression_line) plt.show()