How to implement a linear regression algorithm in python?

1

I'm running a job in college and would like to implement a function that calculates a regressão linear . Given the points and the number of desired exponents, I want as a return the coefficients of the equation. For example, given the points below, and stating that I want only one exponent, I would like me to return the coefficients a and b of the 1st degree equation.

>>> x = [0.4, 0.6, 0.8, 1.4]
>>> y = [1.4, 2.1, 3.5, 6.7]

Any ideas?

    
asked by anonymous 05.11.2015 / 23:35

1 answer

1

You can use the linregress by Lib Scipy.

from scipy import stats
slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)#método de regressão
print slope
print intercept
print r_value
print p_value
print std_err
    
12.11.2015 / 17:00