Skip to content

statspai.compat

compat

Ecosystem compatibility layer.

Provides sklearn-compatible wrappers so that StatsPAI estimators can participate in sklearn.pipeline.Pipeline, cross-validation, GridSearchCV, etc.

from statspai.compat import SklearnOLS, SklearnDID, SklearnDML from sklearn.model_selection import cross_val_score scores = cross_val_score(SklearnOLS(robust='hc1'), X, y, cv=5)

SklearnOLS

Bases: BaseEstimator, RegressorMixin

Sklearn-compatible OLS with robust/clustered standard errors.

Parameters:

Name Type Description Default
robust str

'nonrobust', 'hc0', 'hc1', 'hc2', 'hc3', 'hac'.

'nonrobust'
add_constant bool

If True, prepend a column of ones.

True
Attributes (after fit)

results_ : EconometricResults coef_ : ndarray intercept_ : float

SklearnIV

Bases: BaseEstimator, RegressorMixin

Sklearn-compatible 2SLS / IV estimator.

Parameters:

Name Type Description Default
n_instruments int

Number of columns at the end of X that are instruments (excluded from the second stage).

1
add_constant bool

Prepend constant column.

True
Notes

In fit(X, y) the last n_instruments columns of X are treated as excluded instruments.

SklearnDML

Bases: BaseEstimator, RegressorMixin

Sklearn-compatible Double/Debiased ML wrapper.

Parameters:

Name Type Description Default
n_folds int

Number of cross-fitting folds.

5
model_y object

sklearn estimator for the outcome model.

None
model_t object

sklearn estimator for the treatment model.

None
Notes

fit(X, y) expects the first column of X to be the treatment variable, remaining columns are controls/confounders.

SklearnCausalForest

Bases: BaseEstimator, RegressorMixin

Sklearn-compatible Causal Forest wrapper.

fit(X, y) expects the first column of X to be the binary treatment indicator. predict(X) returns CATE estimates.

Parameters:

Name Type Description Default
n_trees int
100
min_leaf_size int
5