4.1.8. doubleml.utils.PSProcessor#
- class doubleml.utils.PSProcessor(clipping_threshold: float = 0.01, extreme_threshold: float = 1e-12, calibration_method: str | None = None, cv_calibration: bool = False)#
Processor for propensity score calibration, clipping, and validation.
- Parameters:
clipping_threshold (float, default=1e-2) – Minimum and maximum bound for propensity scores after clipping.
extreme_threshold (float, default=1e-12) – Threshold below which propensity scores are considered extreme. Used for generating warnings.
calibration_method ({'isotonic', None}, optional) – If provided, applies the specified calibration method to the propensity scores before clipping.
cv_calibration (bool, default=False) – Whether to use cross-validation for calibration. Only applies if a calibration method is specified.
Examples
>>> import numpy as np >>> from doubleml.utils import PSProcessor >>> ps = np.array([0.001, 0.2, 0.5, 0.8, 0.999]) >>> treatment = np.array([0, 1, 1, 0, 1]) >>> processor = PSProcessor(clipping_threshold=0.01) >>> adjusted = processor.adjust_ps(ps, treatment) >>> print(np.round(adjusted, 3)) [0.01 0.2 0.5 0.8 0.99]
Methods
adjust_ps(propensity_scores, treatment[, ...])Adjust propensity scores via calibration and clipping.
from_config(config)Create PSProcessor from PSProcessorConfig.
Attributes
calibration_methodGet the calibration method.
clipping_thresholdGet the clipping threshold.
cv_calibrationGet whether cross-validation calibration is used.
extreme_thresholdGet the extreme threshold.
- PSProcessor.adjust_ps(propensity_scores: ndarray, treatment: ndarray, cv: int | list | None = None, learner_name: str | None = None) ndarray#
Adjust propensity scores via calibration and clipping.
- Parameters:
propensity_scores (np.ndarray) – Raw propensity score predictions.
treatment (np.ndarray) – Treatment assignments (1 for treated, 0 for control).
cv (int or list, optional) – Cross-validation strategy for calibration. Used only if calibration is applied.
learner_name (str, optional) – Name of the learner providing the propensity scores, used in warnings.
- Returns:
Clipped and validated propensity scores.
- Return type:
np.ndarray
- classmethod PSProcessor.from_config(config: PSProcessorConfig)#
Create PSProcessor from PSProcessorConfig.