Yashvj123 commited on
Commit
eae0c35
Β·
verified Β·
1 Parent(s): a5dc826

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +146 -0
app.py CHANGED
@@ -396,6 +396,152 @@ elif st.session_state.current_page == "EDA":
396
  if st.button("πŸ”™ Go Back to Model Report"):
397
  switch_page("Model Report")
398
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
399
  # Hands-on Model Page
400
  elif st.session_state.current_page == "Hands-on Model":
401
  st.title("Hands-on Model")
 
396
  if st.button("πŸ”™ Go Back to Model Report"):
397
  switch_page("Model Report")
398
 
399
+
400
+ # Model Building
401
+ elif st.session_state.current_page == "Model Building":
402
+ st.markdown("<h2 style='text-align: center;'>Model Building</h2>", unsafe_allow_html=True)
403
+
404
+ # Introduction
405
+ st.markdown("""
406
+ <h5>πŸ“Œ Introduction</h5>
407
+ In this section, we explore different **Ensemble Learning** techniques to improve model performance.
408
+ We implemented three ensemble models:
409
+ - πŸ† <b>Voting Regressor</b>
410
+ - 🎯 <b>Bagging Regressor</b>
411
+ - 🌲 <b>Random Forest Regressor</b>
412
+ """, unsafe_allow_html=True)
413
+ st.markdown("<br>", unsafe_allow_html=True)
414
+
415
+ # Voting Regressor
416
+ st.markdown("""
417
+ <h5>1️⃣ Voting Regressor</h5>
418
+ πŸ”Ή **Concept:** Combines multiple models (**KNN & Decision Tree**) and takes the **average prediction**.
419
+ πŸ”Ή **Why Voting Regressor?**
420
+ - βœ… Works well when models have different strengths.
421
+ - βœ… Reduces variance while maintaining interpretability.
422
+ """, unsafe_allow_html=True)
423
+ st.markdown("<br>", unsafe_allow_html=True)
424
+
425
+ # Bagging Regressor
426
+ st.markdown("""
427
+ <h5>2️⃣ Bagging Regressor</h5>
428
+ πŸ”Ή **Concept:** Uses **bootstrap sampling** to train multiple models on different subsets of data.
429
+ πŸ”Ή **Why Bagging Regressor?**
430
+ - βœ… Reduces overfitting by averaging multiple models.
431
+ - βœ… Works best with **high-variance models** like Decision Tree.
432
+ """, unsafe_allow_html=True)
433
+ st.markdown("<br>", unsafe_allow_html=True)
434
+
435
+ # Random Forest Regressor
436
+ st.markdown("""
437
+ <h5>3️⃣ Random Forest Regressor</h5>
438
+ πŸ”Ή **Concept:**
439
+ - Uses **multiple Decision Trees**, trained on different feature subsets.
440
+ - The final prediction is the **average of all tree predictions**.
441
+ πŸ”Ή **Why Random Forest?**
442
+ - βœ… Handles **non-linearity** well.
443
+ - βœ… Less prone to overfitting compared to a single Decision Tree.
444
+ """, unsafe_allow_html=True)
445
+ st.markdown("<br>", unsafe_allow_html=True)
446
+
447
+ st.markdown("""
448
+ <h5>βš–οΈ Combining High & Low Variance Models</h5>
449
+ A crucial step to improve ensemble performance is **choosing models with different variance levels:**
450
+ - **Voting Regressor:** Uses a combination of **high-variance (Decision Tree, KNN with small K)** and **low-variance (KNN with large K, Decision Tree with depth constraint)** models.
451
+ - **Bagging & Random Forest:** Use **only high-variance models** (Decision Trees with deep splits) to maximize variance reduction.
452
+
453
+ This technique helps create a **balanced ensemble**, preventing excessive overfitting or underfitting! βœ…
454
+ """, unsafe_allow_html=True)
455
+
456
+ st.markdown("<br>", unsafe_allow_html=True)
457
+
458
+ # Hyperparameter Tuning
459
+ st.markdown("""
460
+ <h5>⚑ Hyperparameter Tuning using Optuna</h5>
461
+ We optimized hyperparameters for **KNN, Decision Tree, Bagging Regressor, and Random Forest** using **Optuna**.
462
+ Below are the **optimized parameters** for each model:
463
+
464
+ ### **πŸ”Ή K-Nearest Neighbors (KNN)**
465
+ - `n_neighbors`
466
+ - `p` (Distance metric)
467
+ - `weights`
468
+ - `algorithm`
469
+
470
+ ### **πŸ”Ή Decision Tree**
471
+ - `max_depth`
472
+ - `min_samples_split`
473
+ - `min_samples_leaf`
474
+ - `max_features`
475
+ - `min_impurity_decrease`
476
+
477
+ ### **πŸ”Ή Bagging Regressor**
478
+ - `n_estimators`: 10 to 50
479
+ - `max_samples`: 0.7 to 0.9
480
+
481
+ ### **πŸ”Ή Random Forest**
482
+ - `n_estimators`: 10 to 50
483
+ - `max_samples`: 0.7 to 0.9
484
+ """, unsafe_allow_html=True)
485
+ st.markdown("<br>", unsafe_allow_html=True)
486
+
487
+ # Model Performance Insights
488
+ st.markdown("""
489
+ <h5>πŸ“Š Model Performance Insights</h5>
490
+ st.markdown("<br>", unsafe_allow_html=True)
491
+
492
+ # Model Performance Table
493
+ st.markdown("""
494
+ <style>
495
+ table {
496
+ width: 100%;
497
+ border-collapse: collapse;
498
+ text-align: center;
499
+ }
500
+ th, td {
501
+ padding: 10px;
502
+ border-bottom: 1px solid #ddd;
503
+ }
504
+ </style>
505
+ <table>
506
+ <tr>
507
+ <th>Ensemble</th>
508
+ <th>Training Score</th>
509
+ <th>Test Score</th>
510
+ <th>Generalized Score</th>
511
+ </tr>
512
+ <tr>
513
+ <td>Voting Ensemble</td>
514
+ <td>95.8027%</td>
515
+ <td>92.1368%</td>
516
+ <td>92.89%</td>
517
+ </tr>
518
+ <tr>
519
+ <td>Bagging Ensemble</td>
520
+ <td>98.6861%</td>
521
+ <td>95.0407%</td>
522
+ <td>95.45%</td>
523
+ </tr>
524
+ <tr>
525
+ <td>Random Forest</td>
526
+ <td>97.9244%</td>
527
+ <td>97.9244%</td>
528
+ <td><b>94.71%</b></td>
529
+ </tr>
530
+ </table>
531
+ """, unsafe_allow_html=True)
532
+ st.markdown("<br>", unsafe_allow_html=True)
533
+
534
+ # Choosing the Best Model
535
+ st.markdown("""
536
+ <h5>πŸ† Choosing the Best Model</h5>
537
+ - We checked for **overfitting** (high training accuracy, low test accuracy).
538
+ - We avoided **underfitting** (low training and test accuracy).
539
+ - The best model had a **balanced performance across training and test data**.
540
+
541
+ βœ… **Final Choice: Bagging Ensemble** due to its strong generalization ability! πŸš€
542
+ """, unsafe_allow_html=True)
543
+
544
+
545
  # Hands-on Model Page
546
  elif st.session_state.current_page == "Hands-on Model":
547
  st.title("Hands-on Model")