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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+

|
| 50 |
+
|
| 51 |
+

|
| 52 |
+
|
| 53 |
+

|
| 54 |
+
|
| 55 |
+

|
| 56 |
+
|
| 57 |
+

|
| 58 |
+
|
| 59 |
+

|
| 60 |
+
|
| 61 |
+

|
| 62 |
+
|
| 63 |
+

|
| 64 |
+
|
| 65 |
+

|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
### **Insert dataset head or summary as an image**
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+

|
| 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 |
+

|
| 105 |
+
|
| 106 |
+
|
| 107 |
+

|
| 108 |
+
|
| 109 |
+
|
| 110 |
+

|
| 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 |
+

|
| 151 |
+
|
| 152 |
+
|
| 153 |
+

|
| 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 |
+

|
| 185 |
+
|
| 186 |
+

|
| 187 |
+
|
| 188 |
+

|
| 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 |
+

|
| 249 |
+
|
| 250 |
+

|
| 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 |
+

|
| 288 |
+
|
| 289 |
+

|
| 290 |
+
|
| 291 |
+

|
| 292 |
+
|
| 293 |
+

|
| 294 |
+
|
| 295 |
+

|
| 296 |
+
|
| 297 |
+

|
| 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)
|