econml/ortho_forest.py
def second_stage_parameter_estimator_gen(lambda_reg):
        """
        For the second stage parameter estimation we add a local linear correction. So
        we fit a local linear function as opposed to a local constant function. We also penalize
        the linear part to reduce variance.
        """
        def parameter_estimator_func(Y, T, X,
                                     nuisance_estimates,
                                     sample_weight=None):
            """Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates."""
            # Compute partial moments
            pointwise_params = DiscreteTreatmentOrthoForest._partial_moments(Y, T, nuisance_estimates)
            X_aug = PolynomialFeatures(degree=1, include_bias=True).fit_transform(X)
            # Compute coefficient by OLS on residuals
            if sample_weight is not None:
                weighted_X_aug = sample_weight.reshape(-1, 1) * X_aug
            else:
                weighted_X_aug = X_aug / X_aug.shape[0]
            # ell_2 regularization
            diagonal = np.ones(X_aug.shape[1])
            diagonal[0] = 0
            reg = lambda_reg * np.diag(diagonal)
            # Ridge regression estimate
            param_estimate = np.linalg.lstsq(np.matmul(weighted_X_aug.T, X_aug) + reg,
                                             np.matmul(weighted_X_aug.T, pointwise_params), rcond=None)[0].flatten()
            # Parameter returned by LinearRegression is (d_T, )
            return param_estimate

        return parameter_estimator_func

        For the second stage parameter estimation we add a local linear correction. So
        we fit a local linear function as opposed to a local constant function. We also penalize
        the linear part to reduce variance.
        
For the second stage parameter estimation we add a local linear correction. So
we fit a local linear function as opposed to a local constant function. We also penalize
the linear part to reduce variance.
For the second stage parameter estimation we add a local linear correction . So we fit a local linear function as opposed to a local constant function . We also penalize the linear part to reduce variance .
def second_stage_parameter_estimator_gen(lambda_reg):
        def parameter_estimator_func(Y, T, X,
                                     nuisance_estimates,
                                     sample_weight=None):
            pointwise_params = DiscreteTreatmentOrthoForest._partial_moments(Y, T, nuisance_estimates)
            X_aug = PolynomialFeatures(degree=1, include_bias=True).fit_transform(X)
            if sample_weight is not None:
                weighted_X_aug = sample_weight.reshape(-1, 1) * X_aug
            else:
                weighted_X_aug = X_aug / X_aug.shape[0]
            diagonal = np.ones(X_aug.shape[1])
            diagonal[0] = 0
            reg = lambda_reg * np.diag(diagonal)
            param_estimate = np.linalg.lstsq(np.matmul(weighted_X_aug.T, X_aug) + reg,
                                             np.matmul(weighted_X_aug.T, pointwise_params), rcond=None)[0].flatten()
            return param_estimate
        return parameter_estimator_func
def second_stage_parameter_estimator_gen ( lambda_reg ) : def parameter_estimator_func ( Y , T , X , nuisance_estimates , sample_weight = None ) : """Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.""" pointwise_params = DiscreteTreatmentOrthoForest . _partial_moments ( Y , T , nuisance_estimates ) X_aug = PolynomialFeatures ( degree = 1 , include_bias = True ) . fit_transform ( X ) if sample_weight is not None : weighted_X_aug = sample_weight . reshape ( - 1 , 1 ) * X_aug else : weighted_X_aug = X_aug / X_aug . shape [ 0 ] diagonal = np . ones ( X_aug . shape [ 1 ] ) diagonal [ 0 ] = 0 reg = lambda_reg * np . diag ( diagonal ) param_estimate = np . linalg . lstsq ( np . matmul ( weighted_X_aug . T , X_aug ) + reg , np . matmul ( weighted_X_aug . T , pointwise_params ) , rcond = None ) [ 0 ] . flatten ( ) return param_estimate return parameter_estimator_func
For the second stage parameter estimation we add a local linear correction.
For the second stage parameter estimation we add a local linear correction .
"""
        For the second stage parameter estimation we add a local linear correction. So
        we fit a local linear function as opposed to a local constant function. We also penalize
        the linear part to reduce variance.
        """ """Calculate the parameter of interest for points given by (Y, T) and corresponding nuisance estimates.""" # Compute partial moments # Compute coefficient by OLS on residuals # ell_2 regularization # Ridge regression estimate # Parameter returned by LinearRegression is (d_T, )
lambda_reg