【发布时间】:2020-03-14 14:57:33
【问题描述】:
from sklearn.preprocessing import PolynomialFeatures
train_x_p = np.asanyarray(train[['FUELCONSUMPTION_COMB_MPG']])
poly = PolynomialFeatures(degree = 3)
train_x_poly = poly.fit_transform(train_x_p)
regr.fit(train_x_poly, train_y)
print('Coefficients: ', regr.coef_)
print('Intercept', regr.intercept_)
test_x_poly = poly.fit_transform(test_x)
test_y_poly1 = np.asanyarray(test[['CO2EMISSIONS']]) #im not sure especially about this line
test_y_hat_poly1 = regr.predict(test_x_poly)
mse = metrics.mean_squared_error(test_y_poly1, test_y_hat_poly1)
r2 = (r2_score(test_y_poly1,test_y_hat_poly1))
print('MSE&R2SQUARE polynomial linear regression (FUELCONSUMPTION_COMB_MPG): ')
print('MSE: ',mse)
print('r2-sq: ',r2)
还有什么让我觉得 mse 的结果不正确 我应该将测试 y 转换为 poly,如果应该怎么做?
【问题讨论】:
-
SO 不适合这类问题。请阅读How do I ask a good question?
标签: python machine-learning linear-regression polynomial-math