Implementing Linear Regression
Learn how to implement linear regression using Python’s math library.
- Calculate mean:
def mean(values):
return sum(values) / float(len(values))
- Calculate variance:
def variance(values, mean):
return sum((x-mean)**2 for x in values)
- Calculate covariance:
def covariance(x, mean_x, y, mean_y):
return sum((x[i]-mean_x)*(y[i]-mean_y) for i in range(len(x)))
Read more: Linear Regression