You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 06:47:01