Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self,
n_trees=500,
min_leaf_size=10, max_depth=10,
subsample_ratio=0.7,
bootstrap=False,
lambda_reg=0.01,
propensity_model=LogisticRegression(penalty='l1', solver='saga',
multi_class='auto'), # saga solver supports l1
model_Y=WeightedLassoCVWrapper(cv=3),
propensity_model_final=None,
model_Y_final=None,
n_jobs=-1,
random_state=None):
# Copy and/or define models
self.propensity_model = clone(propensity_model, safe=False)
self.model_Y = clone(model_Y, safe=False)
self.propensity_model_final = clone(propensity_model_final, safe=False)
self.model_Y_final = clone(model_Y_final, safe=False)
if self.propensity_model_final is None:
self.propensity_model_final = clone(self.propensity_model, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Nuisance estimators shall be defined during fitting because they need to know the number of distinct
# treatments
nuisance_estimator = None
def __init__(self,
n_trees=500,
min_leaf_size=10, max_depth=10,
subsample_ratio=0.7,
bootstrap=False,
lambda_reg=0.01,
model_T=WeightedLassoCVWrapper(cv=3),
model_Y=WeightedLassoCVWrapper(cv=3),
model_T_final=None,
model_Y_final=None,
n_jobs=-1,
random_state=None):
# Copy and/or define models
self.lambda_reg = lambda_reg
self.model_T = model_T
self.model_Y = model_Y
self.model_T_final = model_T_final
self.model_Y_final = model_Y_final
if self.model_T_final is None:
self.model_T_final = clone(self.model_T, safe=False)
if self.model_Y_final is None:
self.model_Y_final = clone(self.model_Y, safe=False)
# Define nuisance estimators
def __init__(self,
model_y, model_t, model_final,
featurizer=None,
fit_cate_intercept=True,
linear_first_stages=False,
discrete_treatment=False,
n_splits=2,
random_state=None):
# TODO: consider whether we need more care around stateful featurizers,
# since we clone it and fit separate copies
if model_t == 'auto':
if discrete_treatment:
model_t = LogisticRegressionCV(cv=WeightedStratifiedKFold())
else:
model_t = WeightedLassoCVWrapper()
self.bias_part_of_coef = fit_cate_intercept
self.fit_cate_intercept = fit_cate_intercept
super().__init__(model_y=_FirstStageWrapper(model_y, True,
featurizer, linear_first_stages, discrete_treatment),
model_t=_FirstStageWrapper(model_t, False,
featurizer, linear_first_stages, discrete_treatment),
model_final=_FinalWrapper(model_final, fit_cate_intercept, featurizer, False),
discrete_treatment=discrete_treatment,
n_splits=n_splits,
random_state=random_state)
def __init__(self,
model_y=WeightedLassoCVWrapper(), model_t='auto',
alpha='auto',
max_iter=1000,
tol=1e-4,
featurizer=None,
fit_cate_intercept=True,
linear_first_stages=True,
discrete_treatment=False,
n_splits=2,
random_state=None):
model_final = MultiOutputDebiasedLasso(
alpha=alpha,
fit_intercept=False,
max_iter=max_iter,
tol=tol)
super().__init__(model_y=model_y,
model_t=model_t,