python - Which is the simplest way to make a polynomial regression with sklearn? -


i have data doesn't fit linear regression,

enter image description here

in fact should fit 'exactly' quadratic function:

p = r*i**2  

i'm miking this:

model = sklearn.linear_model.linearregression()

x = alambres[alambre]['mediciones'][x].reshape(-1, 1) y = alambres[alambre]['mediciones'][y].reshape(-1, 1) model.fit(x,y) 

is there chance solve doing like:

model.fit([x,x**2],y) ?

you can use numpy's polyfit.

import numpy np matplotlib import pyplot plt x = np.linspace(0, 100, 50) y = 23.24 + 2.2*x + 0.24*(x**2) + 10*np.random.randn(50) #added noise coefs = np.polyfit(x, y, 2) print(coefs) p = np.poly1d(coefs) plt.plot(x, y, "bo", markersize= 2) plt.plot(x, p(x), "r-") #p(x) evaluates polynomial @ x plt.show() 

out:

[  0.24052058   2.1426103   25.59437789] 

enter image description here


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -