Monotone Constraints#
The monotone_constraints module provides functions for inferring monotone constraints for XGBoost models.
Functions#
infer_monotone_constraints_from_correlations#
- iguanas.monotone_constraints.infer_monotone_constraints_from_correlations(X: polars.DataFrame, y: polars.Series) polars.DataFrame[source]#
Compute monotone constraint signs for XGBoost based on feature-target correlations.
- Parameters:
X (pl.DataFrame) – DataFrame containing features.
y (pl.Series) – Target series for computing correlations.
- Returns:
DataFrame with columns:
feature: Feature name
pearson_corr: Pearson correlation with target
constraint: Constraint value (1 for positive constraint, -1 for negative constraint, 0 for no constraint)
- Return type:
pl.DataFrame
Compute monotone constraint signs for XGBoost based on feature-target correlations.
Calculates Pearson correlations between each feature and the target, then assigns constraint values:
1 for positive correlation
-1 for negative correlation
0 for no correlation
Parameters:
X (pl.DataFrame): DataFrame containing features
y (pl.Series): Target series for computing correlations
Returns:
pl.DataFrame: DataFrame with columns: feature, pearson_corr, constraint
infer_monotone_constraints_from_stumps#
- iguanas.monotone_constraints.infer_monotone_constraints_from_stumps(stump: xgboost.sklearn.XGBClassifier, X: polars.DataFrame, y: polars.Series) polars.DataFrame[source]#
Determine monotone constraints by training decision stumps for each feature.
Trains a single-split tree (max_depth=1) for each feature and examines how predictions change from min to max value to determine monotonic relationship.
- Parameters:
stump (XGBClassifier) – XGBoost classifier configured as a stump (max_depth=1).
X (pl.DataFrame) – Features DataFrame.
y (pl.Series) – Target series for training.
- Returns:
DataFrame with columns: - feature: Feature name - constraint: Constraint value (1 for positive constraint, -1 for negative constraint, 0 for no constraint) - pred_at_min: Predicted probability at minimum feature value - pred_at_max: Predicted probability at maximum feature value - delta: Change in probability (pred_at_max - pred_at_min)
- Return type:
pl.DataFrame
Determine monotone constraints by training decision stumps for each feature.
Trains a single-split tree (max_depth=1) for each feature and examines how predictions change from min to max value to determine monotonic relationship.
Parameters:
stump (XGBClassifier): XGBoost classifier configured as a stump (max_depth=1)
X (pl.DataFrame): Features DataFrame
y (pl.Series): Target series for training
Returns:
pl.DataFrame: DataFrame with columns: feature, constraint, pred_at_min, pred_at_max, delta