class_docstr: Allows the discretisation of continuous features based on the split thresholds of either
  sklearn's DecisionTreeRegressor or DecisionTreeClassifier.
  DecisionTreeSupervisedDiscretiserMethod is inhereited from AbstractSupervisedDiscretiserMethod.
  When instantiated, we have an object with .fit method to learn discretisation thresholds from data
  and .transform method to process the input.
  
  
  Example:
  ::
      >>> import pandas as pd
      >>> import numpy as np
      >>> from causalnex.discretiser.discretiser_strategy import DecisionTreeSupervisedDiscretiserMethod
      >>> from sklearn.datasets import load_iris
      >>> iris = load_iris()
      >>> X, y = iris["data"], iris["target"]
      >>> names = iris["feature_names"]
      >>> data = pd.DataFrame(X, columns=names)
      >>> data["target"] = y
      >>> dt_multi = DecisionTreeSupervisedDiscretiserMethod(
      >>>     mode="multi", tree_params={"max_depth": 3, "random_state": 2020}
      >>> )
      >>> tree_discretiser = dt_multi.fit(
      >>>     feat_names=[
      >>>         "sepal length (cm)",
      >>>         "sepal width (cm)",
      >>>         "petal length (cm)",
      >>>         "petal width (cm)",
      >>>     ],
      >>>     dataframe=data,
      >>>     target="target",
      >>>     target_continuous=False,
      >>> )
      >>> discretised_data = tree_discretiser.transform(data[["petal width (cm)"]])
      >>> discretised_data.values.ravel()
      array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
         0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
         1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
         1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2,
         2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2,
         2, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])
class_docstr_tok: ["Allows","the","discretisation","of","continuous","features","based","on","the","split","thresholds","of","either","sklearn","'s","DecisionTreeRegressor","or","DecisionTreeClassifier",".","DecisionTreeSupervisedDiscretiserMethod","is","inhereited","from","AbstractSupervisedDiscretiserMethod",".","When","instantiated",",","we","have","an","object","with",".fit","method","to","learn","discretisation","thresholds","from","data","and",".transform","method","to","process","the","input",".","Example",":",":",":",">",">",">","import","pandas","as","pd",">",">",">","import","numpy","as","np",">",">",">","from","causalnex.discretiser.discretiser_strategy","import","DecisionTreeSupervisedDiscretiserMethod",">",">",">","from","sklearn.datasets","import","load_iris",">",">",">","iris","=","load_iris","(",")",">",">",">","X",",","y","=","iris","[","``","data","''","]",",","iris","[","``","target","''","]",">",">",">","names","=","iris","[","``","feature_names","''","]",">",">",">","data","=","pd.DataFrame","(","X",",","columns=names",")",">",">",">","data","[","``","target","''","]","=","y",">",">",">","dt_multi","=","DecisionTreeSupervisedDiscretiserMethod","(",">",">",">","mode=","''","multi","''",",","tree_params=","{","``","max_depth","''",":","3",",","``","random_state","''",":","2020","}",">",">",">",")",">",">",">","tree_discretiser","=","dt_multi.fit","(",">",">",">","feat_names=","[",">",">",">","``","sepal","length","(","cm",")","''",",",">",">",">","``","sepal","width","(","cm",")","''",",",">",">",">","``","petal","length","(","cm",")","''",",",">",">",">","``","petal","width","(","cm",")","''",",",">",">",">","]",",",">",">",">","dataframe=data",",",">",">",">","target=","''","target","''",",",">",">",">","target_continuous=False",",",">",">",">",")",">",">",">","discretised_data","=","tree_discretiser.transform","(","data","[","[","``","petal","width","(","cm",")","''","]","]",")",">",">",">","discretised_data.values.ravel","(",")","array","(","[","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","0",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","2",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","1",",","2",",","2",",","2",",","2",",","2",",","2",",","1",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","1",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","1",",","2",",","2",",","2",",","1",",","1",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2",",","2","]",")"]
docstr: The fit method allows DecisionTrees to learn split thresholds from the input data
  
  Args:
      feat_names (List[str]): a list of feature to be discretised
      target (str): name of variable that is going to be used a target for the decision tree
      dataframe (pd.DataFrame): pandas dataframe of input data
      target_continuous (bool): a boolean that indicates if the target variable is continuous
  
  Returns:
      self: DecisionTreeSupervisedDiscretiserMethod object with learned split thresholds from the decision tree
docstr_tok: ["The","fit","method","allows","DecisionTrees","to","learn","split","thresholds","from","the","input","data","Args",":","feat_names","(","List","[","str","]",")",":","a","list","of","feature","to","be","discretised","target","(","str",")",":","name","of","variable","that","is","going","to","be","used","a","target","for","the","decision","tree","dataframe","(","pd.DataFrame",")",":","pandas","dataframe","of","input","data","target_continuous","(","bool",")",":","a","boolean","that","indicates","if","the","target","variable","is","continuous","Returns",":","self",":","DecisionTreeSupervisedDiscretiserMethod","object","with","learned","split","thresholds","from","the","decision","tree"]
code: def fit(
      self,
      feat_names: List[str],
      target: str,
      dataframe: pd.DataFrame,
      target_continuous: bool,
  ) -> "DecisionTreeSupervisedDiscretiserMethod":
      """
      The fit method allows DecisionTrees to learn split thresholds from the input data
  
      Args:
          feat_names (List[str]): a list of feature to be discretised
          target (str): name of variable that is going to be used a target for the decision tree
          dataframe (pd.DataFrame): pandas dataframe of input data
          target_continuous (bool): a boolean that indicates if the target variable is continuous
  
      Returns:
          self: DecisionTreeSupervisedDiscretiserMethod object with learned split thresholds from the decision tree
      """
      dtree = (
          DecisionTreeRegressor(**self.tree_params)
          if target_continuous
          else DecisionTreeClassifier(**self.tree_params)
      )
      self.feat_names = feat_names
      self.map_thresholds = {}
  
      if self.mode == "single":
          for feat in feat_names:
              dtree = deepcopy(dtree)
  
              dtree.fit(dataframe[[feat]], dataframe[[target]])
              thresholds = extract_thresholds_from_dtree(dtree, 1)[0]
              self.map_thresholds[feat] = thresholds
  
      elif self.mode == "multi":
          dtree = deepcopy(dtree)
          dtree.fit(dataframe[feat_names], dataframe[[target]])
          threshold_list = extract_thresholds_from_dtree(
              dtree, len(feat_names)
          )
  
          for feat, threshold in zip(feat_names, threshold_list):
              self.map_thresholds[feat] = threshold
  
          if self.split_unselected_feat:
              for feat, thres in self.map_thresholds.items():
                  if thres.size == 0:
                      dtree = deepcopy(dtree)
                      dtree.fit(dataframe[[feat]], dataframe[[target]])
                      thresholds = extract_thresholds_from_dtree(
                          dtree, 1
                      )[0]
                      self.map_thresholds[feat] = thresholds
  
          else:
              no_use = []
              for feat in list(self.map_thresholds.keys()):
                  if self.map_thresholds[feat].size == 0:
                      no_use.append(feat)
                      del self.map_thresholds[feat]
              if len(no_use) > 0:
                  logging.warning(
                      "%s not selected by the decision tree. No discretisation thresholds were learned. "
                      "Consider setting split_unselected_feat = True or discretise them using single mode",
                      no_use,
                  )
  
      return self
  
file_path: causalnex/causalnex/discretiser/discretiser_strategy.py
imports: import logging
  from copy import deepcopy
  from typing import Any, Dict, List
  import pandas
  from sklearn.tree import DecisionTreeClassifier, DecisionTreeRegressor
  from causalnex.discretiser.abstract_discretiser import AbstractSupervisedDiscretiserMethod
  from causalnex.utils.decision_tree_tools import extract_thresholds_from_dtree
label_desc: Use image node_id 2 for calling the DecisionTreeSupervisedDiscretiserMethod obj's underlying member method code with example usage: obj.fit(feat_names, target, dataframe, target_continuous) and returns: self