code: def plotly_rf_trees(
      model,
      observation,
      y=None,
      highlight_tree=None,
      round=2,
      pos_label=1,
      target="",
      units="",
  ):
      """Generate a plot showing the prediction of every single tree inside a RandomForest model
  
      Args:
          model ({RandomForestClassifier, RandomForestRegressor}): model to display trees for
          observation (pd.DataFrame): row of input data, e.g. X.iloc[[0]]
          y (np.ndarray, optional): Target values. Defaults to None.
          highlight_tree (int, optional): DecisionTree to highlight in graph. Defaults to None.
          round (int, optional): Apply rounding to floats. Defaults to 2.
          pos_label (int, optional): For RandomForestClassifier: Class label
              to generate graph for. Defaults to 1.
          target (str, optional): Description of target variable. Defaults to "".
          units (str, optional): Units of target variable. Defaults to "".
  
      Returns:
          Plotly fig
      """
      assert safe_isinstance(
          model,
          "RandomForestClassifier",
          "RandomForestRegressor",
          "ExtraTreesClassifier",
          "ExtraTreesRegressor",
      ), (
          f"model is of type {type(model)}, but plot_rf_trees() only accepts RandomForestClassifier, "
          "RandomForestRegressor, ExtraTreesClassifier or ExtraTreesRegressor!"
      )
  
      colors = ["blue"] * len(model.estimators_)
      if highlight_tree is not None:
          assert highlight_tree >= 0 and highlight_tree <= len(
              model.estimators_
          ), f"{highlight_tree} is out of range (0, {len(model.estimators_)})"
          colors[highlight_tree] = "red"
      warnings.filterwarnings("ignore", category=UserWarning)
      if safe_isinstance(
          model, "RandomForestClassifier", "ExtraTreesClassifier"
      ):
          preds_df = (
              pd.DataFrame(
                  {
                      "model": range(len(model.estimators_)),
                      "prediction": [
                          np.round(
                              100
                              * m.predict_proba(observation)[
                                  0, pos_label
                              ],
                              round,
                          )
                          for m in model.estimators_
                      ],
                      "color": colors,
                  }
              )
              .sort_values("prediction")
              .reset_index(drop=True)
          )
      else:
          preds_df = (
              pd.DataFrame(
                  {
                      "model": range(len(model.estimators_)),
                      "prediction": [
                          np.round(m.predict(observation)[0], round)
                          for m in model.estimators_
                      ],
                      "color": colors,
                  }
              )
              .sort_values("prediction")
              .reset_index(drop=True)
          )
      warnings.filterwarnings("default", category=UserWarning)
  
      trace0 = go.Bar(
          x=preds_df.index,
          y=preds_df.prediction,
          marker_color=preds_df.color,
          text=[
              f"tree no {t}:<br> prediction={p}<br> click for detailed info"
              for (t, p) in zip(
                  preds_df.model.values, preds_df.prediction.values
              )
          ],
          hoverinfo="text",
      )
  
      if target:
          title = f"Individual decision trees predicting {target}"
          yaxis_title = (
              f"Predicted {target} {f'({units})' if units else ''}"
          )
      else:
          title = f"Individual decision trees"
          yaxis_title = (
              f"Predicted outcome ({units})"
              if units
              else "Predicted outcome"
          )
  
      layout = go.Layout(
          title=title,
          plot_bgcolor="#fff",
          yaxis=dict(title=yaxis_title),
          xaxis=dict(title="decision trees (sorted by prediction"),
      )
      fig = go.Figure(data=[trace0], layout=layout)
      shapes = [
          dict(
              type="line",
              xref="x",
              yref="y",
              x0=0,
              x1=preds_df.model.max(),
              y0=preds_df.prediction.mean(),
              y1=preds_df.prediction.mean(),
              line=dict(color="lightgray", width=4, dash="dot"),
          )
      ]
  
      annotations = [
          go.layout.Annotation(
              x=1.2 * preds_df.model.mean(),
              y=preds_df.prediction.mean(),
              text=f"Average prediction = {preds_df.prediction.mean():.{round}f}",
              bgcolor="lightgrey",
              arrowcolor="lightgrey",
              startstandoff=0,
          )
      ]
  
      if y is not None:
          shapes.append(
              dict(
                  type="line",
                  xref="x",
                  yref="y",
                  x0=0,
                  x1=preds_df.model.max(),
                  y0=y,
                  y1=y,
                  line=dict(color="red", width=4, dash="dashdot"),
              )
          )
          annotations.append(
              go.layout.Annotation(
                  x=0.8 * preds_df.model.mean(),
                  y=y,
                  text=f"observed={y}",
                  bgcolor="red",
                  arrowcolor="red",
              )
          )
  
      fig.update_layout(shapes=shapes)
      fig.update_layout(annotations=annotations)
      fig.update_layout(margin=dict(t=40, b=40, l=40, r=40))
      return fig
  
imports: import warnings
  import numpy
  import pandas
  from pandas.api.types import is_numeric_dtype
  import plotly.graph_objs
  from plotly.subplots import make_subplots
  from sklearn.metrics import classification_report, confusion_matrix, precision_recall_curve, roc_curve, roc_auc_score, average_precision_score
  from .explainer_methods import matching_cols, safe_isinstance
label_desc: Use image node_id 20 for calling a global function with example usage: plotly_rf_trees(model, observation, y, highlight_tree, round, pos_label, target, units) and returns: fig