简体   繁体   English

PolynomialFeatures fit_transform给出值错误

[英]PolynomialFeatures fit_transform is giving Value error

I am getting a ValueError while trying to run the Polynomial Regression example: 我在尝试运行多项式回归示例时遇到ValueError:

from sklearn.preprocessing import PolynomialFeatures
import numpy as np

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

The error is: 错误是:

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.

My scikit-learn version is 0.15.2 我的scikit-learn版本是0.15.2

This is example is taken from: http://scikit-learn.org/stable/modules/linear_model.html#polynomial-regression-extending-linear-models-with-basis-functions 此示例摘自: http : //scikit-learn.org/stable/modules/linear_model.html#polynomial-regression-extending-linear-models-with-basis-functions

You should try to set include_bias to False when creating object of PolynomialFeatures class like this 创建像这样的PolynomialFeatures类的对象时,应尝试将include_bias设置为False。

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

Note that the final matrix in the example does not have the first column now. 请注意,示例中的最终矩阵现在没有第一列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM