class_docstr: A Causal Tree regressor class.
  The Causal Tree is a decision tree regressor with a split criteria for treatment effects.
  Details are available at Athey and Imbens (2015) (https://arxiv.org/abs/1504.01132)
class_docstr_tok: ["A","Causal","Tree","regressor","class",".","The","Causal","Tree","is","a","decision","tree","regressor","with","a","split","criteria","for","treatment","effects",".","Details","are","available","at","Athey","and","Imbens","(","2015",")","(","https",":","\/\/arxiv.org\/abs\/1504.01132",")"]
docstr: Initialize a Causal Tree
  Args:
      criterion: ({"causal_mse", "standard_mse"}, default="causal_mse")
          The function to measure the quality of a split.
      splitter: ({"best", "random"}, default="best")
          The strategy used to choose the split at each node. Supported
          strategies are "best" to choose the best split and "random" to choose
          the best random split.
      alpha: (float): the confidence level alpha of the ATE estimate and ITE bootstrap estimates
      control_name: (str or int): name of control group
      max_depth: (int, default=None)
          The maximum depth of the tree. If None, then nodes are expanded until
          all leaves are pure or until all leaves contain less than
          min_samples_split samples.
      min_samples_split: (int or float, default=2)
          The minimum number of samples required to split an internal node:
          - If int, then consider `min_samples_split` as the minimum number.
          - If float, then `min_samples_split` is a fraction and
            `ceil(min_samples_split * n_samples)` are the minimum
            number of samples for each split.
      min_weight_fraction_leaf: (float, default=0.0)
          The minimum weighted fraction of the sum total of weights (of all
          the input samples) required to be at a leaf node. Samples have
          equal weight when sample_weight is not provided.
      max_features: (int, float or {"auto", "sqrt", "log2"}, default=None)
          The number of features to consider when looking for the best split:
  
          - If int, then consider `max_features` features at each split.
          - If float, then `max_features` is a fraction and
            `int(max_features * n_features)` features are considered at each
            split.
          - If "auto", then `max_features=n_features`.
          - If "sqrt", then `max_features=sqrt(n_features)`.
          - If "log2", then `max_features=log2(n_features)`.
          - If None, then `max_features=n_features`.
      max_leaf_nodes: (int, default=None)
          Grow a tree with ``max_leaf_nodes`` in best-first fashion.
          Best nodes are defined as relative reduction in impurity.
          If None then unlimited number of leaf nodes.
      min_impurity_decrease: (float, default=float("-inf")))
          A node will be split if this split induces a decrease of the impurity
          greater than or equal to this value.
      ccp_alpha: (non-negative float, default=0.0)
          Complexity parameter used for Minimal Cost-Complexity Pruning. The
          subtree with the largest cost complexity that is smaller than
          ``ccp_alpha`` will be chosen. By default, no pruning is performed. See
          :ref:`minimal_cost_complexity_pruning` for details.
      groups_penalty: (float, default=0.5)
          This penalty coefficient manages the node impurity increase in case of the difference between
          treatment and control samples sizes.
      min_samples_leaf: (int or float), default=100
          The minimum number of samples required to be at a leaf node.
          A split point at any depth will only be considered if it leaves at
          least ``min_samples_leaf`` training samples in each of the left and
          right branches.  This may have the effect of smoothing the model,
          especially in regression.
  
          - If int, then consider `min_samples_leaf` as the minimum number.
          - If float, then `min_samples_leaf` is a fraction and
            `ceil(min_samples_leaf * n_samples)` are the minimum
            number of samples for each node.
      random_state: (int), RandomState instance or None, default=None
          Used to pick randomly the `max_features` used at each split.
          See :term:`Glossary <random_state>` for details.
      groups_cnt: (bool), count treatment and control groups for each node/leaf
      groups_cnt_mode: (str, 'nodes', 'leaves'), mode for samples counting
docstr_tok: ["Initialize","a","Causal","Tree","Args",":","criterion",":","(","{","``","causal_mse","''",",","``","standard_mse","''","}",",","default=","''","causal_mse","''",")","The","function","to","measure","the","quality","of","a","split",".","splitter",":","(","{","``","best","''",",","``","random","''","}",",","default=","''","best","''",")","The","strategy","used","to","choose","the","split","at","each","node",".","Supported","strategies","are","``","best","''","to","choose","the","best","split","and","``","random","''","to","choose","the","best","random","split",".","alpha",":","(","float",")",":","the","confidence","level","alpha","of","the","ATE","estimate","and","ITE","bootstrap","estimates","control_name",":","(","str","or","int",")",":","name","of","control","group","max_depth",":","(","int",",","default=None",")","The","maximum","depth","of","the","tree",".","If","None",",","then","nodes","are","expanded","until","all","leaves","are","pure","or","until","all","leaves","contain","less","than","min_samples_split","samples",".","min_samples_split",":","(","int","or","float",",","default=2",")","The","minimum","number","of","samples","required","to","split","an","internal","node",":","-","If","int",",","then","consider","`","min_samples_split","`","as","the","minimum","number",".","-","If","float",",","then","`","min_samples_split","`","is","a","fraction","and","`","ceil","(","min_samples_split","*","n_samples",")","`","are","the","minimum","number","of","samples","for","each","split",".","min_weight_fraction_leaf",":","(","float",",","default=0.0",")","The","minimum","weighted","fraction","of","the","sum","total","of","weights","(","of","all","the","input","samples",")","required","to","be","at","a","leaf","node",".","Samples","have","equal","weight","when","sample_weight","is","not","provided",".","max_features",":","(","int",",","float","or","{","``","auto","''",",","``","sqrt","''",",","``","log2","''","}",",","default=None",")","The","number","of","features","to","consider","when","looking","for","the","best","split",":","-","If","int",",","then","consider","`","max_features","`","features","at","each","split",".","-","If","float",",","then","`","max_features","`","is","a","fraction","and","`","int","(","max_features","*","n_features",")","`","features","are","considered","at","each","split",".","-","If","``","auto","''",",","then","`","max_features=n_features","`",".","-","If","``","sqrt","''",",","then","`","max_features=sqrt","(","n_features",")","`",".","-","If","``","log2","''",",","then","`","max_features=log2","(","n_features",")","`",".","-","If","None",",","then","`","max_features=n_features","`",".","max_leaf_nodes",":","(","int",",","default=None",")","Grow","a","tree","with","``","max_leaf_nodes","``","in","best-first","fashion",".","Best","nodes","are","defined","as","relative","reduction","in","impurity",".","If","None","then","unlimited","number","of","leaf","nodes",".","min_impurity_decrease",":","(","float",",","default=float","(","``","-inf","''",")",")",")","A","node","will","be","split","if","this","split","induces","a","decrease","of","the","impurity","greater","than","or","equal","to","this","value",".","ccp_alpha",":","(","non-negative","float",",","default=0.0",")","Complexity","parameter","used","for","Minimal","Cost-Complexity","Pruning",".","The","subtree","with","the","largest","cost","complexity","that","is","smaller","than","``","ccp_alpha","``","will","be","chosen",".","By","default",",","no","pruning","is","performed",".","See",":","ref",":","`","minimal_cost_complexity_pruning","`","for","details",".","groups_penalty",":","(","float",",","default=0.5",")","This","penalty","coefficient","manages","the","node","impurity","increase","in","case","of","the","difference","between","treatment","and","control","samples","sizes",".","min_samples_leaf",":","(","int","or","float",")",",","default=100","The","minimum","number","of","samples","required","to","be","at","a","leaf","node",".","A","split","point","at","any","depth","will","only","be","considered","if","it","leaves","at","least","``","min_samples_leaf","``","training","samples","in","each","of","the","left","and","right","branches",".","This","may","have","the","effect","of","smoothing","the","model",",","especially","in","regression",".","-","If","int",",","then","consider","`","min_samples_leaf","`","as","the","minimum","number",".","-","If","float",",","then","`","min_samples_leaf","`","is","a","fraction","and","`","ceil","(","min_samples_leaf","*","n_samples",")","`","are","the","minimum","number","of","samples","for","each","node",".","random_state",":","(","int",")",",","RandomState","instance","or","None",",","default=None","Used","to","pick","randomly","the","`","max_features","`","used","at","each","split",".","See",":","term",":","`","Glossary","<","random_state",">","`","for","details",".","groups_cnt",":","(","bool",")",",","count","treatment","and","control","groups","for","each","node\/leaf","groups_cnt_mode",":","(","str",",","'nodes","'",",","'leaves","'",")",",","mode","for","samples","counting"]
code: def __init__(
      self,
      *,
      criterion: str = "causal_mse",
      splitter: str = "best",
      alpha: float = 0.05,
      control_name: Union[int, str] = 0,
      max_depth: int = None,
      min_samples_split: Union[int, float] = 60,
      min_weight_fraction_leaf: float = 0.0,
      max_features: Union[int, float, str] = None,
      max_leaf_nodes: int = None,
      min_impurity_decrease: float = float("-inf"),
      ccp_alpha: float = 0.0,
      groups_penalty: float = 0.5,
      min_samples_leaf: int = 100,
      random_state: int = None,
      groups_cnt: bool = False,
      groups_cnt_mode: str = "nodes",
  ):
      """
      Initialize a Causal Tree
      Args:
          criterion: ({"causal_mse", "standard_mse"}, default="causal_mse")
              The function to measure the quality of a split.
          splitter: ({"best", "random"}, default="best")
              The strategy used to choose the split at each node. Supported
              strategies are "best" to choose the best split and "random" to choose
              the best random split.
          alpha: (float): the confidence level alpha of the ATE estimate and ITE bootstrap estimates
          control_name: (str or int): name of control group
          max_depth: (int, default=None)
              The maximum depth of the tree. If None, then nodes are expanded until
              all leaves are pure or until all leaves contain less than
              min_samples_split samples.
          min_samples_split: (int or float, default=2)
              The minimum number of samples required to split an internal node:
              - If int, then consider `min_samples_split` as the minimum number.
              - If float, then `min_samples_split` is a fraction and
                `ceil(min_samples_split * n_samples)` are the minimum
                number of samples for each split.
          min_weight_fraction_leaf: (float, default=0.0)
              The minimum weighted fraction of the sum total of weights (of all
              the input samples) required to be at a leaf node. Samples have
              equal weight when sample_weight is not provided.
          max_features: (int, float or {"auto", "sqrt", "log2"}, default=None)
              The number of features to consider when looking for the best split:
  
              - If int, then consider `max_features` features at each split.
              - If float, then `max_features` is a fraction and
                `int(max_features * n_features)` features are considered at each
                split.
              - If "auto", then `max_features=n_features`.
              - If "sqrt", then `max_features=sqrt(n_features)`.
              - If "log2", then `max_features=log2(n_features)`.
              - If None, then `max_features=n_features`.
          max_leaf_nodes: (int, default=None)
              Grow a tree with ``max_leaf_nodes`` in best-first fashion.
              Best nodes are defined as relative reduction in impurity.
              If None then unlimited number of leaf nodes.
          min_impurity_decrease: (float, default=float("-inf")))
              A node will be split if this split induces a decrease of the impurity
              greater than or equal to this value.
          ccp_alpha: (non-negative float, default=0.0)
              Complexity parameter used for Minimal Cost-Complexity Pruning. The
              subtree with the largest cost complexity that is smaller than
              ``ccp_alpha`` will be chosen. By default, no pruning is performed. See
              :ref:`minimal_cost_complexity_pruning` for details.
          groups_penalty: (float, default=0.5)
              This penalty coefficient manages the node impurity increase in case of the difference between
              treatment and control samples sizes.
          min_samples_leaf: (int or float), default=100
              The minimum number of samples required to be at a leaf node.
              A split point at any depth will only be considered if it leaves at
              least ``min_samples_leaf`` training samples in each of the left and
              right branches.  This may have the effect of smoothing the model,
              especially in regression.
  
              - If int, then consider `min_samples_leaf` as the minimum number.
              - If float, then `min_samples_leaf` is a fraction and
                `ceil(min_samples_leaf * n_samples)` are the minimum
                number of samples for each node.
          random_state: (int), RandomState instance or None, default=None
              Used to pick randomly the `max_features` used at each split.
              See :term:`Glossary <random_state>` for details.
          groups_cnt: (bool), count treatment and control groups for each node/leaf
          groups_cnt_mode: (str, 'nodes', 'leaves'), mode for samples counting
      """
  
      self.criterion = criterion
      self.splitter = splitter
      self.alpha = alpha
      self.control_name = control_name
      self.max_depth = max_depth
      self.min_samples_split = min_samples_split
      self.min_weight_fraction_leaf = min_weight_fraction_leaf
      self.max_features = max_features
      self.max_leaf_nodes = max_leaf_nodes
      self.min_impurity_decrease = min_impurity_decrease
      self.ccp_alpha = ccp_alpha
      self.groups_penalty = groups_penalty
      self.min_samples_leaf = min_samples_leaf
      self.random_state = random_state
  
      self.eps = 1e-5
      self._classes = {}
      self.groups_cnt = groups_cnt
      self.groups_cnt_mode = groups_cnt_mode
      self._with_outcomes = False
      self._groups_cnt = {}
  
      super().__init__(
          criterion=criterion,
          splitter=splitter,
          max_depth=max_depth,
          min_samples_split=min_samples_split,
          min_weight_fraction_leaf=min_weight_fraction_leaf,
          max_features=max_features,
          max_leaf_nodes=max_leaf_nodes,
          min_impurity_decrease=min_impurity_decrease,
          ccp_alpha=ccp_alpha,
          min_samples_leaf=min_samples_leaf,
          random_state=random_state,
      )
  
imports: import logging
  import sys
  from typing import Union
  import tqdm
  import numpy
  from numpy import float32
  from pathos.pools import ProcessPool
  from scipy.stats import norm
  from sklearn.base import RegressorMixin
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from causalml.inference.meta.utils import check_treatment_vector
  from ._tree import BaseCausalDecisionTree
  from ..utils import get_tree_leaves_mask, timeit
label_desc: Use image node_id 1 to create a new CausalTreeRegressor object from inherited base classes: RegressorMixin, BaseCausalDecisionTree with example: obj = CausalTreeRegressor()