How to implement a linear regression algorithm in python?

Asked

Viewed 906 times

1

I am 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 exponents desired, I want to return the coefficients of the equation. For example, given the points below, and stating that I want only one exponent, I would like you to return the coefficients a and b of the first degree equation.

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

Any idea?

1 answer

1

You can use the method linregress 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
  • 1

    Lucas, I would like to implement a method and not use a ready one. I already knew this method mentioned, but I would like to implement some linear regression algorithm.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.