eli5.lightgbm
eli5 has LightGBM support - eli5.explain_weights()
shows feature importances, and eli5.explain_prediction() explains
predictions by showing feature weights.
Both functions work for LGBMClassifier and LGBMRegressor.
- explain_prediction_lightgbm(lgb, doc, vec=None, top=None, top_targets=None, target_names=None, targets=None, feature_names=None, feature_re=None, feature_filter=None, vectorized=False, is_regression=None)[source]
Return an explanation of LightGBM prediction (via scikit-learn wrapper LGBMClassifier or LGBMRegressor, or via lightgbm.Booster) as feature weights.
See
eli5.explain_prediction()for description oftop,top_targets,target_names,targets,feature_names,feature_reandfeature_filterparameters.vecis a vectorizer instance used to transform raw features to the input of the estimatorxgb(e.g. a fitted CountVectorizer instance); you can pass it instead offeature_names.vectorizedis a flag which tells eli5 ifdocshould be passed throughvecor not. By default it is False, meaning that ifvecis not None,vec.transform([doc])is passed to the estimator. Set it to True if you’re passingvec, butdocis already vectorized.is_regressionis a flag, True if solving a regression problem and False for a classification problem. Needs to be passed only if it can’t be determined from other arguments.Method for determining feature importances follows an idea from http://blog.datadive.net/interpreting-random-forests/. Feature weights are calculated by following decision paths in trees of an ensemble. Each leaf has an output score, and expected scores can also be assigned to parent nodes. Contribution of one feature on the decision path is how much expected score changes from parent to child. Weights of all features sum to the output score of the estimator.
- explain_weights_lightgbm(lgb, vec=None, top=20, target_names=None, targets=None, feature_names=None, feature_re=None, feature_filter=None, importance_type='gain', is_regression=None)[source]
Return an explanation of an LightGBM estimator (via scikit-learn wrapper LGBMClassifier or LGBMRegressor, or via lightgbm.Booster) as feature importances.
See
eli5.explain_weights()for description oftop,feature_names,target_names,feature_reandfeature_filterparameters.target_namesarguement is ignored forlightgbm.LGBMClassifer/lightgbm.LGBMRegressor, but used forlightgbm.Booster.targetsargument is ignored.- Parameters:
importance_type (str, optional) – A way to get feature importance. Possible values are:
‘gain’ - the average gain of the feature when it is used in trees (default)
‘split’ - the number of times a feature is used to split the data across all trees
‘weight’ - the same as ‘split’, for compatibility with xgboost
is_regression (bool, optional) – True if solving a regression problem and False for a classification problem. Needs to be passed only if it can’t be determined from other arguments.