code: def a_tree(df_1, y, json_file, trained=True):
      """
      decision tree training function
      :param df_1: dataframe
      :param y: is the target column
      :trained: whether the model is already trained or not
      :return compiled decision tree model
      """
      criterion = "gini"
      splitter = "best"
      max_depth = None
      min_samples_split = 2
      min_samples_leaf = 1
  
      if "params" in json_file:
          parameters = json_file["params"]
          if "criterion" in json_file["params"]:
              criterion = parameters["criterion"]
          if "splitter" in json_file["params"]:
              splitter = parameters["splitter"]
          if "max_depth" in json_file["params"]:
              max_depth = parameters["max_depth"]
          if "min_samples_split" in json_file["params"]:
              min_samples_split = parameters["min_samples_split"]
          if "min_samples_leaf" in json_file["params"]:
              min_samples_leaf = parameters["min_samples_leaf"]
  
          tree = DecisionTreeClassifier(
              criterion=criterion,
              splitter=splitter,
              max_depth=max_depth,
              min_samples_split=min_samples_split,
              min_samples_leaf=min_samples_leaf,
          )
          if trained:
              tree.fit(df_1, y)
  
      else:
          grid_dict = {
              "criterion": ["gini", "entropy"],
              "max_depth": range(1, 10),
              "min_samples_split": [(x * 0.1) for x in range(1, 10)],
              "min_samples_leaf": range(1, 5),
          }
          tree = DecisionTreeClassifier()
          tree.fit(df_1, y)
  
          grid = GridSearchCV(tree, param_grid=grid_dict, verbose=0)
          grid.fit(df_1, y)
  
      return tree
  
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 4 for calling a global function with example usage: a_tree(df_1, y, json_file, trained) and returns: tree