code: def _get_prediction_feature_weights(lgb, X, n_targets):
      """
      Return a list of {feat_id: value} dicts with feature weights,
      following ideas from  http://blog.datadive.net/interpreting-random-forests/
      """
      if n_targets == 2:
          n_targets = 1
      dump = lgb.booster_.dump_model()
      tree_info = dump["tree_info"]
      _compute_node_values(tree_info)
      pred_leafs = lgb.booster_.predict(X, pred_leaf=True).reshape(
          -1, n_targets
      )
      tree_info = np.array(tree_info).reshape(-1, n_targets)
      assert pred_leafs.shape == tree_info.shape
  
      res = []
      for target in range(n_targets):
          feature_weights = defaultdict(
              float
          )  # type: DefaultDict[Optional[str], float]
          for info, leaf_id in zip(
              tree_info[:, target], pred_leafs[:, target]
          ):
              leaf_index, split_index = _get_leaf_split_indices(
                  info["tree_structure"]
              )
              bias, path = _get_decision_path(
                  leaf_index, split_index, leaf_id
              )
              feature_weights[None] += bias
              for feat, value in path:
                  feature_weights[feat] += value
          res.append(dict(feature_weights))
      return res
  
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 9 for calling a global function with example usage: _get_prediction_feature_weights(lgb, X, n_targets) and returns: res