多项式特征fit_transform给出值错误



我在尝试运行多项式回归示例时收到ValueError:

from sklearn.preprocessing import PolynomialFeatures
import numpy as np
poly = PolynomialFeatures(degree=2)
poly.fit_transform(X)   ==> ERROR

错误为:

File "/root/.local/lib/python2.7/site-packages/sklearn/base.py", line 426, in fit_transform
    return self.fit(X, **fit_params).transform(X)
File "/root/.local/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 473, in fit
  self.include_bias)
File "/root/.local/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 463, in _power_matrix
  powers = np.vstack(np.bincount(c, minlength=n_features) for c in combn)
File "/usr/lib/python2.7/dist-packages/numpy/core/shape_base.py", line 226, in vstack
  return _nx.concatenate(map(atleast_2d,tup),0)
File "/root/.local/lib/python2.7/site-packages/sklearn/preprocessing/data.py", line 463, in <genexpr>
  powers = np.vstack(np.bincount(c, minlength=n_features) for c in combn)  
  ValueError: The first argument cannot be empty.

我的scikit学习版本是0.15.2

此示例摘自:http://scikit-learn.org/stable/modules/linear_model.html#polynomial-具有基函数的回归扩展线性模型

当创建像这样的多项式特征类的对象时,应该尝试将include_bias设置为False

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

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

相关内容

  • 没有找到相关文章

最新更新