code: def nearest_neighbors(df_1, y, json_file, trained=True):
      """
      nearest_neighbors training function
      :param df_1: dataframe
      :param y: is the target column
      :trained: whether the model is already trained or not
      :return compiled nearest_neighbors model
      """
  
      if "params" in json_file:
          n_neighbors = 5
          weights = "uniform"
          algorithm = "auto"
          alpha = 0.0001
  
          parameters = json_file["params"]
          if "n_neighbors" in parameters:
              n_neighbors = parameters["n_neighbors"]
          if "weights" in parameters:
              weights = parameters["weights"]
          if "algorithm" in parameters:
              algorithm = parameters["algorithm"]
          if "alpha" in parameters:
              alpha = parameters["alpha"]
  
          neigh = KNeighborsClassifier(
              n_neighbors=n_neighbors,
              weights=weights,
              algorithm=algorithm,
              alpha=alpha,
          )
  
          if trained:
              neigh.fit(df_1, y)
          return neigh
      else:
          min_neighbors = 3
          max_neighbors = 13
          best_score = 0
          best_model = None
          best_neighbors = 0
  
          if trained:
              sample_amount = int(len(df_1) * 0.5)
              sampled_df = df_1.iloc[:sample_amount]
              sampled_y = y.iloc[:sample_amount]
  
              for x in range(min_neighbors, max_neighbors):
                  neigh = KNeighborsClassifier(n_neighbors=x)
                  neigh.fit(sampled_df, sampled_y)
                  neigh.fit(sampled_df, sampled_y)
                  a_score = accuracy_score(
                      neigh.predict(sampled_df), sampled_y
                  )
                  if a_score > best_score:
                      best_score = a_score
                      best_neighbors = x
                      best_model = neigh
  
              model = KNeighborsClassifier(
                  n_neighbors=best_neighbors
              ).fit(df_1, y)
          else:
              model = KNeighborsClassifier()
      return model
  
imports: from sklearn.tree import DecisionTreeClassifier
  from sklearn import svm
  import numpy
  from sklearn.linear_model import SGDClassifier
  from sklearn.neighbors import KNeighborsClassifier
  from sklearn.ensemble import GradientBoostingClassifier
  from sklearn.ensemble import AdaBoostClassifier
  from sklearn.ensemble import RandomForestClassifier
  from sklearn.neural_network import MLPClassifier
  from sklearn.metrics import accuracy_score
  from sklearn.ensemble import ExtraTreesClassifier
  from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
  import warnings
label_desc: Use image node_id 3 for calling a global function with example usage: nearest_neighbors(df_1, y, json_file, trained) and returns: model, neigh