Skip to content Skip to sidebar Skip to footer

Polynomial Regression With Scikit Learn Vs Np.polyfit

I am quite surprised that nobody talks about this: the difference of polynomial regression done with scikit learn vs polyfit from numpy. First, the data: xdic={'X': {11: 300, 12: 1

Solution 1:

I used both of them, and got the same R2 score and the same curve

regr = LinearRegression()
cubic = PolynomialFeatures(degree=3)
X_cubic = cubic.fit_transform(dfa3.home_realshow_cnt.values.reshape(-1, 1))
regr = regr.fit(X_cubic,dfa3.prop)

sklearn_r2=r2_score(dfa3.prop,regr.predict(X_cubic))
fit_r2=r2_score(dfa3.prop,yvalsa)
print("sklearn_r2: ",sklearn_r2,'; fit_r2: ',fit_r2)
def fit(x,y,n):
    z1 = np.polyfit(x,y, n)
    p1 = np.poly1d(z1)
    return p1(x)

Post a Comment for "Polynomial Regression With Scikit Learn Vs Np.polyfit"