使用LazyPredict拟合时报错:OneHotEncoder初始化参数'sparse'异常
解决LazyPredict拟合时OneHotEncoder的sparse参数报错问题
问题原因
scikit-learn 1.2及以上版本已移除OneHotEncoder类的sparse参数,但旧版LazyPredict的代码仍在使用该参数,版本不兼容导致触发TypeError。
可行解决方案
- 降级scikit-learn到兼容版本,执行命令:
pip install scikit-learn==1.1.3 - 升级LazyPredict到最新版本(已修复该兼容问题),执行命令:
pip install --upgrade lazypredict - 手动修改LazyPredict源码(不推荐):找到LazyPredict安装目录下的
Supervised.py文件,将所有OneHotEncoder(sparse=...)的代码替换为OneHotEncoder(sparse_output=...),比如把OneHotEncoder(sparse=False)改成OneHotEncoder(sparse_output=False)
内容的提问来源于stack exchange,提问作者Mohammad Affan
相关产品推荐
相关产品推荐

