File size: 6,193 Bytes
cc36f2a
 
 
 
 
 
 
 
 
 
 
0b794cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ae12df
0b794cc
 
 
 
 
 
 
9ae12df
0b794cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ae12df
0b794cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
---
title: Predictive Maintenance System
emoji: πŸ”§
colorFrom: blue
colorTo: green
sdk: streamlit
sdk_version: 1.29.0
app_file: app.py
pinned: false
---

# Predictive Maintenance System - AI4I 2020 Dataset

## Project Overview

This project implements a comprehensive predictive maintenance system using machine learning to predict when industrial machinery needs maintenance. The system analyzes the AI4I 2020 Predictive Maintenance Dataset and provides interactive visualizations and real-time predictions through a Streamlit web application.

## Features

- **Comprehensive EDA**: 15+ different exploratory data analyses
- **Machine Learning Model**: Random Forest Classifier for failure prediction
- **Real-time Predictions**: Interactive interface for runtime predictions
- **Maintenance Scheduling**: Estimates time to failure and maintenance urgency
- **Interactive Visualizations**: Dynamic charts and graphs using Plotly
- **Batch Processing**: Upload CSV files for batch predictions

## Dataset

The AI4I 2020 Predictive Maintenance Dataset contains:
- **10,000 machine records**
- **14 features** including temperature, rotational speed, torque, and tool wear
- **Binary target**: Machine failure (0 = no failure, 1 = failure)
- **5 failure types**: TWF, HDF, PWF, OSF, RNF

## Project Structure

```
project/
β”œβ”€β”€ ai4i2020.csv              # Dataset file
β”œβ”€β”€ analysis.py               # EDA analysis script
β”œβ”€β”€ preprocessing.py          # Data preprocessing module
β”œβ”€β”€ model.py                  # Machine learning model
β”œβ”€β”€ train_model.py           # Script to train and save model
β”œβ”€β”€ app.py                    # Streamlit web application
└── README.md                 # Project documentation
```

## Installation

1. **Clone or download the project**
2. **Install dependencies** (requirements listed below):
```bash
pip install pandas==2.1.4 numpy==1.26.2 matplotlib==3.8.2 seaborn==0.13.0 scikit-learn==1.4.0 streamlit==1.29.0 plotly==5.18.0
```
3. **Ensure the dataset file (`ai4i2020.csv`) is in the project directory**

## Usage

### Option 1: Run Streamlit App Directly (Recommended)

The app will train the model automatically on first run:

```bash
streamlit run app.py
```

### Option 2: Train Model First, Then Run App

1. **Train the model**:
```bash
python train_model.py
```

2. **Run the Streamlit app**:
```bash
streamlit run app.py
```

### Option 3: Run EDA Analysis Only

```bash
python analysis.py
```

## Streamlit Application

The web application includes four main sections:

### 1. Introduction
- Dataset overview and statistics
- Project goals and features
- Dataset preview

### 2. Exploratory Data Analysis
Interactive visualizations including:
- Summary statistics
- Target distribution
- Feature distributions
- Correlation analysis
- Failure analysis by machine type
- Tool wear analysis
- Temperature analysis
- Outlier detection
- Pairwise relationships
- Failure type breakdown

### 3. Model & Predictions
- Model performance metrics
- Feature importance visualization
- **Runtime prediction**: Enter machine parameters to predict maintenance needs
- **Batch prediction**: Upload CSV file for multiple predictions
- Maintenance urgency assessment
- Time-to-failure estimation

### 4. Conclusion
- Key findings and takeaways
- Applications and future improvements

## EDA Analyses Performed

1. Summary statistics (mean, median, mode, etc.)
2. Missing value analysis
3. Data types and unique value counts
4. Target variable distribution
5. Correlation analysis
6. Outlier detection (IQR method)
7. Feature distribution analysis
8. Failure analysis by machine type
9. Tool wear analysis
10. Temperature analysis
11. Power and rotational speed analysis
12. Pairwise feature relationships
13. Detailed failure type analysis
14. Time to failure estimation
15. Grouped aggregations

## Machine Learning Model

- **Algorithm**: Random Forest Classifier
- **Features**: 11 engineered features including:
  - Air temperature, Process temperature
  - Rotational speed, Torque
  - Tool wear
  - Temperature difference
  - Power
  - Machine type encoding
  
- **Evaluation Metrics**:
  - Accuracy
  - Precision
  - Recall
  - F1-Score
  - ROC-AUC

## Predictive Features

The model predicts:
1. **Machine Failure**: Binary prediction (Yes/No)
2. **Failure Probability**: Probability score (0-1)
3. **Time to Failure**: Estimated minutes until maintenance needed
4. **Maintenance Status**: Current maintenance requirement status
5. **Maintenance Urgency**: CRITICAL, HIGH, MEDIUM, or LOW

## Runtime Prediction

Users can input machine parameters:
- Machine Type (L, M, H)
- Air Temperature (K)
- Process Temperature (K)
- Rotational Speed (rpm)
- Torque (Nm)
- Tool Wear (minutes)

The system provides:
- Failure prediction
- Maintenance urgency level
- Estimated time to failure
- Detailed recommendations

## Technical Stack

- **Python 3.8+**
- **Data Processing**: Pandas, NumPy
- **Visualization**: Matplotlib, Seaborn, Plotly
- **Machine Learning**: Scikit-learn
- **Web Framework**: Streamlit

## Key Insights

1. **Tool wear** is the most critical indicator of machine health
2. **Temperature difference** between process and air temperature correlates with failures
3. Machine **type affects failure rates** differently
4. Early detection can **prevent costly downtime**
5. Proactive maintenance scheduling can **optimize operations**

## Applications

- Industrial manufacturing
- Equipment monitoring systems
- Preventive maintenance scheduling
- Cost reduction through failure prevention
- Production optimization

## Future Enhancements

1. Real-time data streaming integration
2. IoT sensor integration
3. Advanced ensemble methods
4. Time-series analysis
5. Automated alert system
6. Historical maintenance record integration

## Author

Developed as part of the Introduction to Data Science course project.

## License

This project is for educational purposes.

## Acknowledgments

- AI4I 2020 Predictive Maintenance Dataset
- Scikit-learn documentation
- Streamlit documentation

---

**Note**: Make sure the `ai4i2020.csv` file is in the same directory as the scripts before running the application.