code: def 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,
  ):
      """Return an explanation of LightGBM prediction (via scikit-learn wrapper
      LGBMClassifier or LGBMRegressor) as feature weights.
  
      See :func:`eli5.explain_prediction` for description of
      ``top``, ``top_targets``, ``target_names``, ``targets``,
      ``feature_names``, ``feature_re`` and ``feature_filter`` parameters.
  
      ``vec`` is a vectorizer instance used to transform
      raw features to the input of the estimator ``xgb``
      (e.g. a fitted CountVectorizer instance); you can pass it
      instead of ``feature_names``.
  
      ``vectorized`` is a flag which tells eli5 if ``doc`` should be
      passed through ``vec`` or not. By default it is False, meaning that
      if ``vec`` is not None, ``vec.transform([doc])`` is passed to the
      estimator. Set it to True if you're passing ``vec``,
      but ``doc`` is already vectorized.
  
      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.
      """
  
      vec, feature_names = handle_vec(
          lgb, doc, vec, vectorized, feature_names
      )
      if feature_names.bias_name is None:
          # LightGBM estimators do not have an intercept, but here we interpret
          # them as having an intercept
          feature_names.bias_name = "<BIAS>"
      X = get_X(doc, vec, vectorized=vectorized)
  
      proba = predict_proba(lgb, X)
      weight_dicts = _get_prediction_feature_weights(
          lgb, X, _lgb_n_targets(lgb)
      )
      x = get_X0(add_intercept(X))
  
      is_regression = isinstance(lgb, lightgbm.LGBMRegressor)
      is_multiclass = _lgb_n_targets(lgb) > 2
      names = lgb.classes_ if not is_regression else ["y"]
  
      def get_score_weights(_label_id):
          _weights = _target_feature_weights(
              weight_dicts[_label_id],
              num_features=len(feature_names),
              bias_idx=feature_names.bias_idx,
          )
          _score = _get_score(weight_dicts[_label_id])
          return _score, _weights
  
      return get_decision_path_explanation(
          lgb,
          doc,
          vec,
          x=x,
          feature_names=feature_names,
          feature_filter=feature_filter,
          feature_re=feature_re,
          top=top,
          vectorized=vectorized,
          original_display_names=names,
          target_names=target_names,
          targets=targets,
          top_targets=top_targets,
          is_regression=is_regression,
          is_multiclass=is_multiclass,
          proba=proba,
          get_score_weights=get_score_weights,
      )
  
file_path: eli5/eli5/lightgbm.py
imports: from __future__ import absolute_import, division
  from collections import defaultdict
  from typing import DefaultDict, Optional
  import numpy
  import lightgbm
  from eli5.explain import explain_weights, explain_prediction
  from eli5._feature_importances import get_feature_importance_explanation
  from eli5.sklearn.utils import handle_vec, get_X, get_X0, add_intercept, predict_proba
  from eli5._decision_path import get_decision_path_explanation
label_desc: Use image node_id 2 for calling a global function with example usage: explain_prediction_lightgbm(lgb, doc, vec, top, top_targets, target_names, targets, feature_names, feature_re, feature_filter, vectorized) and returns: get_decision_path_explanation, _score,  _weights