class_docstr: Class to perform sensitivity analysis for partially linear model.
  
  An efficient version of the non parametric sensitivity analyzer that works for estimators that return residuals of regression from confounders on treatment and outcome, such as the DML method. For all other methods (or when the partially linear assumption is not guaranteed to be satisfied), use the non-parametric sensitivity analysis.
  
  Based on this work:
      Chernozhukov, V., Cinelli, C., Newey, W., Sharma, A., & Syrgkanis, V. (2022). Long Story Short: Omitted Variable Bias in Causal Machine Learning (No. w30302). National Bureau of Economic Research.
  
  :param estimator: estimator of the causal model
  :param num_splits: number of splits for cross validation. (default = 5)
  :param shuffle_data : shuffle data or not before splitting into folds (default = False)
  :param shuffle_random_seed: seed for randomly shuffling data
  :param effect_strength_treatment: C^2_T, list of plausible sensitivity parameters for effect of confounder on treatment
  :param effect_strength_outcome: C^2_Y, list of plausible sensitivity parameters for effect of confounder on outcome
  :param benchmark_common_causes: names of variables for bounding strength of confounders
  :param significance_level: confidence interval for statistical inference(default = 0.05)
  :param frac_strength_treatment: strength of association between unobserved confounder and treatment compared to benchmark covariate
  :param frac_strength_outcome: strength of association between unobserved confounder and outcome compared to benchmark covariate
  :param g_s_estimator_list: list of estimator objects for finding g_s. These objects should have fit() and predict() functions.
  :param g_s_estimator_param_list: list of dictionaries with parameters for tuning respective estimators in "g_s_estimator_list".
  :param alpha_s_estimator_list: list of estimator objects for finding the treatment predictor which is used for alpha_s estimation. These objects should have fit() and predict_proba() functions.
  :param alpha_s_estimator_param_list: list of dictionaries with parameters for tuning respective estimators in "alpha_s_estimator_list".
                                   The order of the dictionaries in the list should be consistent with the estimator objects order in "g_s_estimator_list"
  :param observed_common_causes: common causes dataframe
  :param outcome: outcome dataframe
  :param treatment: treatment dataframe
class_docstr_tok: ["Class","to","perform","sensitivity","analysis","for","partially","linear","model",".","An","efficient","version","of","the","non","parametric","sensitivity","analyzer","that","works","for","estimators","that","return","residuals","of","regression","from","confounders","on","treatment","and","outcome",",","such","as","the","DML","method",".","For","all","other","methods","(","or","when","the","partially","linear","assumption","is","not","guaranteed","to","be","satisfied",")",",","use","the","non-parametric","sensitivity","analysis",".","Based","on","this","work",":","Chernozhukov",",","V.",",","Cinelli",",","C.",",","Newey",",","W.",",","Sharma",",","A.",",","&","Syrgkanis",",","V.","(","2022",")",".","Long","Story","Short",":","Omitted","Variable","Bias","in","Causal","Machine","Learning","(","No",".","w30302",")",".","National","Bureau","of","Economic","Research",".",":","param","estimator",":","estimator","of","the","causal","model",":","param","num_splits",":","number","of","splits","for","cross","validation",".","(","default","=","5",")",":","param","shuffle_data",":","shuffle","data","or","not","before","splitting","into","folds","(","default","=","False",")",":","param","shuffle_random_seed",":","seed","for","randomly","shuffling","data",":","param","effect_strength_treatment",":","C^2_T",",","list","of","plausible","sensitivity","parameters","for","effect","of","confounder","on","treatment",":","param","effect_strength_outcome",":","C^2_Y",",","list","of","plausible","sensitivity","parameters","for","effect","of","confounder","on","outcome",":","param","benchmark_common_causes",":","names","of","variables","for","bounding","strength","of","confounders",":","param","significance_level",":","confidence","interval","for","statistical","inference","(","default","=","0.05",")",":","param","frac_strength_treatment",":","strength","of","association","between","unobserved","confounder","and","treatment","compared","to","benchmark","covariate",":","param","frac_strength_outcome",":","strength","of","association","between","unobserved","confounder","and","outcome","compared","to","benchmark","covariate",":","param","g_s_estimator_list",":","list","of","estimator","objects","for","finding","g_s",".","These","objects","should","have","fit","(",")","and","predict","(",")","functions",".",":","param","g_s_estimator_param_list",":","list","of","dictionaries","with","parameters","for","tuning","respective","estimators","in","``","g_s_estimator_list","''",".",":","param","alpha_s_estimator_list",":","list","of","estimator","objects","for","finding","the","treatment","predictor","which","is","used","for","alpha_s","estimation",".","These","objects","should","have","fit","(",")","and","predict_proba","(",")","functions",".",":","param","alpha_s_estimator_param_list",":","list","of","dictionaries","with","parameters","for","tuning","respective","estimators","in","``","alpha_s_estimator_list","''",".","The","order","of","the","dictionaries","in","the","list","should","be","consistent","with","the","estimator","objects","order","in","``","g_s_estimator_list","''",":","param","observed_common_causes",":","common","causes","dataframe",":","param","outcome",":","outcome","dataframe",":","param","treatment",":","treatment","dataframe"]
docstr: Computes the change in partial R^2 due to presence of unobserved confounders
  :param split_indices: training and testing data indices obtained after cross folding
  :param second_stage_linear: True if second stage regression is linear else False (default = False)
  :param is_partial_linear: True if the data-generating process is assumed to be partially linear
  
  :returns delta_r2_y_wj: observed additive gains in explanatory power with outcome when including benchmark covariate  on regression equation
  :returns delta_r2t_wj: observed additive gains in explanatory power with treatment when including benchmark covariate  on regression equation
docstr_tok: ["Computes","the","change","in","partial","R^2","due","to","presence","of","unobserved","confounders",":","param","split_indices",":","training","and","testing","data","indices","obtained","after","cross","folding",":","param","second_stage_linear",":","True","if","second","stage","regression","is","linear","else","False","(","default","=","False",")",":","param","is_partial_linear",":","True","if","the","data-generating","process","is","assumed","to","be","partially","linear",":","returns","delta_r2_y_wj",":","observed","additive","gains","in","explanatory","power","with","outcome","when","including","benchmark","covariate","on","regression","equation",":","returns","delta_r2t_wj",":","observed","additive","gains","in","explanatory","power","with","treatment","when","including","benchmark","covariate","on","regression","equation"]
code: def compute_r2diff_benchmarking_covariates(
      self,
      treatment_df,
      features,
      T,
      Y,
      W,
      benchmark_common_causes,
      split_indices=None,
      second_stage_linear=False,
      is_partial_linear=True,
  ):
      """
      Computes the change in partial R^2 due to presence of unobserved confounders
      :param split_indices: training and testing data indices obtained after cross folding
      :param second_stage_linear: True if second stage regression is linear else False (default = False)
      :param is_partial_linear: True if the data-generating process is assumed to be partially linear
  
      :returns delta_r2_y_wj: observed additive gains in explanatory power with outcome when including benchmark covariate  on regression equation
      :returns delta_r2t_wj: observed additive gains in explanatory power with treatment when including benchmark covariate  on regression equation
      """
      T = T.ravel()
      Y = Y.ravel()
      num_samples = W.shape[0]
  
      # common causes after removing the benchmark causes
      W_j_df = features.drop(benchmark_common_causes, axis=1)
      numeric_features = get_numeric_features(X=W_j_df)
      W_j = W_j_df.to_numpy()
      # dataframe with treatment and observed common causes after removing benchmark causes
      T_W_j_df = pd.concat([treatment_df, W_j_df], axis=1)
      numeric_features_t = get_numeric_features(X=T_W_j_df)
      T_W_j = T_W_j_df.to_numpy()
  
      # R^2 of treatment with observed common causes removing benchmark causes
      if is_partial_linear:
          r2t_w_j = self.get_regression_r2(
              X=W_j,
              Y=T,
              numeric_features=numeric_features,
              split_indices=split_indices,
          )
          delta_r2t_wj = self.r2t_w - r2t_w_j
      else:  # non parametric DGP
          # return the variance of alpha_s
          var_alpha_wj = self.get_alpharegression_var(
              X=T_W_j,
              numeric_features=numeric_features,  # using numeric_features because the model only uses W
              split_indices=split_indices,
          )
          delta_r2t_wj = var_alpha_wj
  
      reg_function = None
      if second_stage_linear is True:
          reg_function = get_generic_regressor(
              cv=split_indices,
              X=T_W_j,
              Y=Y,
              max_degree=self.reisz_polynomial_max_degree,
              estimator_list=[
                  LinearRegression(),
                  Pipeline(
                      [
                          (
                              "scale",
                              ColumnTransformer(
                                  [
                                      (
                                          "num",
                                          StandardScaler(),
                                          numeric_features,
                                      )
                                  ],
                                  remainder="passthrough",
                              ),
                          ),
                          ("lasso_model", Lasso()),
                      ]
                  ),
                  SGDRegressor(alpha=0.001),
                  Ridge(),
                  RidgeCV(cv=5),
              ],
              estimator_param_list=[
                  {"fit_intercept": [True, False]},
                  {
                      "lasso_model__alpha": [
                          0.01,
                          0.001,
                          1e-4,
                          1e-5,
                          1e-6,
                      ]
                  },
                  {"alpha": [0.0001, 1e-5, 0.01]},
                  {"alpha": [0.0001, 1e-5, 0.01, 1, 2]},
                  {"cv": [2, 3, 4]},
              ],
              numeric_features=numeric_features,
          )  # Regressing over observed common causes removing benchmark causes and treatment
      # R^2 of outcome with observed common causes and treatment after removing benchmark causes
      r2y_tw_j = self.get_regression_r2(
          X=T_W_j,
          Y=Y,
          numeric_features=numeric_features_t,
          split_indices=split_indices,
          regression_model=reg_function,
      )
      delta_r2_y_wj = self.r2y_tw - r2y_tw_j
  
      return delta_r2_y_wj, delta_r2t_wj
  
imports: import logging
  import matplotlib.pyplot
  import numpy
  import pandas
  import scipy
  from sklearn.compose import ColumnTransformer
  from sklearn.linear_model import Lasso, LinearRegression, Ridge, RidgeCV, SGDRegressor
  from sklearn.model_selection import KFold
  from sklearn.pipeline import Pipeline
  from sklearn.preprocessing import StandardScaler
  from dowhy.causal_refuters.reisz import get_generic_regressor
  from dowhy.utils.regression import get_numeric_features
label_desc: Use image node_id 8 for calling the PartialLinearSensitivityAnalyzer obj's underlying member method code with example usage: obj.compute_r2diff_benchmarking_covariates(treatment_df, features, T, Y, W, benchmark_common_causes, split_indices, second_stage_linear, is_partial_linear) and returns: delta_r2_y_wj,  delta_r2t_wj