class_docstr: Manager for generating causal analyses from a dataset.
class_docstr_tok: ["Manager","for","generating","causal","analyses","from","a","dataset","."]
docstr: Compute causal insights.
  :param treatment_features: Treatment feature names.
  :type treatment_features: list
  :param heterogeneity_features: Features that mediate the causal effect.
  :type heterogeneity_features: list
  :param nuisance_model: This model used to estimate the outcome and the
      treatment features from the other features present in user data.
      It is one of {'linear', 'automl'}, optional (default='linear').
      If 'linear', then LassoCV (for regression) and
      LogisticRegressionCV (for classification) are used.
      If 'automl', then a k-fold cross-validation and model selection
      is performed among several models and the best is chosen.
  :type nuisance_model: str
  :param heterogeneity_model: The heterogeneity model is used to
      estimate the treatment effect based on the heterogeneity features.
      It is one of {'linear', 'forest'} (default='linear').
      'linear' means that a heterogeneity model of the form
      theta(X)=<a, X> will be used, while 'forest' means that a
      forest model will be trained instead.
  :type heterogeneity_model: str
  :param alpha: Confidence level of confidence intervals.
  :type alpha: float
  :param upper_bound_on_cat_expansion: Maximum expansion for
                                       categorical features.
  :type upper_bound_on_cat_expansion: int
  :param treatment_cost: Cost of treatment. If 0, all treatments will
      have zero cost. If a list is passed, then each element will be
      applied to each treatment feature. Each element can be a scalar
      value to indicate a constant cost of applying that treatment or
      an array indicating the cost for each sample. If the treatment
      is a discrete treatment, then the array for that feature should
      be two dimensional with the first dimension representing samples
      and the second representing the difference in cost between the
      non-default values and the default value.
  :type treatment_cost: None, List of float or array
  :param min_tree_leaf_samples: Minimum number of samples per leaf
      in policy tree.
  :type min_tree_leaf_samples: int
  :param max_tree_depth: Maximum depth of policy tree.
  :type max_tree_depth: int
  :param skip_cat_limit_checks:
      By default, categorical features need to have several instances
      of each category in order for a model to be fit robustly.
      Setting this to True will skip these checks.
  :type skip_cat_limit_checks: bool
  :param categories: 'auto' or list of category values, default 'auto'
      What categories to use for the categorical columns.
      If 'auto', then the categories will be inferred for all
      categorical columns. Otherwise, this argument should have
      as many entries as there are categorical columns.
      Each entry should be either 'auto' to infer the values for
      that column or the list of values for the column.
      If explicit values are provided, the first value is treated
      as the "control" value for that column against which other
      values are compared.
  :type categories: str or list
  :param n_jobs: Degree of parallelism to use when training models
      via joblib.Parallel
  :type n_jobs: int
  :param verbose: Controls the verbosity when fitting and predicting.
  :type verbose: int
  :param random_state: Controls the randomness of the estimator.
  :type random_state: int or RandomState or None
docstr_tok: ["Compute","causal","insights",".",":","param","treatment_features",":","Treatment","feature","names",".",":","type","treatment_features",":","list",":","param","heterogeneity_features",":","Features","that","mediate","the","causal","effect",".",":","type","heterogeneity_features",":","list",":","param","nuisance_model",":","This","model","used","to","estimate","the","outcome","and","the","treatment","features","from","the","other","features","present","in","user","data",".","It","is","one","of","{","'linear","'",",","'automl","'","}",",","optional","(","default='linear","'",")",".","If","'linear","'",",","then","LassoCV","(","for","regression",")","and","LogisticRegressionCV","(","for","classification",")","are","used",".","If","'automl","'",",","then","a","k-fold","cross-validation","and","model","selection","is","performed","among","several","models","and","the","best","is","chosen",".",":","type","nuisance_model",":","str",":","param","heterogeneity_model",":","The","heterogeneity","model","is","used","to","estimate","the","treatment","effect","based","on","the","heterogeneity","features",".","It","is","one","of","{","'linear","'",",","'forest","'","}","(","default='linear","'",")",".","'linear","'","means","that","a","heterogeneity","model","of","the","form","theta","(","X",")","=","<","a",",","X",">","will","be","used",",","while","'forest","'","means","that","a","forest","model","will","be","trained","instead",".",":","type","heterogeneity_model",":","str",":","param","alpha",":","Confidence","level","of","confidence","intervals",".",":","type","alpha",":","float",":","param","upper_bound_on_cat_expansion",":","Maximum","expansion","for","categorical","features",".",":","type","upper_bound_on_cat_expansion",":","int",":","param","treatment_cost",":","Cost","of","treatment",".","If","0",",","all","treatments","will","have","zero","cost",".","If","a","list","is","passed",",","then","each","element","will","be","applied","to","each","treatment","feature",".","Each","element","can","be","a","scalar","value","to","indicate","a","constant","cost","of","applying","that","treatment","or","an","array","indicating","the","cost","for","each","sample",".","If","the","treatment","is","a","discrete","treatment",",","then","the","array","for","that","feature","should","be","two","dimensional","with","the","first","dimension","representing","samples","and","the","second","representing","the","difference","in","cost","between","the","non-default","values","and","the","default","value",".",":","type","treatment_cost",":","None",",","List","of","float","or","array",":","param","min_tree_leaf_samples",":","Minimum","number","of","samples","per","leaf","in","policy","tree",".",":","type","min_tree_leaf_samples",":","int",":","param","max_tree_depth",":","Maximum","depth","of","policy","tree",".",":","type","max_tree_depth",":","int",":","param","skip_cat_limit_checks",":","By","default",",","categorical","features","need","to","have","several","instances","of","each","category","in","order","for","a","model","to","be","fit","robustly",".","Setting","this","to","True","will","skip","these","checks",".",":","type","skip_cat_limit_checks",":","bool",":","param","categories",":","'auto","'","or","list","of","category","values",",","default","'auto'","What","categories","to","use","for","the","categorical","columns",".","If","'auto","'",",","then","the","categories","will","be","inferred","for","all","categorical","columns",".","Otherwise",",","this","argument","should","have","as","many","entries","as","there","are","categorical","columns",".","Each","entry","should","be","either","'auto","'","to","infer","the","values","for","that","column","or","the","list","of","values","for","the","column",".","If","explicit","values","are","provided",",","the","first","value","is","treated","as","the","``","control","''","value","for","that","column","against","which","other","values","are","compared",".",":","type","categories",":","str","or","list",":","param","n_jobs",":","Degree","of","parallelism","to","use","when","training","models","via","joblib.Parallel",":","type","n_jobs",":","int",":","param","verbose",":","Controls","the","verbosity","when","fitting","and","predicting",".",":","type","verbose",":","int",":","param","random_state",":","Controls","the","randomness","of","the","estimator",".",":","type","random_state",":","int","or","RandomState","or","None"]
code: def add(
      self,
      treatment_features: List[str],
      heterogeneity_features: Optional[List[str]] = None,
      nuisance_model: str = ModelTypes.LINEAR,
      heterogeneity_model: str = ModelTypes.LINEAR,
      alpha: float = DefaultParams.DEFAULT_ALPHA,
      upper_bound_on_cat_expansion: int = (
          DefaultParams.DEFAULT_MAX_CAT_EXPANSION
      ),
      treatment_cost: Union[float, List[Union[float, np.ndarray]]] = (
          DefaultParams.DEFAULT_TREATMENT_COST
      ),
      min_tree_leaf_samples: int = (
          DefaultParams.DEFAULT_MIN_TREE_LEAF_SAMPLES
      ),
      max_tree_depth: int = (DefaultParams.DEFAULT_MAX_TREE_DEPTH),
      skip_cat_limit_checks: bool = (
          DefaultParams.DEFAULT_SKIP_CAT_LIMIT_CHECKS
      ),
      categories: Union[str, List[Union[str, List[Any]]]] = (
          DefaultParams.DEFAULT_CATEGORIES
      ),
      n_jobs: int = (DefaultParams.DEFAULT_N_JOBS),
      verbose: int = (DefaultParams.DEFAULT_VERBOSE),
      random_state: Optional[Union[int, np.random.RandomState]] = (
          DefaultParams.DEFAULT_RANDOM_STATE
      ),
  ):
      """Compute causal insights.
      :param treatment_features: Treatment feature names.
      :type treatment_features: list
      :param heterogeneity_features: Features that mediate the causal effect.
      :type heterogeneity_features: list
      :param nuisance_model: This model used to estimate the outcome and the
          treatment features from the other features present in user data.
          It is one of {'linear', 'automl'}, optional (default='linear').
          If 'linear', then LassoCV (for regression) and
          LogisticRegressionCV (for classification) are used.
          If 'automl', then a k-fold cross-validation and model selection
          is performed among several models and the best is chosen.
      :type nuisance_model: str
      :param heterogeneity_model: The heterogeneity model is used to
          estimate the treatment effect based on the heterogeneity features.
          It is one of {'linear', 'forest'} (default='linear').
          'linear' means that a heterogeneity model of the form
          theta(X)=<a, X> will be used, while 'forest' means that a
          forest model will be trained instead.
      :type heterogeneity_model: str
      :param alpha: Confidence level of confidence intervals.
      :type alpha: float
      :param upper_bound_on_cat_expansion: Maximum expansion for
                                           categorical features.
      :type upper_bound_on_cat_expansion: int
      :param treatment_cost: Cost of treatment. If 0, all treatments will
          have zero cost. If a list is passed, then each element will be
          applied to each treatment feature. Each element can be a scalar
          value to indicate a constant cost of applying that treatment or
          an array indicating the cost for each sample. If the treatment
          is a discrete treatment, then the array for that feature should
          be two dimensional with the first dimension representing samples
          and the second representing the difference in cost between the
          non-default values and the default value.
      :type treatment_cost: None, List of float or array
      :param min_tree_leaf_samples: Minimum number of samples per leaf
          in policy tree.
      :type min_tree_leaf_samples: int
      :param max_tree_depth: Maximum depth of policy tree.
      :type max_tree_depth: int
      :param skip_cat_limit_checks:
          By default, categorical features need to have several instances
          of each category in order for a model to be fit robustly.
          Setting this to True will skip these checks.
      :type skip_cat_limit_checks: bool
      :param categories: 'auto' or list of category values, default 'auto'
          What categories to use for the categorical columns.
          If 'auto', then the categories will be inferred for all
          categorical columns. Otherwise, this argument should have
          as many entries as there are categorical columns.
          Each entry should be either 'auto' to infer the values for
          that column or the list of values for the column.
          If explicit values are provided, the first value is treated
          as the "control" value for that column against which other
          values are compared.
      :type categories: str or list
      :param n_jobs: Degree of parallelism to use when training models
          via joblib.Parallel
      :type n_jobs: int
      :param verbose: Controls the verbosity when fitting and predicting.
      :type verbose: int
      :param random_state: Controls the randomness of the estimator.
      :type random_state: int or RandomState or None
      """
      if any(_find_features_having_missing_values(self._train)):
          raise UserConfigValidationException(
              "Missing values are not allowed in "
              "the train dataset while computing causal effects."
          )
      if any(_find_features_having_missing_values(self._test)):
          raise UserConfigValidationException(
              "Missing values are not allowed in "
              "the test dataset while computing causal effects."
          )
      if not isinstance(treatment_features, list):
          raise UserConfigValidationException(
              "Expecting a list for treatment_features but got {0}".format(
                  type(treatment_features)
              )
          )
      if len(treatment_features) == 0:
          raise UserConfigValidationException(
              "Please specify at least one feature in "
              "treatment_features list"
          )
      for feature in treatment_features:
          if (
              self._feature_metadata
              and self._feature_metadata.dropped_features
              and feature
              in set(self._feature_metadata.dropped_features)
          ):
              message = (
                  "'{}' in treatment_features has been dropped "
                  "during training the model"
              ).format(feature)
              raise UserConfigValidationException(message)
      difference_set = set(treatment_features) - set(
          self._train.columns
      )
      if len(difference_set) > 0:
          message = (
              "Feature names in treatment_features do "
              f"not exist in train data: {list(difference_set)}"
          )
          raise UserConfigValidationException(message)
  
      if heterogeneity_features is not None:
          difference_set = set(heterogeneity_features) - set(
              self._train.columns
          )
          if len(difference_set) > 0:
              message = (
                  "Feature names in heterogeneity_features do "
                  f"not exist in train data: {list(difference_set)}"
              )
              raise UserConfigValidationException(message)
  
      if self._task_type == ModelTask.CLASSIFICATION:
          is_multiclass = (
              len(
                  np.unique(
                      self._train[self._target_column].values
                  ).tolist()
              )
              > 2
          )
          if is_multiclass:
              raise UserConfigValidationException(
                  "Multiclass classification isn't supported"
              )
  
      if nuisance_model not in [ModelTypes.AUTOML, ModelTypes.LINEAR]:
          message = (
              f"nuisance_model should be one of "
              f"['{ModelTypes.AUTOML}', "
              f"'{ModelTypes.LINEAR}'], "
              f"got {nuisance_model}"
          )
          raise UserConfigValidationException(message)
  
      if heterogeneity_model not in [
          ModelTypes.FOREST,
          ModelTypes.LINEAR,
      ]:
          message = (
              f"heterogeneity_model should be one of "
              f"['{ModelTypes.FOREST}', "
              f"'{ModelTypes.LINEAR}'], "
              f"got {heterogeneity_model}"
          )
          raise UserConfigValidationException(message)
  
      # Check treatment_cost is valid
      if isinstance(treatment_cost, int) and treatment_cost == 0:
          revised_treatment_cost = [0] * len(treatment_features)
      else:
          revised_treatment_cost = treatment_cost
  
      if not isinstance(revised_treatment_cost, list):
          message = (
              "treatment_cost must be a list with "
              "the same number of elements as "
              "treatment_features where each element "
              "is either a constant cost of treatment "
              "or an array specifying the cost of "
              "treatment per sample. "
              "Found treatment_cost of type "
              f"{type(revised_treatment_cost)}, expected list."
          )
          raise UserConfigValidationException(message)
      elif len(revised_treatment_cost) != len(treatment_features):
          message = (
              "treatment_cost must be a list with "
              "the same number of elements as "
              "treatment_features. "
              "Length of treatment_cost was "
              f"{len(revised_treatment_cost)}, expected "
              f"{len(treatment_features)}."
          )
          raise UserConfigValidationException(message)
  
      validate_train_test_categories(
          train_data=self._train,
          test_data=self._test,
          rai_compute_type="Causal analysis",
          categoricals=self._categorical_features,
      )
  
      result = CausalResult()
      result.config = CausalConfig(
          treatment_features=treatment_features,
          heterogeneity_features=heterogeneity_features,
          nuisance_model=nuisance_model,
          heterogeneity_model=heterogeneity_model,
          alpha=alpha,
          upper_bound_on_cat_expansion=upper_bound_on_cat_expansion,
          treatment_cost=revised_treatment_cost,
          min_tree_leaf_samples=min_tree_leaf_samples,
          max_tree_depth=max_tree_depth,
          skip_cat_limit_checks=skip_cat_limit_checks,
          n_jobs=n_jobs,
          categories=categories,
          verbose=verbose,
          random_state=random_state,
          categorical_features=self._categorical_features,
      )
      self._results.append(result)
  
imports: from pathlib import Path
  from typing import Any, List, Optional, Union
  import numpy
  import pandas
  from econml.solutions.causal_analysis import CausalAnalysis
  from raiutils.exceptions import UserConfigValidationException
  from raiutils.models import ModelTask
  from responsibleai._data_validations import validate_train_test_categories
  from responsibleai._internal.constants import CausalManagerKeys, ListProperties, ManagerNames
  from responsibleai._tools.causal.causal_config import CausalConfig
  from responsibleai._tools.causal.causal_constants import DefaultParams, ModelTypes
  from responsibleai._tools.causal.causal_result import CausalResult
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from responsibleai.feature_metadata import FeatureMetadata
  from responsibleai.managers.base_manager import BaseManager
  from responsibleai.utils import _find_features_having_missing_values, _measure_time
label_desc: Use image node_id 2 for calling the CausalManager obj's underlying member method code with example usage: obj.add(treatment_features, heterogeneity_features, nuisance_model, heterogeneity_model, alpha, upper_bound_on_cat_expansion, treatment_cost, min_tree_leaf_samples, max_tree_depth, skip_cat_limit_checks, categories, n_jobs, verbose, random_state) without return types