【问题标题】:ValueError: name is not a valid ExplainerComponentValueError:名称不是有效的解释器组件
【发布时间】:2022-07-15 17:06:34
【问题描述】:

我正在尝试在 ExplainerHub 中可视化我的仪表板。但是,我的比较选项卡在我单独运行时运行,而不是在 ExplainerHub 中运行。结果,我收到了这个 ValueError: name is not a valid ExplainerComponent ... 这是我试图作为比较仪表板运行的仪表板:

class ResultComparison(ExplainerComponent):
    def __init__(self, explainer_lgbm, explainer_xgb):
        super().__init__(explainer_catb)
                
        # ShapDependenceComponent
        self.confmat_catb_shap_dep = ShapDependenceComponent(explainer_catb, subtitle='CatBoost', cutoff=0.3,
                            hide_selector=True, hide_percentage=True)
        self.confmat_xgb_shap_dep = ShapDependenceComponent(explainer_xgb, subtitle='XGBoost', cutoff=0.3,
                            hide_selector=True, hide_percentage=True)
        
        # PrecisionComponent
        self.confmat_catb_prec = PrecisionComponent(explainer_catb, subtitle='CatBoost', cutoff=0.3,
                            hide_selector=True, hide_percentage=True)
        self.confmat_xgb_prec = PrecisionComponent(explainer_xgb, subtitle='XGBoost', cutoff=0.3,
                            hide_selector=True, hide_percentage=True)
       
    def layout(self):
        return dbc.Container([
            dbc.Row([
                dbc.Col([
                    self.confmat_catb_shap_dep.layout()
                ]),
                dbc.Col([
                    self.confmat_xgb_shap_dep.layout()
                ]),
            ]),
            dbc.Row([
                dbc.Col([
                    self.confmat_catb_prec.layout()
                ]),
                dbc.Col([
                    self.confmat_xgb_prec.layout()
                ]),

            ]),
        ])
    
tab = ResultComparison(explainer_catb, explainer_xgb)

db_comp = ExplainerDashboard(explainer_xgb, tabs=tab, name='comparison', title="Comarison Results",
                            decision_trees=False,
                            whatif=False,
                            shap_interaction=False,
                            contributions=False, 
                             model_summary=False, 
                             shap_dependence=False)
# run comparison dashboard alone
#db_comp.run(8052)
# Run all dashboards in a single host
#db_catb, db_lgbm, db_xgb, 
hub = ExplainerHub([db_comp])
hub.run(8053)```


When I run explainer it throws this error. 

【问题讨论】:

    标签: python python-3.x


    【解决方案1】:

    它可能来自这一行:

    # your way
    db_comp = ExplainerDashboard(explainer_xgb, tabs=tab, ...)
    
    # correct way
    db_comp = ExplainerDashboard(explainer_xgb, tabs=[tab], ...)
    

    抛出错误的那一行被这行调用:

    self.tabs  = [
       instantiate_component(tab, explainer, name=str(i+1), **kwargs)
       for i, tab in enumerate(tabs)
    ]
    

    显然它不接受tab,但它应该接受[tab],因为它应该是一个组件列表。 抛出的错误不是很解释,在文档中它同时用于tab[tab] 形式,但只有[tab] 是正确的。

    可能在它进行迭代时(因为它期望一个列表枚举)它实际上是在迭代这个元组(tab, explainer, name=str(i+1), **kwargs),所以它得到参数'name',它实际上是在抛出:ValueError: name is not a valid ExplainerComponent,如name 不是一个组件,正确的。

    【讨论】:

      猜你喜欢
      • 2017-03-02
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 2016-02-24
      • 1970-01-01
      • 2015-06-10
      • 2016-08-03
      相关资源
      最近更新 更多