maorsoul commited on
Commit
8901fa7
ยท
verified ยท
1 Parent(s): 578d41d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +368 -3
README.md CHANGED
@@ -1,3 +1,368 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ # โœˆ๏ธ Flight Delay Predictor
4
+
5
+ A complete end-to-end Machine Learning project predicting whether a flight will experience **low delay** or **high delay**, based on real U.S. flight data.
6
+
7
+ ---
8
+
9
+ # ๐Ÿ“Œ 1. Project Goal
10
+
11
+ The original dataset included a **regression target** (`ArrDelay`).
12
+ To make the project more practical and interpretable, we transformed the target into a **binary classification problem**:
13
+
14
+ * **Low delay (0)** โ€” ArrDelay โ‰ค median
15
+ * **High delay (1)** โ€” ArrDelay > median
16
+
17
+ The project walks through the full ML process:
18
+
19
+ * Data loading & cleaning
20
+ * EDA
21
+ * Feature engineering
22
+ * Model training
23
+ * Evaluation
24
+ * Selecting a winner
25
+ * Exporting the model
26
+
27
+
28
+ # ๐Ÿ“Š 2. Dataset Overview
29
+
30
+ In this section we explored:
31
+
32
+ * Total rows, columns
33
+ * Data types
34
+ * Missing values
35
+ * Basic statistical patterns
36
+ * Target variable behavior before classification
37
+
38
+ **Main actions performed:**
39
+
40
+ * Loaded 20,000 rows from the 2018 dataset
41
+ * Removed irrelevant fields (like tail IDs)
42
+ * Verified missing values and cleaned them
43
+ * Verified numerical ranges to detect odd values
44
+ * Converted original delay (`ArrDelay`) into the classification target `y_class`
45
+ * Split into 80% train, 20% test
46
+
47
+ โฌ‡๏ธ
48
+
49
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.37.33](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/H5TkmTdvamGzCX3tnkWbK.png)
50
+
51
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.38.47](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/ATuj1DhNFu4IOKADBVvfT.png)
52
+
53
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.39.05](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/uVzJysvmUNKrI6dGyDxJU.png)
54
+
55
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.39.25](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/dFULLmyeCowD54qkHMV3J.png)
56
+
57
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.39.41](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/ecNxcebQio2SOgl63r93a.png)
58
+
59
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.39.57](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/-G9t6hG5_-q9pBHxqN7rT.png)
60
+
61
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.40.08](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/cL1WcEpM2edSFbPHKSiUo.png)
62
+
63
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.40.19](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/oY-wiihgzmlMtMvqzIZFK.png)
64
+
65
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.40.29](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/cYOZt4qv4fOxWr8RxQkfu.png)
66
+
67
+
68
+ ### **Insert dataset head or summary as an image**
69
+
70
+
71
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.41.55](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/OzNiiXLyr8accJYlArisL.png)
72
+
73
+
74
+ # ๐Ÿ” 3. Exploratory Data Analysis (EDA)
75
+
76
+ In this phase we studied the patterns behind delay behavior.
77
+
78
+ ### What we analyzed:
79
+
80
+ * **Distribution of arrival delays**
81
+ Helps understand skew, outliers, and how reasonable our classification threshold is.
82
+
83
+ * **Correlation between numerical features**
84
+ Found that distance and scheduled times impact delays but not extremely strongly.
85
+
86
+ * **Delay behavior by airline**
87
+ Some airlines have significantly more variability in delays.
88
+
89
+ * **Time of day vs delay**
90
+ Late-day flights tend to accumulate more delays.
91
+
92
+ * **Outlier detection using Z-score**
93
+ Removed unrealistic delays > ยฑ3 standard deviations.
94
+
95
+ ### Why it matters:
96
+
97
+ EDA allowed us to understand which features influence delays and how noisy the data is.
98
+ This guided feature engineering and reduced overfitting risk.
99
+
100
+ โฌ‡๏ธ
101
+
102
+ ### **Place graphs here**
103
+
104
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.44.08](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/M3ETCvLN0Rf_AItthFbw3.png)
105
+
106
+
107
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.44.28](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/-m8eDsCZWlH-AxGvrtZgS.png)
108
+
109
+
110
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.44.41](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/rXCdxRxcnJap6b9U28-d9.png)
111
+
112
+
113
+ # ๐Ÿ› ๏ธ 4. Feature Engineering
114
+
115
+ Feature engineering was critical for improving model quality.
116
+
117
+ ### Done in this step:
118
+
119
+ #### **1. One-Hot Encoding for categorical features**
120
+
121
+ * Airline
122
+ * Origin airport
123
+ * Destination airport
124
+ * Day of Week
125
+ * Cancellation field
126
+
127
+ This expanded the dataset into thousands of columns but preserved categorical meaning.
128
+
129
+ #### **2. Scaling important numerical fields**
130
+
131
+ * Distance
132
+ * CRSDepTime
133
+ * CRSArrTime
134
+ * AirTime
135
+
136
+ Scaling prevents models like Logistic Regression and Gradient Boosting from being biased by large numeric ranges.
137
+
138
+ #### **3. PCA (optional)**
139
+
140
+ Used only for visualization; helped validate that the classes are somewhat separable.
141
+
142
+ #### **4. K-Means clustering (optional exploratory step)**
143
+
144
+ Cluster labels added as an experimental feature to see if they help models (they had mild impact).
145
+
146
+ โฌ‡๏ธ
147
+
148
+ ### **Place FE graphs here**
149
+
150
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.45.11](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/T7pjOhFJL1Zn54OroFK9T.png)
151
+
152
+
153
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.45.26](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/Tq6yVLGH-w8tLty1rbNQG.png)
154
+
155
+
156
+ # ๐Ÿค– 5. Models Trained
157
+
158
+ We compared **three supervised classification models**:
159
+
160
+ ### โœ” Logistic Regression
161
+
162
+ * Simple baseline
163
+ * Fast, linear, interpretable
164
+ * Surprisingly produced perfect predictions (overfitting to clean, thresholded labels)
165
+
166
+ ### โœ” Random Forest Classifier
167
+
168
+ * Non-linear
169
+ * Handles high-dimensional data
170
+ * Good but struggled with high-delay recall
171
+
172
+ ### โœ” Gradient Boosting Classifier
173
+
174
+ * Ensemble of weak learners
175
+ * Best real-world performance
176
+ * Most balanced precisionโ€“recall
177
+ * Strong against noise
178
+ * Best generalization to unseen data
179
+
180
+ โฌ‡๏ธ
181
+
182
+ ### **Insert models summary image**
183
+
184
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.45.46](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/LWGxTGHU-gYW2QRFOjhm_.png)
185
+
186
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.46.01](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/WelQ-fbqravyTW1nYv4pW.png)
187
+
188
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.46.11](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/kA863njS1KJj4ZvvIFvAq.png)
189
+
190
+
191
+ # ๐Ÿ† 6. Winning Model
192
+
193
+ The selected model is:
194
+
195
+ # **๐ŸŒŸ Gradient Boosting Classifier**
196
+
197
+ ### Why this one?
198
+
199
+ * Best tradeoff between false positives and false negatives
200
+ * Highest real F1-score
201
+ * Handles imbalanced patterns better
202
+ * Robust to feature noise and outliers
203
+ * Most realistic generalization
204
+
205
+ ## 7. Regression-to-Classification
206
+
207
+ ### 7.1 Creating Classes from the Numeric Target (Median Split)
208
+
209
+ In this part we reframed the original regression target **ArrDelay** into a
210
+ binary classification target.
211
+
212
+ We computed the **median arrival delay on the training set** (โ‰ˆ โˆ’5 minutes) and
213
+ used it as a threshold:
214
+
215
+ - **Class 0 โ€“ Low delay:** `ArrDelay < median`
216
+ (flight is on time or earlier than a typical flight in the dataset).
217
+ - **Class 1 โ€“ High delay:** `ArrDelay โ‰ฅ median`
218
+ (flight is more delayed than a typical flight).
219
+
220
+ The same rule was applied to both **train and test** targets, using the **same
221
+ engineered features** as in the regression part.
222
+ This keeps the classification task aligned with the original question:
223
+ > *โ€œHow large will the arrival delay be?โ€*
224
+ now phrased as
225
+ > *โ€œWill this flight have a higher-than-typical delay or not?โ€*
226
+
227
+
228
+ ### 7.2 Checking Class Balance
229
+
230
+ After creating the classes, we examined their distribution:
231
+
232
+ - **Training set:**
233
+ about **50.6% High delay (Class 1)** and **49.4% Low delay (Class 0)**.
234
+ - **Test set:**
235
+ about **51.3% Low delay (Class 0)** and **48.7% High delay (Class 1)**.
236
+
237
+ The classes are therefore **well balanced**, and no class is clearly
238
+ under-represented.
239
+
240
+ Because of this balance, **accuracy** is already informative, but to avoid
241
+ being misled in edge cases and to keep the focus on the โ€œHigh delayโ€ class,
242
+ we mainly compared models using the **F1-score** (which combines precision and
243
+ recall for the positive class).
244
+
245
+ ๐Ÿ‘‰ *Here I will insert a bar plot (or table screenshot) of the class
246
+ distribution in train/test.*
247
+
248
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.55.24](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/fSo9lYbeNOK6_8qrBtFRc.png)
249
+
250
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.55.39](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/-kh6L76mQaE9tJv4nymxA.png)
251
+
252
+ ## 8. Train & Evaluate Classification Models
253
+
254
+ ### 8.1 Precision vs. Recall โ€” What Matters More?
255
+
256
+ In the context of predicting **high-delay flights**, **recall** for the positive class is more important than precision.
257
+
258
+ The reason:
259
+ Missing a truly delayed flight (false negative) is operationally worse than mistakenly flagging
260
+ an on-time flight as delayed (false positive).
261
+ A missed severe delay can lead to missed connections, poor customer experience, and scheduling disruptions,
262
+ while a false alarm only causes minor adjustments like extra buffer time.
263
+
264
+ ---
265
+
266
+ ### 8.1 False Positives vs. False Negatives โ€” Which Is Worse?
267
+
268
+ - A **false positive** means predicting โ€œhigh delayโ€ when the flight is actually low-delay.
269
+ - A **false negative** means predicting โ€œlow delayโ€ when the flight is actually highly delayed.
270
+
271
+ In our task, **false negatives are more critical**, because they leave planners unprepared for major delays.
272
+ False positives are less harmful โ€” they may cause unnecessary caution, but do not create operational failures.
273
+
274
+ ---
275
+
276
+ ### 8.2 Training Three Classification Models
277
+
278
+ We trained and evaluated three different models from scikit-learn, using the same engineered features
279
+ and the binary target created in Part 7:
280
+
281
+ 1. **Logistic Regression**
282
+ 2. **Random Forest Classifier**
283
+ 3. **Gradient Boosting Classifier**
284
+
285
+ ๐Ÿ‘‰ *Insert model training diagram or screenshots of code here (optional).*
286
+
287
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.57.44](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/vHzlqE8vnf7tRBxACgY-V.png)
288
+
289
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.57.59](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/o4D5WklP1INIFBvvubdf3.png)
290
+
291
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.58.14](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/o9L76PgbO7hWmyEZIfQHL.png)
292
+
293
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.58.25](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/5BaZaCtq0RDU4Sg_kAneC.png)
294
+
295
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.58.36](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/0YggL_58zalfn50WokKf0.png)
296
+
297
+ ![ืฆื™ืœื•ื ืžืกืš 2025-11-29 ื‘-9.58.48](https://cdn-uploads.huggingface.co/production/uploads/69183cd79510e3441ef86afc/S896FbQSOUX4pQTl5ym4d.png)
298
+
299
+
300
+ ### 8.3 Model Evaluation
301
+
302
+ For each model we generated:
303
+
304
+ - `classification_report` (precision, recall, F1-score, support)
305
+ - Confusion matrix
306
+ - Interpretation of the types of errors the model makes
307
+
308
+ Below is a summary of the results:
309
+
310
+ #### **Logistic Regression**
311
+ - Achieved **perfect classification** on the test set (F1 = 1.00).
312
+ - The confusion matrix shows **0 errors**.
313
+ - This suggests the engineered features were highly separable.
314
+
315
+
316
+ #### **Random Forest Classifier**
317
+ - F1-score โ‰ˆ **0.79**
318
+ - Stronger recall for Class 0 (low delay), weaker for Class 1 (high delay).
319
+ - Confusion matrix shows the model tends to **miss high-delay flights** (false negatives).
320
+
321
+
322
+ #### **Gradient Boosting Classifier**
323
+ - F1-score โ‰ˆ **0.85**
324
+ - Better balance between precision and recall compared to Random Forest.
325
+ - Fewer false negatives than Random Forest and more consistent performance overall.
326
+
327
+
328
+ ### 8.3 Which Model Performs Best โ€” and Why?
329
+
330
+ The **best model is the Logistic Regression**, because:
331
+
332
+ - It achieves **perfect predictive performance** on this dataset.
333
+ - It cleanly separates the engineered feature space into the two classes.
334
+ - It avoids the false negatives that are most critical in this task.
335
+ - Its confusion matrix shows **zero misclassifications**.
336
+
337
+ While this may indicate a highly separable dataset rather than model superiority alone,
338
+ within the scope of this assignment **it is the clear winner**.
339
+
340
+ ---
341
+
342
+ ### 8.4 Winner: Exporting and Uploading the Model
343
+
344
+ We exported the winning model (Logistic Regression) to a pickle file and uploaded it to the HuggingFace repository:
345
+
346
+ - **File:** `winning_classifier_model.pkl`
347
+ - Stored alongside the earlier regression winning model file:
348
+ - `winning_model.pkl`
349
+
350
+ Both files live in the same HuggingFace model repository as required.
351
+
352
+
353
+
354
+ # ๐ŸŽฅ 9. Video Presentation
355
+
356
+ Your recording should include:
357
+
358
+ * Quick dataset overview
359
+ * Key EDA takeaways
360
+ * How you encoded and engineered features
361
+ * Explanation of each model
362
+ * Confusion matrices
363
+ * Why Gradient Boosting won
364
+ * Summary of lessons learned
365
+
366
+ โฌ‡๏ธ
367
+
368
+ [Watch Presentation](https://your-video-link.com)