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

使用interpret库的LimeTabular报错:缺少必填参数'model'

问题解决:LimeTabular初始化报错TypeError: init() missing 1 required positional argument: 'model'

错误原因

你使用的interpret库版本中,LimeTabular的构造函数已更新,model参数变为必填项,不再支持仅通过predict_fn传入预测函数的方式初始化。

修复方案

修改LimeTabular的初始化代码,添加model参数,将训练好的随机森林模型传入:

# 修正后的Lime初始化代码
lime = LimeTabular(model=rf,  # 新增必填的model参数
                   data=X_train, 
                   random_state=1)

若需自定义预测逻辑(比如不用模型默认的predict_proba),可同时保留predict_fn参数,但model仍为必填:

lime = LimeTabular(model=rf,
                   predict_fn=rf.predict_proba,
                   data=X_train, 
                   random_state=1)

完整修正后的代码片段

# %% Apply lime
# Initilize Lime for Tabular data
lime = LimeTabular(model=rf,
                   data=X_train, 
                   random_state=1)
# Get local explanations
lime_local = lime.explain_local(X_test[-20:], 
                                y_test[-20:], 
                                name='LIME')

show(lime_local)

补充说明

  • 新版本interpret库的LimeTabular设计更规范,强制关联模型实例,避免仅传预测函数可能导致的上下文缺失问题。
  • 若需兼容旧写法,可降级interpret库到0.2.7及以下版本,但更推荐适配新版本参数要求。

内容的提问来源于stack exchange,提问作者pan kai

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 13:32:40