code: def oob_classifier_f1_score(rf, X_train, y_train):
      """
      Compute out-of-bag (OOB) f1 score for a scikit-learn random forest
      classifier. We learned the guts of scikit's RF from the BSD licensed
      code:
  
      https://github.com/scikit-learn/scikit-learn/blob/a24c8b46/sklearn/ensemble/forest.py#L425
      """
      X = X_train.values
      y = y_train.values
  
      n_samples = len(X)
      n_classes = len(np.unique(y))
      predictions = np.zeros((n_samples, n_classes))
      for tree in rf.estimators_:
          unsampled_indices = _get_unsampled_indices(tree, n_samples)
          tree_preds = tree.predict_proba(X[unsampled_indices, :])
          predictions[unsampled_indices] += tree_preds
  
      predicted_class_indexes = np.argmax(predictions, axis=1)
      predicted_classes = [
          rf.classes_[i] for i in predicted_class_indexes
      ]
  
      oob_score = f1_score(y, predicted_classes, average="macro")
      return oob_score
  
imports: import pandas
  import numpy
  import matplotlib.pyplot
  import sklearn
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.ensemble import RandomForestRegressor
  from distutils.version import LooseVersion
  from sklearn.model_selection import cross_val_score
  from sklearn.base import clone
  from sklearn.metrics import r2_score
  from sklearn.metrics import f1_score
  from sklearn.preprocessing import LabelEncoder
  from scipy import stats
  from pandas.api.types import is_numeric_dtype
  from matplotlib.colors import ListedColormap
  from matplotlib.ticker import FormatStrFormatter
  from copy import copy
  import warnings
  import tempfile
  from os import getpid, makedirs
label_desc: Use image node_id 13 for calling a global function with example usage: oob_classifier_f1_score(rf, X_train, y_train) and returns: oob_score