A partial dependence plot shows how a model's prediction changes with one feature, averaged over the data.
The average hides two things. ICE curves show per-row responses, which reveals whether everyone reacts
the same way. ALE removes the unrealistic rows a PDP invents when features are correlated.
scripts/gen_pdp_script.py writes a script that draws centred ICE + PDP (+ ALE, + two-way PDP) and exports
the curves. scripts/ice_analysis.py reads the curves and reports what the average hides.
Trigger Conditions
Activate this skill when the user:
- Asks how a feature influences predictions ("what happens to risk as tenure grows?")
- Wants PDP, ICE, ALE or two-way interaction plots
- Suspects an interaction or a subgroup that reacts differently
- Must check that a response is monotonic, plausible or within regulatory expectations
Per-row attributions: shap-value-explainer (SHAP dependence plots are the attribution counterpart). Global rankings: feature-importance-reporter. Smallest change to flip a decision: counterfactual-explanation-generator.
Workflow
1. PICK -> features to show: top of the importance ranking, plus any with a business question
2. GENERATE -> python scripts/gen_pdp_script.py --model model.joblib --data test.csv --target y --features tenure plan --ale -o pdp.py
3. RUN -> python pdp.py (ice_<f>.csv, rows_<f>.csv, pdp_<f>.png [, ale_<f>.csv, pdp2_a_b.png])
4. ANALYSE -> python scripts/ice_analysis.py ice_tenure.csv --features rows_tenure.csv
5. FOLLOW UP -> interaction found -> two-way PDP (--pair) or ICE coloured by the separator; correlated -> ALE
6. REPORT -> plot, shape in words, heterogeneity, support, caveatsPDP, ICE or ALE?
| Situation | Use | Why |
|---|---|---|
| First look at a feature | centred ICE + PDP | the average and its spread in one plot |
| Feature correlated with others (|r| > 0.5) | ALE | PDP evaluates impossible rows (a 20-year tenure with 1 month of charges) |
| Suspected interaction | ICE coloured by the second feature, two-way PDP | the 1-D average cancels opposite effects |
| Categorical feature | PDP / ICE per level | ALE needs an ordering |
| Monotonicity check | ICE: share of curves going the wrong way | a monotonic PDP can hide non-monotonic rows |
| Stakeholder chart | PDP with a confidence band or ALE, rug of observed values | simple, honest about support |
Centred ICE (each curve minus its value at the first grid point) is the default. Uncentred ICE curves stack by level and hide shape differences. Definitions, maths and the cost of each method: pdp-ice-ale.md.
What ice_analysis.py Reports
| Finding | Rule | Meaning |
|---|---|---|
| direction and monotonic share | PDP end minus start; share of steps in that direction | overall shape |
| steepest segment | largest change per unit of the grid | threshold-like effect |
| OPPOSITE EFFECTS | >= 10% of curves move against the PDP beyond noise | the average hides an interaction |
| SUBGROUPS | exact two-group split of curve changes, >= 3 pooled sd apart | two strengths of one effect |
| separator | feature with AUC >= 0.7 (or <= 0.3) for the group label | the likely interaction partner |
| low support | grid outside the 5th-95th percentile of observed values | extrapolation: do not interpret |
| heterogeneity | end-point spread / PDP range > 1 | the PDP is a poor summary |
Verified: the PDP equals sklearn.inspection.partial_dependence's average. On a planted a x sign(b)
interaction, the separator is b with AUC 1.00. On the fixture, the separator recovers the planted
contract subgroup. ALE recovers the exact coefficient of a linear model with correlated features.
Reading Rules
- Causal language is wrong. "Predicted churn falls with tenure in this model", not "tenure reduces churn".
- Interpret only where data exists. Show the rug and ignore the tails outside the observed range.
- Correlated features make PDP lie. Check correlations first and use ALE when |r| > 0.5.
- Flat PDP does not mean no effect. Opposite ICE curves can cancel. Check
ice_analysis.py. - Scale matters. Classifiers: probability (or log-odds for additivity). Say which.
- Grid percentiles: 5th-95th by default. Extending the grid shows extrapolation, not knowledge.
Reading guide and worked examples: reading-pdp-ice.md. Monotonic constraints, regulatory checks and stakeholder charts: using-pdp-in-practice.md.
Output Format
When presenting partial dependence, deliver:
- Setup - model, data and sample size, grid, response (probability / prediction), class.
- Plots - centred ICE + PDP per feature with rug; ALE where features correlate; two-way PDP for interactions.
- Shape in words - direction, thresholds, monotonicity, magnitude in output units.
- Heterogeneity - opposite effects or subgroups, with the separating feature.
- Caveats - support, correlation, non-causal reading.
Scripts
python scripts/gen_pdp_script.py --model model.joblib --data test.csv --target churned --features tenure_months support_calls -o pdp.py
python scripts/gen_pdp_script.py --model pipe.joblib --data test.csv --features sqft --ale --sample 500
python scripts/gen_pdp_script.py --model m.joblib --data x.csv --features age --pair age income --class 1Reorders columns to the training order and converts integer columns to float (scikit-learn refuses
integer columns for partial dependence). Uses predict_proba of the last class (or --class) for
classifiers, a 5th-95th percentile grid, and level grids for categorical features. Writes the curves, the
sampled rows and the PNGs. Verified with LightGBM and logistic-regression Pipelines, numeric and categorical
features, ALE and two-way PDP. Exit codes: 0 written, 2 usage error.
python scripts/ice_analysis.py ice_tenure.csv
python scripts/ice_analysis.py ice.csv --features rows.csv --id-col row_id --jsonReads ICE curves in long format (row_id, grid value, prediction); numeric or categorical grids. Exit codes: 0 analysed, 2 usage or read error.
Additional Resources
| File | Content |
|---|---|
| pdp-ice-ale.md | definitions, centred ICE, ALE algorithm, two-way PDP, H-statistic, cost, library calls |
| reading-pdp-ice.md | shapes and what they mean, interactions, support, misreadings, worked fixture example |
| using-pdp-in-practice.md | monotonic constraints, plausibility reviews, regulated models, stakeholder charts |
anomaly-detection-model-builder
Build and evaluate anomaly detection for tabular, sensor and transaction data with few or no labels: define the anomaly type (point, contextual, collective), choose detectors (robust z-score/MAD and IQR rules, Mahalanobis with robust covariance, k-NN distance, LOF, Isolation Forest, one-class SVM, PCA reconstruction / autoencoders, forecasting residuals for time series), combine them by rank, explain each alert by its deviating features, set thresholds from an alert budget or the score distribution, and evaluate with precision@k, PR-AUC and recall on known incidents, or detector agreement when no labels exist. Includes pure-Python detectors (robust z, Mahalanobis, kNN, Isolation Forest, ensemble) and an evaluation script.
catboost-model-builder
Build CatBoost models that use its strengths correctly: raw categorical columns as cat_features (ordered target statistics, no manual encoding), text_features, Pool construction with NaN-safe categories, ordered boosting and has_time for temporal data, symmetric (oblivious) trees, overfitting detector with eval_set and use_best_model, losses for classification, regression (Quantile, Poisson, Tweedie) and ranking (YetiRank), class weights, monotone constraints, feature importance (PredictionValuesChange, LossFunctionChange) and SHAP values, GPU training and model export. Plans cat/text/numeric columns from a CSV and generates a runnable training script, and checks parameter sets for the conflicts CatBoost rejects (iterations vs n_estimators, Bayesian bootstrap with subsample, multiple class-weight options, depth > 16, use_best_model without eval_set).
categorical-encoding-selector
Choose and implement the right encoding for every categorical column given the model family and the data: one-hot (with infrequent-level grouping and handle_unknown), ordinal with an explicit order, cross-fitted target encoding (scikit-learn TargetEncoder, CatBoost ordered statistics, category_encoders inside CV), frequency/count encoding, feature hashing, native categorical support in LightGBM, HistGradientBoosting, XGBoost and CatBoost, prefix levels for codes (zip3, NAICS-2), and embeddings. Measures cardinality, rare-level share, unseen-level rate on a time-ordered holdout and target signal per column, emits the ColumnTransformer, and quantifies target-encoding leakage (in-sample vs out-of-fold vs holdout AUC).
classification-model-selector
Choose the right classification algorithm for tabular, text or mixed data and prove the choice with a fair bake-off: logistic regression (L2, L1, elastic net), linear SVM, naive Bayes, k-NN, RBF SVM, decision trees, random forest, extra trees, HistGradientBoosting, LightGBM, XGBoost, CatBoost, explainable boosting machines (EBM/GAM), points scorecards and MLPs, matched to data size, width, categorical and high-cardinality share, missingness, class imbalance, text, and constraints such as interpretability, monotonic constraints, calibrated probabilities, latency budgets and tiny deployable models. Ranks candidates with starting hyperparameters and cautions, then generates a bake-off script running every candidate on identical CV folds with per-fold metrics, fit time and prediction latency.
clustering-algorithm-selector
Choose the right clustering algorithm and check that clustering makes sense at all: cluster tendency (Hopkins statistic with a correlated-features caveat, nearest-neighbour isolation), then k-means / MiniBatchKMeans, Gaussian mixtures with BIC, agglomerative (Ward, average, complete, single) with dendrograms, DBSCAN, HDBSCAN, OPTICS, spectral clustering, BIRCH, mean shift, k-prototypes and k-modes for mixed or categorical data, and Gower distance, matched to data size, expected shapes, noise, varying density, known k, soft memberships, hierarchy and streaming. Covers preprocessing (scaling, encoding, dimensionality, distance metrics), validation (internal indices, bootstrap stability, external labels, business profiling) and assigning new points.
collaborative-filtering-implementer
Implement collaborative filtering recommenders that beat popularity: item-based kNN with cosine, Jaccard or asymmetric similarity, shrinkage, neighbourhood size, positive-only or mean-centred rating signals and 'because you liked X' explanations; implicit ALS with confidence weighting, BPR pairwise ranking and the closed-form EASE model in plain NumPy, tuned on a temporal validation split by recall@k and NDCG@k and refit on all data; plus user-kNN, explicit matrix factorisation, the implicit/LightFM libraries, hyperparameter ranges, cold-start fallbacks, scaling with sparse matrices and approximate nearest neighbours. Produces top-k lists in the format of the recommendation evaluator.