interpret_community.mimic.models.lightgbm_model module¶
Defines an explainable lightgbm model.
-
class
interpret_community.mimic.models.lightgbm_model.
LGBMExplainableModel
(multiclass=False, random_state=123, shap_values_output=<ShapValuesOutput.DEFAULT: 'default'>, classification=True, **kwargs)¶ Bases:
interpret_community.mimic.models.explainable_model.BaseExplainableModel
-
available_explanations
= ['global', 'local']¶
-
expected_values
¶ Use TreeExplainer to get the expected values.
Returns: The expected values of the LightGBM tree model. Return type: list
-
explain_global
(**kwargs)¶ Call lightgbm feature importances to get the global feature importances from the explainable model.
Returns: The global explanation of feature importances. Return type: numpy.ndarray
-
explain_local
(evaluation_examples, probabilities=None, **kwargs)¶ Use TreeExplainer to get the local feature importances from the trained explainable model.
Parameters: - evaluation_examples (numpy.array or pandas.DataFrame or scipy.sparse.csr_matrix) – The evaluation examples to compute local feature importances for.
- probabilities (numpy.ndarray) – If output_type is probability, can specify the teacher model’s probability for scaling the shap values.
Returns: The local explanation of feature importances.
Return type: Union[list, numpy.ndarray]
-
static
explainable_model_type
()¶ Retrieve the model type.
Returns: Tree explainable model type. Return type: ExplainableModelType
-
explainer_type
= 'model'¶ LightGBM (fast, high performance framework based on decision tree) explainable model.
Please see documentation for more details: https://github.com/Microsoft/LightGBM
Additional arguments to LightGBMClassifier and LightGBMRegressor can be passed through kwargs.
Parameters: - multiclass (bool) – Set to true to generate a multiclass model.
- random_state (int) – Int to seed the model.
- shap_values_output (interpret_community.common.constants.ShapValuesOutput) – The type of the output from explain_local when using TreeExplainer. Currently only types ‘default’, ‘probability’ and ‘teacher_probability’ are supported. If ‘probability’ is specified, then we approximately scale the raw log-odds values from the TreeExplainer to probabilities.
- classification (bool) – Indicates if this is a classification or regression explanation.
-
fit
(dataset, labels, **kwargs)¶ Call lightgbm fit to fit the explainable model.
Parameters: - dataset (numpy.array or pandas.DataFrame or scipy.sparse.csr_matrix) – The dataset to train the model on.
- labels (numpy.array) – The labels to train the model on.
-
model
¶ Retrieve the underlying model.
Returns: The lightgbm model, either classifier or regressor. Return type: Union[LGBMClassifier, LGBMRegressor]
-
predict
(dataset, **kwargs)¶ Call lightgbm predict to predict labels using the explainable model.
Parameters: dataset (numpy.array or pandas.DataFrame or scipy.sparse.csr_matrix) – The dataset to predict on. Returns: The predictions of the model. Return type: list
-
predict_proba
(dataset, **kwargs)¶ Call lightgbm predict_proba to predict probabilities using the explainable model.
Parameters: dataset (numpy.array or pandas.DataFrame or scipy.sparse.csr_matrix) – The dataset to predict probabilities on. Returns: The predictions of the model. Return type: list
-