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: This Discretiser Method uses Decision Trees to predict the target.
  The cutting points on the the Decision Tree becomes the chosen discretisation thresholds
  
  If the target is a continuous variable, we fit a `DecisionTreeRegressor` to discretise the data.
  Otherwise, we fit a Classifier.
  
  Args:
      max_depth (int): maximum depth of the decision tree.
      mode (str): Either 'single' or 'multi'.
      - if single, Train a univariate decision tree for each continuous variable being discretised.
          The splitting points of the decision tree become discretiser fixed points
      - if multi, Train a decision tree over all the variables passed.
          The splitting points of each variable used in the Decision tree become the thresholds for discretisation
      split_unselected_feat (bool): only applicable if self.mode = 'multi'.
      - if True, features not selected by the decision tree will be discretised using 'single' mode
      with the same tree parameters
      - if False, features not selected by the decision tree will be left unchanged
      tree_params: keyword arguments, which are parameters
      used for `sklearn.tree.DecisionTreeClassifier`/`sklearn.tree.DecisionTreeRegressor`
  Raises:
      KeyError: if an incorrect argument is passed
docstr_tok: ["This","Discretiser","Method","uses","Decision","Trees","to","predict","the","target",".","The","cutting","points","on","the","the","Decision","Tree","becomes","the","chosen","discretisation","thresholds","If","the","target","is","a","continuous","variable",",","we","fit","a","`","DecisionTreeRegressor","`","to","discretise","the","data",".","Otherwise",",","we","fit","a","Classifier",".","Args",":","max_depth","(","int",")",":","maximum","depth","of","the","decision","tree",".","mode","(","str",")",":","Either","'single","'","or","'multi","'",".","-","if","single",",","Train","a","univariate","decision","tree","for","each","continuous","variable","being","discretised",".","The","splitting","points","of","the","decision","tree","become","discretiser","fixed","points","-","if","multi",",","Train","a","decision","tree","over","all","the","variables","passed",".","The","splitting","points","of","each","variable","used","in","the","Decision","tree","become","the","thresholds","for","discretisation","split_unselected_feat","(","bool",")",":","only","applicable","if","self.mode","=","'multi","'",".","-","if","True",",","features","not","selected","by","the","decision","tree","will","be","discretised","using","'single","'","mode","with","the","same","tree","parameters","-","if","False",",","features","not","selected","by","the","decision","tree","will","be","left","unchanged","tree_params",":","keyword","arguments",",","which","are","parameters","used","for","`","sklearn.tree.DecisionTreeClassifier","`","\/","`","sklearn.tree.DecisionTreeRegressor","`","Raises",":","KeyError",":","if","an","incorrect","argument","is","passed"]
code: def __init__(
      self,
      mode: str = "single",
      split_unselected_feat: bool = False,
      tree_params: Dict[str, Any] = None,
  ):
      """
      This Discretiser Method uses Decision Trees to predict the target.
      The cutting points on the the Decision Tree becomes the chosen discretisation thresholds
  
      If the target is a continuous variable, we fit a `DecisionTreeRegressor` to discretise the data.
      Otherwise, we fit a Classifier.
  
      Args:
          max_depth (int): maximum depth of the decision tree.
          mode (str): Either 'single' or 'multi'.
          - if single, Train a univariate decision tree for each continuous variable being discretised.
              The splitting points of the decision tree become discretiser fixed points
          - if multi, Train a decision tree over all the variables passed.
              The splitting points of each variable used in the Decision tree become the thresholds for discretisation
          split_unselected_feat (bool): only applicable if self.mode = 'multi'.
          - if True, features not selected by the decision tree will be discretised using 'single' mode
          with the same tree parameters
          - if False, features not selected by the decision tree will be left unchanged
          tree_params: keyword arguments, which are parameters
          used for `sklearn.tree.DecisionTreeClassifier`/`sklearn.tree.DecisionTreeRegressor`
      Raises:
          KeyError: if an incorrect argument is passed
      """
  
      super().__init__()
      tree_params = tree_params or {"max_depth": 2}
      self.tree_params = tree_params
      self.feat_names = None
      self.map_thresholds = {}
      if mode not in ["single", "multi"]:
          raise KeyError(
              f"mode, `{mode}` is not valid, please choose in ['single', 'multi']"
          )
      self.mode = mode
      self.split_unselected_feat = split_unselected_feat
  
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 1 to create a new DecisionTreeSupervisedDiscretiserMethod object from inherited base classes: AbstractSupervisedDiscretiserMethod with example: obj = DecisionTreeSupervisedDiscretiserMethod(mode, split_unselected_feat, tree_params)