nnpiv.ensemble.EnsembleIVL2

class nnpiv.ensemble.EnsembleIVL2(adversary='auto', learner='auto', n_iter=100, delta_scale='auto', delta_exp='auto', CV=False, alpha_scales='auto', n_alphas=30, n_folds=5)[source]

Empirical-L2-regularized ensemble IV estimator.

The effective learner penalty is mu = alpha * delta_n**2, where delta_n = delta_scale / n**delta_exp. Cross-validation evaluates a critic trained on each training-fold residual through the held-out payoff mean(2 * residual * critic - critic**2).

Parameters
  • adversary (str or estimator) – Regression critic. 'auto' uses a shallow RandomForestRegressor.

  • learner (str or estimator) – Regression learner. 'auto' uses a shallow RandomForestRegressor.

  • n_iter (int) – Number of learners to average; must be positive.

  • delta_scale (str or float) – Numerator of delta_n. 'auto' uses 5.

  • delta_exp (str or float) – Sample-size exponent in delta_n. 'auto' uses 0.4.

  • CV (bool) – Whether to select alpha by cross-validation.

  • alpha_scales (str or iterable) – Candidate alpha scales. 'auto' uses a geometric grid.

  • n_alphas (int) – Size of the automatic candidate grid.

  • n_folds (int) – Number of cross-validation folds.

best_alpha_

Selected scale when CV=True.

Type

float

fit(Z, T, Y, alpha=1.0, cross_validating=False)[source]

Fit the empirical-L2-regularized ensemble IV model.

Parameters
  • Z (array-like) – Instrument covariates used by the critic.

  • T (array-like) – Covariates used by the learner function.

  • Y (array-like) – Scalar outcome.

  • alpha (float) – Positive scale in mu = alpha * delta_n**2. Ignored when CV=True on the outer fit.

  • cross_validating (bool) – Internal guard that prevents recursive cross-validation while fitting a fold.

Returns

Fitted ensemble IV model.

Return type

self

predict(T)[source]

Average the fitted regression learners at T.

Parameters

T (array-like) – Treatment variables.

Returns

Predicted outcomes.

Return type

array