py-why / EconML

ALICE (Automated Learning and Intelligence for Causation and Economics) is a Microsoft Research project aimed at applying Artificial Intelligence concepts to economic decision making. One of its goals is to build a toolkit that combines state-of-the-art machine learning techniques with econometrics in order to bring automation to complex causal inference problems. To date, the ALICE Python SDK (econml) implements orthogonal machine learning algorithms such as the double machine learning work of Chernozhukov et al. This toolkit is designed to measure the causal effect of some treatment variable(s) t on an outcome variable y, controlling for a set of features x.
https://www.microsoft.com/en-us/research/project/alice/
Other
3.84k stars 717 forks source link

Objective did not converge. You might want to increase the number of iterations. Duality gap: 0.0, tolerance: 0.0 #417

Open federiconuta opened 3 years ago

federiconuta commented 3 years ago

The error on the title appears when I fit the following model:

est = SparseLinearDML(model_y= ElasticNetCV(cv=[(fold00, fold11), (fold11, fold00)],fit_intercept=False,max_iter=10000,n_alphas = 500), 
                                       model_t= MultiTaskElasticNetCV(cv=[(fold00, fold11), (fold11, fold00)],max_iter=10000,n_alphas = 500),
                                       n_splits = [(fold0, fold1), (fold1, fold0)],
                                       linear_first_stages=False,
                                       max_iter=10000)

I actually increased a lot the number of iterations so I don't know what's wrong. Can you please help me figuring out this?

Thank you

kbattocchi commented 3 years ago

Could you provide a full stack trace? Is the warning definitely arising from the fitting of SparseLinearDML's final model, or could it be from fitting one of the first-stage models? That warning is generated by sklearn when the gap remains above the tolerance, but in this case they both round down to 0.0 so it's hard to know how far from convergence you are, but it may not really be a problem at all.

As an aside, if both of your first stage models are using variations of ElasticNet then linear_first_stages should ideally be set to true so for correctness.

federiconuta commented 3 years ago

@kbattocchi

Could you provide a full stack trace? Is the warning definitely arising from the fitting of SparseLinearDML's final model, or could it be from fitting one of the first-stage models?

Actually I moved from SparseLinearDML to LinearDML with auto inference and the problem does not arise. Apparently the problem with SparseLinearDML arises when inputting the X value of dummies which I constructed as follows:

for g in np.arange(n_groups):
            for i in np.arange(n_products_per_group):
                for j in np.arange(n_months):
                    index_i = n_products_per_group*g + i
                    minus_i = (np.arange(n_products) >= (n_products_per_group*g))
                    minus_i &= (np.arange(n_products) < (n_products_per_group*(g+1)))
                    minus_i &= (np.arange(n_products) != (index_i))
                    p_minus[index_i, j] = np.mean(p[minus_i, j])
                    X[index_i, j, :(n_products)] = 1.0 * (np.arange(0, n_products) == (index_i))
                    X[index_i, j, (n_products):(n_products + n_groups - 1)] =  1.0 * (np.arange(1, n_groups) == g)
                    X[index_i, j, (n_products + n_groups - 1):] = 1.0 * (np.arange(1, n_months) == j) 

Consider that I then fit only a portion of X:

est.fit(Y, T=T, X=X[:, :(n_products)], W=W, inference='auto')

which consists of a series of dummy for each period. The problem of Objective not converge does not arise if I do not employ such X. I also tries with fit_cate_intercept=False and linear_first_stages=False or increasing both the number of alphas and tolerance. Actually I cannot change my X. Do you think that using LinearDML would affect the results considering that I am including time dummies and individual dummies?

Thank you!