Skip to content

kpe()

kpe.kpe(X, A, Y, propensity=None, *, n_shuffles=100, n_folds=6, n_nuisance_folds=None, is_rct=True, contextual_policy='policy_tree', best_arm='ips', reward_model='random_forest', propensity_model='logistic', policy_features=None, n_jobs=1, random_state=None, verbose=False)

K-Fold Personalization Estimator — kpe2 shared-nuisance cross-fitting.

This kpe2 variant fits all nuisances (reward model, contextual policy, best single arm, and — when is_rct=False — the propensity) on a shared set of n_nuisance_folds folds, then evaluates the AIPW influence on the held-out evaluation block. See :mod:kpe.core.cross_fit.

Parameters:

Name Type Description Default
X (array - like, shape(n, d))

Baseline covariates.

required
A array-like of int, shape (n,)

Observed treatment, values in 0..K-1.

required
Y (array - like, shape(n))

Observed outcome.

required
propensity scalar, shape (n,), or shape (n, K)

Known propensity p(A_i | X_i). Required when is_rct=True. When is_rct=False it is ignored (the propensity is fit on the nuisance folds) and may be omitted.

None
n_shuffles int

Number of Algorithm-1 repetitions (each with a different seed).

100
n_folds int

Number of folds K the data is partitioned into (default 6).

6
n_nuisance_folds int

Number of folds m used to fit all nuisances (default n_folds - 1). The evaluation block size is b = n_folds - m and must divide n_folds (non-overlapping blocks); each sample is evaluated exactly once per shuffle. The default gives leave-one-fold-out.

None
is_rct bool

If True, propensity is the known design propensity and nothing is fit for it. If False, an estimated p_hat(a|x) is fit on the nuisance folds (via propensity_model) and used in both the AIPW evaluation and the best-arm IPS.

True
contextual_policy Any

Each may be a string in the built-in registry or a fit/predict object. propensity_model is used only when is_rct=False.

'policy_tree'
best_arm Any

Each may be a string in the built-in registry or a fit/predict object. propensity_model is used only when is_rct=False.

'policy_tree'
reward_model Any

Each may be a string in the built-in registry or a fit/predict object. propensity_model is used only when is_rct=False.

'policy_tree'
propensity_model Any

Each may be a string in the built-in registry or a fit/predict object. propensity_model is used only when is_rct=False.

'policy_tree'
policy_features sequence of int

Columns of X to pass to the contextual policy. Defaults to all columns.

None
n_jobs int

Passed through to joblib. 1 is sequential (default); -1 uses all cores.

1
random_state int

Base seed. Shuffle s uses random_state + s.

None