python出错 unexpected keyword argument 'categories'

python出错 unexpected keyword argument 'categories'

    • 解决办法
      • 首先卸载scikit-learn
      • 下载scikit-learn 新版
      • 安装scikit-learn新版
      • 下载numpy 新版
      • 安装numpy新版

python 运行OneHotEncode出错:TypeError: init() got an unexpected keyword argument 'categories’
运行一个网上的GBDT+LR 开源代码 报下面的错:

Traceback (most recent call last):
  File "D:/code/test_ML/plot_feature_transformation.py", line 65, in <module>
    rf_enc = OneHotEncoder(categories='auto')
TypeError: __init__() got an unexpected keyword argument 'categories'

解决办法

经过实践可能是 scikit_learn 和 numpy版本过低
删除原有scilit_learn 安装0.21版(原来是0.19)
删除原有numpy 安装1.17(原来是1.14)
再运行调用 OneHotEncoder 的文件错误消失。

首先卸载scikit-learn

C:\Users\dd>pip uninstall scikit-learn
Uninstalling scikit-learn-0.19.1:
  Would remove:
    d:\programdata\anaconda3\lib\site-packages\scikit_learn-0.19.1-py3.6.egg-info
    d:\programdata\anaconda3\lib\site-packages\sklearn
Proceed (y/n)? y
  Successfully uninstalled scikit-learn-0.19.1

下载scikit-learn 新版

widows安装包下载链接
https://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn
linux安装包下载链接https://pypi.org/project/scikit-learn/#files

安装scikit-learn新版

windows系统下安装

D:
cd D:\download\install_src\PythonPacket
pip install scikit_learn-0.21.3-cp36-cp36m-win_amd64.wh

linux系统下安装

$ cd /mnt/hgfs/D/download/install_src/PythonPacket/
$pip install scikit_learn-0.21.3-cp36-cp36m-manylinux1_x86_64.whl

下载numpy 新版

widows安装包下载链接
https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
linux安装包下载链接https://pypi.org/project/numpy/#files

安装numpy新版

Windows系统下安装

D:\download\install_src\PythonPacket>pip install "numpy-1.17.2+mkl-cp36-cp36m-win_amd64.whl"
Processing d:\download\install_src\pythonpacket\numpy-1.17.2+mkl-cp36-cp36m-win_amd64.whl
distributed 1.21.8 requires msgpack, which is not installed.
Installing collected packages: numpy
Successfully installed numpy-1.17.2+mkl
You are using pip version 10.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

linux系统下安装

$ cd /mnt/hgfs/D/download/install_src/PythonPacket/
$pip install numpy-1.17.3-cp36-cp36m-manylinux1_x86_64.whl

Skit_learn 库的使用,可以参考相关文章1


  1. 链接 https://www.cnblogs.com/wj-1314/p/10179741.html ↩︎

你可能感兴趣的:(python出错 unexpected keyword argument 'categories')