Search code examples
pythonnumpylinear-regression

what does deg do in np.polyfit numpy


x = np.array([1, 3, 5, 7, 9])

y = np.array([ 6, 3, 9, 5 , 4])

m , b = np.polyfit(x, y, 1)

how does the 1(deg) work in this linear regression? I do know it represents the degree of fitting the polynomial but how does it actually work.


Solution

  • The degree-parameter n determines the polynimial equation used for fitting. The coefficients p in this formula are in descending powers, and the length of p is n+1

    enter image description here

    This formula is then fitted (in a least-squares sense) to the data.