How dhanuk8778-netizen/predictive_models works
Purpose and Entry Points
This repository is a batch ML workflow for predicting industrial machine failure from AI4I 2020 sensor data. It is executed as ordered Python scripts from src/, beginning with preparation and ending with evaluation and SHAP interpretation. Source data is local at data/ai4i2020.csv; generated visual artifacts are written under output/figures.
1. Data Ingestion and Label Validation
src/data_prep.py loads and cleans the dataset, validates the binary machine-failure target, and establishes the dataset consumed by later stages. A critical boundary is between the target and failure-subtype flags: subtype labels are post-failure information and must not enter predictive training.
• src/data_prep.py
• data/ai4i2020.csv
2. Exploratory Validation
src/eda.py examines class prevalence, feature distributions, and correlations. This stage may use the subtype flags to validate target semantics, but it is analytical only and must not feed leakage-prone columns into modeling.
• src/eda.py
• output/figures
3. Leakage-Safe Feature Construction
src/features.py removes post-outcome subtype flags, creates physically motivated predictors, and creates stratified train/test partitions. Core engineered signals include temperature difference, torque × rotational-speed power proxy, and torque/wear interaction. The untouched test partition is the boundary for final generalization measurement.
• src/features.py
• src/data_prep.py
4. Imbalance-Aware Model Training and Selection
src/train.py trains Random Forest and XGBoost candidates using stratified 5-fold cross-validation and randomized hyperparameter search. Selection centers on PR-AUC because failure is rare (~3.39%), making accuracy misleading. Imbalance is handled in-model through Random Forest class weights and XGBoost positive-class weighting rather than resampling.
• src/train.py
• requirements.txt
5. Held-Out Evaluation and Operating Thresholds
src/evaluate.py evaluates selected models against the held-out test set using confusion matrices, ROC/PR curves, ROC-AUC, PR-AUC, precision, and recall. It also derives XGBoost operating points at target recall levels; threshold choice is a business-risk boundary between missed failures and false maintenance alarms.
• src/evaluate.py
• output/figures
6. Model Explainability
src/shap_analysis.py produces global and per-prediction SHAP explanations for the trained model. These outputs validate whether learned behavior aligns with known physical failure mechanisms, particularly tool wear, speed, and power-related features.
• src/shap_analysis.py
• output/figures/shap_summary.png
• output/figures/shap_waterfall_example.png
Runtime and Dependencies
The system is a local Python, file-oriented pipeline with no service, database, or cloud infrastructure. Material external inputs are the UCI AI4I dataset stored locally; material ML/runtime dependencies are defined in requirements.txt, including the Random Forest/XGBoost and SHAP ecosystem implied by the workflow.
• requirements.txt
• data/ai4i2020.csv
Main entry points: train.py Candidate training & selection · shap_analysis.py SHAP analysis · features.py Feature construction · evaluate.py Held-out evaluation
Components 18
Data & validation
- AI4I 2020 sensor data
data/ai4i2020.csv - Data preparation · Cleans data and validates the binary failure target.
src/data_prep.py - Validated dataset · Keeps failure subtype flags distinct from the predictive target.
- Exploratory validation · Uses subtype flags only for analytical target validation.
src/eda.py - EDA figures
output/figures
Feature boundary
- Feature construction · Removes post-outcome flags and engineers physical predictors.
src/features.py - Stratified training partition
- Untouched test partition · Reserved for final generalization measurement.
Modeling & evaluation
- Candidate training & selection · Runs stratified 5-fold randomized search using PR-AUC.
src/train.py - Random Forest candidate · Uses class weighting for imbalance.
- XGBoost candidate · Uses positive-class weighting for imbalance.
- Selected trained model · Selected by cross-validated PR-AUC.
- Held-out evaluation · Computes metrics and recall-targeted operating thresholds.
src/evaluate.py - Evaluation figures
output/figures
Interpretation outputs
- SHAP analysis · Explains global and individual trained-model predictions.
src/shap_analysis.py - SHAP summary
- SHAP waterfall example
Other components
- ML dependencies
requirements.txt
Connections 20
- AI4I 2020 sensor data → Data preparation: load
- Data preparation → Validated dataset: clean and validate
- Validated dataset → Exploratory validation: analyze
- Exploratory validation → EDA figures: write
- Validated dataset → Feature construction: construct leakage-safe features
- Feature construction → Stratified training partition: stratified split
- Feature construction → Untouched test partition: reserve
- ML dependencies → Candidate training & selection: provides ML stack
- Stratified training partition → Candidate training & selection: cross-validate and tune
- Candidate training & selection → Random Forest candidate: train
- Candidate training & selection → XGBoost candidate: train
- Random Forest candidate → Selected trained model: compare by PR-AUC
- XGBoost candidate → Selected trained model: compare by PR-AUC
- Selected trained model → Held-out evaluation: score
- Untouched test partition → Held-out evaluation: held-out measurement
- Held-out evaluation → Evaluation figures: write curves and matrices
- Selected trained model → SHAP analysis: explain
- Untouched test partition → SHAP analysis: explain predictions
- SHAP analysis → SHAP summary: write
- SHAP analysis → SHAP waterfall example: write