多项式特征拟合变换给出了数值

2024-05-06 06:38:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试运行多项式回归示例时遇到值错误:

from sklearn.preprocessing import PolynomialFeatures
import numpy as np

poly = PolynomialFeatures(degree=2)
poly.fit_transform(X)   ==> ERROR

错误是:

^{pr2}$

我的scikit学习版本是0.15.2

这个例子取自:http://scikit-learn.org/stable/modules/linear_model.html#polynomial-regression-extending-linear-models-with-basis-functions


Tags: fromimportnumpy示例as错误npsklearn
1条回答
网友
1楼 · 发布于 2024-05-06 06:38:00

在创建像这样的多项式特征类的对象时,您应该尝试将include\u bias设置为False

poly = PolynomialFeatures(degree=2, include_bias=False)

请注意,示例中的最终矩阵现在没有第一列。在

相关问题 更多 >