tabensemb.trainer.Trainer.cal_feature_importance#

method

Trainer.cal_feature_importance(program: str, model_name: str, method: str = 'permutation', **kwargs) Tuple[ndarray, List[str]][source]#

Calculate feature importance using a specified model. If the model base is a tabensemb.model.TorchModel, captum or shap is called to make permutations. If the model base is only a tabensemb.model.AbstractModel, the calculation will be much slower.

Parameters:
program

The selected model base.

model_name

The selected model in the model base.

method

The method to calculate importance. “permutation” or “shap”.

kwargs

kwargs for tabensemb.model.AbstractModel.cal_feature_importance()

Returns:
attr

Values of feature importance.

importance_names

Corresponding feature names. If the model base is a TorchModel, all features including derived unstacked features will be included. Otherwise, only all_feature_names() will be considered.