class_docstr: Compute effect of treatment using some regression function.
  
  Fits a regression model for estimating the outcome using treatment(s) and
  confounders.
  
  Base class for all regression models, inherited by
  LinearRegressionEstimator and GeneralizedLinearModelEstimator.
class_docstr_tok: ["Compute","effect","of","treatment","using","some","regression","function",".","Fits","a","regression","model","for","estimating","the","outcome","using","treatment","(","s",")","and","confounders",".","Base","class","for","all","regression","models",",","inherited","by","LinearRegressionEstimator","and","GeneralizedLinearModelEstimator","."]
code: def _build_features(
      self, data_df: pd.DataFrame, treatment_values=None
  ):
      treatment_vals = self._encode(
          data_df[self._target_estimand.treatment_variable], "treatment"
      )
  
      if len(self._observed_common_causes_names) > 0:
          observed_common_causes_vals = data_df[
              self._observed_common_causes_names
          ]
          observed_common_causes_vals = self._encode(
              observed_common_causes_vals, "observed_common_causes"
          )
  
      if self._effect_modifier_names:
          effect_modifiers_vals = data_df[self._effect_modifier_names]
          effect_modifiers_vals = self._encode(
              effect_modifiers_vals, "effect_modifiers"
          )
  
      # Fixing treatment value to the specified value, if provided
      if treatment_values is not None:
          treatment_vals = treatment_values
      if type(treatment_vals) is not np.ndarray:
          treatment_vals = treatment_vals.to_numpy()
      # treatment_vals and data_df should have same number of rows
      if treatment_vals.shape[0] != data_df.shape[0]:
          raise ValueError(
              "Provided treatment values and dataframe should have the same length."
          )
  
      # Bulding the feature matrix
      n_treatment_cols = (
          1
          if len(treatment_vals.shape) == 1
          else treatment_vals.shape[1]
      )
      n_samples = treatment_vals.shape[0]
      treatment_2d = treatment_vals.reshape(
          (n_samples, n_treatment_cols)
      )
      if len(self._observed_common_causes_names) > 0:
          features = np.concatenate(
              (treatment_2d, observed_common_causes_vals), axis=1
          )
      else:
          features = treatment_2d
      if self._effect_modifier_names:
          for i in range(treatment_2d.shape[1]):
              curr_treatment = treatment_2d[:, i]
              new_features = (
                  curr_treatment[:, np.newaxis]
                  * effect_modifiers_vals.to_numpy()
              )
              features = np.concatenate(
                  (features, new_features), axis=1
              )
      features = features.astype(
          float, copy=False
      )  # converting to float in case of binary treatment and no other variables
      features = sm.add_constant(
          features, has_constant="add"
      )  # to add an intercept term
      return features
  
file_path: dowhy/dowhy/causal_estimators/regression_estimator.py
imports: from typing import Any, List, Optional, Union
  import numpy
  import pandas
  import statsmodels.api
  from dowhy.causal_estimator import CausalEstimate, CausalEstimator, IdentifiedEstimand
  from dowhy.utils.encoding import one_hot_encode
label_desc: Use image node_id 8 for calling the RegressionEstimator obj's underlying member method code with example usage: obj._build_features(data_df, treatment_values) and returns: features