A Streamlit web app and a notebook for predicting machine failure risk from sensor readings (temperature, vibration, power usage, humidity and machine type). The app lets a user upload a CSV, explore it, train a Random Forest and get a live prediction from the sidebar.
Every model in the notebook (logistic regression, SVM, decision tree, random forest) scores 70% accuracy. That looks reasonable until it is compared with the simplest possible rule: always predict "no failure". 70% of the machines in the data are labelled "no failure", so that rule also scores 70%. The confusion matrix confirms that the models were doing exactly this. They predicted "no failure" for all 200 test machines and caught none of the 60 at-risk ones.
Further checks show that the sensor readings in this dataset carry no information about the label:
| Check | Result |
|---|---|
| Average readings, at-risk vs normal machines | almost identical (e.g. temperature 70.6 vs 70.0, vibration 50.3 vs 50.4) |
| Cross-validated ROC AUC, logistic regression | 0.49 |
| Cross-validated ROC AUC, random forest | 0.49 |
| XGBoost / XGBoost + SMOTE | 63% / 54% accuracy, both below the baseline |
An AUC of 0.5 is what random guessing gives, so the labels behave as if they were assigned at random. This looks like a synthetic dataset. No model can do better on it, and adding more of the same data would not help. The useful lesson is about evaluation: report the majority-class baseline, the confusion matrix and recall for the failure class, not accuracy alone. The app now shows the baseline next to the accuracy and warns when the model does not beat it.
- Data: uses the bundled
machine_failure_dataset.csv, or a CSV you upload (the target must be the last column). - Exploration: raw data, data types, summary statistics, correlation heatmap and target distribution.
- Preprocessing: one label encoder per text column, then standard scaling of all features.
- Model: a Random Forest (100 trees) trained on a stratified 80/20 split. Training is cached, so the model is trained once per dataset rather than on every click.
- Evaluation: classification report, confusion matrix, accuracy and the majority-class baseline.
- Prediction: enter values in the sidebar (they start at typical values from the data) and press Predict.
pip install -r requirements.txt
streamlit run streamlitApp.py| File | What it is |
|---|---|
streamlitApp.py |
the web app |
machine_failure.ipynb |
notebook comparing logistic regression, SVM, decision tree, random forest and XGBoost (with and without SMOTE) |
machine_failure_dataset.csv |
1,000 machines, 6 columns; 70% labelled "no failure", 30% "failure risk" |
requirements.txt |
Python packages |
- Real data with signal, e.g. the AI4I 2020 predictive maintenance dataset or NASA's turbofan run-to-failure data, where sensor readings genuinely change before failure.
- Metrics suited to rare failures: recall and precision on the failure class, precision-recall curves, and a decision threshold chosen for the cost of a missed failure versus a false alarm.
- Cross-validation instead of a single train/test split.
Richard Olanite · github.com/thatboypage