Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
X_final[:, -d_t:],
X_final[:, :d_x],
X_final[:, d_x:-d_t],
sample_weight=n_sum,
sample_var=var_sum,
inference=StatsModelsInference(cov_type=cov_type))
class Splitter:
def __init__(self):
return
def split(self, X, T):
return [(np.arange(0, first_half), np.arange(first_half, X.shape[0])),
(np.arange(first_half, X.shape[0]), np.arange(0, first_half))]
lr = LinearDMLCateEstimator(model_y=first_stage(),
model_t=first_stage(),
n_splits=Splitter(),
linear_first_stages=False,
discrete_treatment=False)
lr.fit(y, X[:, -d_t:], X[:, :d_x], X[:, d_x:-d_t],
inference=StatsModelsInference(cov_type=cov_type))
for alpha in alpha_list:
key = ("n_{}_n_exp_{}_hetero_{}_d_{}_d_x_"
"{}_p_{}_d_t_{}_cov_type_{}_alpha_{}").format(
n, n_exp, hetero_coef, d, d_x, p, d_t, cov_type, alpha)
_append_coverage(key, coverage_est, est, X_test,
alpha, true_coef, true_effect)
_append_coverage(key, coverage_lr, lr, X_test,
alpha, true_coef, true_effect)
if it == n_exp - 1:
n_tests += 1
# columns: prices interacted with products (and constant), features
results = np.empty((n_weeks * block_size, (1 + n_products) + block_features.shape[1]))
# observe n_products * n_stores prices, same number of quantities
for w in range(n_weeks):
prices = gammas + np.random.normal(size=gammas.shape)
quantities[w * block_size: (w + 1) * block_size] = alphas_tiled * prices + \
betas + np.random.normal(size=betas.size)
results[w * block_size: (w + 1) * block_size, 0:1 + n_products] = prices.reshape((-1, 1)) * \
np.concatenate((np.ones((block_features.shape[0], 1)), block_features[:, :n_products]), axis=1)
results[w * block_size: (w + 1) * block_size, 1 + n_products:] = block_features
lassos.append(LassoCV().fit(results, quantities).coef_[0:n_products + 1])
ridges.append(RidgeCV().fit(results, quantities).coef_[0:n_products + 1])
# use features starting at index 1+n_products to skip all prices
doubleMls.append(econml.dml.LinearDMLCateEstimator(model_final=RidgeCV()).fit(results, quantities).coef_)
alphass.append(alphas)
pickleFile = open('pickledSparse_{0}_{1}_{2}_{3}.pickle'.format(n_exp, n_products, n_stores, n_weeks), 'wb')
pickle.dump((alphass, ridges, lassos, doubleMls), pickleFile)
pickleFile.close()
n_sum = np.concatenate((n_sum_first, n_sum_sec))
var_sum = np.concatenate((var_first, var_sec))
first_half_sum = len(y_sum_first)
first_half = len(y1)
for cov_type in cov_type_list:
class SplitterSum:
def __init__(self):
return
def split(self, X, T):
return [(np.arange(0, first_half_sum),
np.arange(first_half_sum, X.shape[0])),
(np.arange(first_half_sum, X.shape[0]),
np.arange(0, first_half_sum))]
est = LinearDMLCateEstimator(model_y=first_stage(),
model_t=first_stage(),
n_splits=SplitterSum(),
linear_first_stages=False,
discrete_treatment=False)
est.fit(y_sum,
X_final[:, -d_t:],
X_final[:, :d_x],
X_final[:, d_x:-d_t],
sample_weight=n_sum,
sample_var=var_sum,
inference=StatsModelsInference(cov_type=cov_type))
class Splitter:
def __init__(self):
return