code: def get_weighted_neighbors_dataframe(
      X_leaves, y_train_leaves, y_train, y_weights
  ):
      """For each test sample, get the list of weighted targets that are assigned to the same leaf by at least one estimator.
  
      Parameters
      ----------
      X_leaves : array, shape [n_test, n_estimators]
          Index of the leave assigned to each test sample by each estimator.
      y_train_leaves : array, shape [n_estimators, n_train]
          Index of the leave assigned to each training sample by each estimator.
      y_train : array, shape [n_train]
          Values of training samples.
      y_weights : array, shape [n_estimators, n_train]
          Weight assigned to each training sample by each estimator.
  
      Returns
      -------
      weighted_neighbors_dataframe : pd.DataFrame
          Dataframe that contains weighted neighbors of each item in the test set.
          Columns:
              item_id: ID of each item in the test set
              y: Target value encountered in the same leaf as the item
              weight: Weight assigned to each target value
      """
      assert (
          X_leaves.shape[1]
          == y_train_leaves.shape[0]
          == y_weights.shape[0]
      )
      assert (
          y_train_leaves.shape[1]
          == y_train.shape[0]
          == y_weights.shape[1]
      )
  
      num_test, num_trees = X_leaves.shape
      _, num_train = y_train_leaves.shape
  
      tree_index_x = np.arange(num_trees)[None].repeat(
          [num_test], axis=0
      )
      item_index_x = np.arange(num_test)[:, None].repeat(
          [num_trees], axis=1
      )
      df_x = pd.DataFrame(
          {
              "item_id": item_index_x.ravel(),
              "tree_id": tree_index_x.ravel(),
              "leaf": X_leaves.ravel(),
          }
      )
      tree_index_y = np.arange(num_trees)[:, None].repeat(
          [num_train], axis=1
      )
      target_y = y_train[None].repeat([num_trees], axis=0)
      df_y = pd.DataFrame(
          {
              "tree_id": tree_index_y.ravel(),
              "leaf": y_train_leaves.ravel(),
              "y": target_y.ravel(),
              "weight": y_weights.ravel(),
          }
      )
      samples_with_neighbors = pd.merge(
          df_x, df_y, on=["tree_id", "leaf"]
      )
      return (
          samples_with_neighbors.groupby(["item_id", "y"])
          .sum()
          .reset_index()[["item_id", "y", "weight"]]
      )
  
imports: import logging
  from functools import partial
  import numpy
  import pandas
  from sklearn.ensemble._forest import ForestRegressor
  from sklearn.tree import BaseDecisionTree, DecisionTreeRegressor, ExtraTreeRegressor
  from sklearn.utils import check_array, check_random_state, check_X_y
label_desc: Use image node_id 3 for calling a global function with example usage: get_weighted_neighbors_dataframe(X_leaves, y_train_leaves, y_train, y_weights) and returns: samples_with_neighbors