sree4411 commited on
Commit
9dd58c8
Β·
verified Β·
1 Parent(s): 30eefb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -27
app.py CHANGED
@@ -4,7 +4,7 @@ st.set_page_config(page_title="ML Performance Metrics", layout="wide")
4
 
5
  # Title
6
  st.title("πŸ“Š Machine Learning Performance Metrics")
7
- st.markdown("Understand key metrics used to evaluate ML models β€” for both **classification** and **regression** problems.")
8
 
9
  st.markdown("---")
10
 
@@ -14,60 +14,78 @@ tab1, tab2 = st.tabs(["🧠 Classification Metrics", "πŸ“ˆ Regression Metrics"])
14
  # ======================== CLASSIFICATION ========================
15
  with tab1:
16
  st.header("🧠 Classification Metrics")
17
- st.markdown("These metrics evaluate how well a model classifies input data into distinct categories.")
 
 
 
 
 
 
 
 
 
18
 
19
  with st.expander("🎯 Accuracy"):
20
  st.latex(r"Accuracy = \frac{TP + TN}{TP + TN + FP + FN}")
21
- st.markdown("Proportion of correct predictions out of all predictions.")
22
- st.info("βœ”οΈ Best used when classes are balanced.")
23
 
24
  with st.expander("🎯 Precision"):
25
  st.latex(r"Precision = \frac{TP}{TP + FP}")
26
- st.markdown("How many predicted positives are actually correct?")
27
- st.info("βœ”οΈ Important when False Positives are costly (e.g., spam detection).")
28
 
29
- with st.expander("🎯 Recall (Sensitivity)"):
30
  st.latex(r"Recall = \frac{TP}{TP + FN}")
31
- st.markdown("How many actual positives did we correctly predict?")
32
- st.info("βœ”οΈ Critical when False Negatives are costly (e.g., disease detection).")
 
 
 
 
 
33
 
34
  with st.expander("🎯 F1 Score"):
35
  st.latex(r"F1 = 2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}")
36
- st.markdown("Harmonic mean of precision and recall.")
37
- st.info("βœ”οΈ Good balance when you need both precision and recall.")
38
-
39
- with st.expander("🎯 ROC-AUC Score"):
40
- st.markdown("Area under the ROC curve β€” plots **True Positive Rate** vs **False Positive Rate**.")
41
- st.image("https://upload.wikimedia.org/wikipedia/commons/6/6b/Roccurves.png", caption="ROC Curves Example",use_container_width=True)
42
- st.info("βœ”οΈ Best when evaluating probabilistic classifiers.")
 
 
 
 
43
 
44
  st.markdown("---")
45
- st.success("πŸ“Œ Tip: Always use multiple metrics for a complete performance picture.")
46
 
47
  # ======================== REGRESSION ========================
48
  with tab2:
49
  st.header("πŸ“ˆ Regression Metrics")
50
- st.markdown("These metrics evaluate how well a model predicts continuous numerical values.")
51
 
52
  with st.expander("🎯 Mean Absolute Error (MAE)"):
53
  st.latex(r"MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|")
54
- st.markdown("Average of absolute differences between actual and predicted values.")
55
- st.info("βœ”οΈ Less sensitive to outliers.")
56
 
57
  with st.expander("🎯 Mean Squared Error (MSE)"):
58
  st.latex(r"MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2")
59
- st.markdown("Average of squared differences. Penalizes larger errors more.")
60
- st.info("βœ”οΈ Good for highlighting large deviations.")
61
 
62
  with st.expander("🎯 Root Mean Squared Error (RMSE)"):
63
  st.latex(r"RMSE = \sqrt{MSE}")
64
- st.markdown("Square root of MSE. Same units as target variable.")
65
- st.info("βœ”οΈ Interpretable on the same scale as the original data.")
66
 
67
  with st.expander("🎯 RΒ² Score (Coefficient of Determination)"):
68
  st.latex(r"R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}")
69
- st.markdown("Measures proportion of variance explained by the model.")
70
- st.info("βœ”οΈ Ranges from 0 to 1. Closer to 1 means better model.")
71
 
72
  st.markdown("---")
73
- st.success("πŸ“Œ Tip: Use MAE when you care about average error, and RMSE when you want to penalize large errors.")
 
4
 
5
  # Title
6
  st.title("πŸ“Š Machine Learning Performance Metrics")
7
+ st.markdown("Learn how to evaluate ML models for both **classification** and **regression** problems with detailed explanations, formulas, and tips.")
8
 
9
  st.markdown("---")
10
 
 
14
  # ======================== CLASSIFICATION ========================
15
  with tab1:
16
  st.header("🧠 Classification Metrics")
17
+ st.markdown("Classification metrics help evaluate how well your model predicts categories or labels.")
18
+
19
+ with st.expander("πŸ” Understanding TP, TN, FP, FN"):
20
+ st.markdown("""
21
+ - **True Positive (TP)**: Model predicted Positive and it was actually Positive
22
+ - **True Negative (TN)**: Model predicted Negative and it was actually Negative
23
+ - **False Positive (FP)**: Model predicted Positive but it was actually Negative (Type I Error)
24
+ - **False Negative (FN)**: Model predicted Negative but it was actually Positive (Type II Error)
25
+ """)
26
+ st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/2/26/Precisionrecall.svg/1200px-Precisionrecall.svg.png", caption="TP, FP, TN, FN Overview", use_column_width=True)
27
 
28
  with st.expander("🎯 Accuracy"):
29
  st.latex(r"Accuracy = \frac{TP + TN}{TP + TN + FP + FN}")
30
+ st.markdown("**How often the model is correct overall.**")
31
+ st.info("βœ”οΈ Best when classes are balanced. Can be misleading for imbalanced datasets.")
32
 
33
  with st.expander("🎯 Precision"):
34
  st.latex(r"Precision = \frac{TP}{TP + FP}")
35
+ st.markdown("**Out of all predicted positives, how many were actually positive?**")
36
+ st.info("βœ”οΈ Use when False Positives are costly (e.g., spam detection).")
37
 
38
+ with st.expander("🎯 Recall (Sensitivity / True Positive Rate)"):
39
  st.latex(r"Recall = \frac{TP}{TP + FN}")
40
+ st.markdown("**Out of all actual positives, how many were correctly predicted?**")
41
+ st.info("βœ”οΈ Use when False Negatives are costly (e.g., disease diagnosis).")
42
+
43
+ with st.expander("🎯 Specificity (True Negative Rate)"):
44
+ st.latex(r"Specificity = \frac{TN}{TN + FP}")
45
+ st.markdown("**How many actual negatives were correctly predicted as negative?**")
46
+ st.info("βœ”οΈ Important when you also care about negatives being classified correctly.")
47
 
48
  with st.expander("🎯 F1 Score"):
49
  st.latex(r"F1 = 2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}")
50
+ st.markdown("**Balances both Precision and Recall.**")
51
+ st.info("βœ”οΈ Useful when there's an uneven class distribution.")
52
+
53
+ with st.expander("🎯 ROC Curve & AUC"):
54
+ st.markdown("""
55
+ - **ROC Curve** plots the **True Positive Rate (Recall)** vs **False Positive Rate**.
56
+ - **AUC** (Area Under the Curve) measures how well the model separates the classes.
57
+ - AUC ranges from 0 to 1. Closer to 1 = better.
58
+ """)
59
+ st.image("https://upload.wikimedia.org/wikipedia/commons/6/6b/Roccurves.png", caption="ROC Curves Example", use_column_width=True)
60
+ st.info("βœ”οΈ Best for evaluating probabilistic classifiers.")
61
 
62
  st.markdown("---")
63
+ st.success("πŸ“Œ Tip: Use **F1 Score** or **ROC-AUC** in imbalanced classification problems!")
64
 
65
  # ======================== REGRESSION ========================
66
  with tab2:
67
  st.header("πŸ“ˆ Regression Metrics")
68
+ st.markdown("Regression metrics help evaluate how well your model predicts **continuous numeric values**.")
69
 
70
  with st.expander("🎯 Mean Absolute Error (MAE)"):
71
  st.latex(r"MAE = \frac{1}{n} \sum_{i=1}^{n} |y_i - \hat{y}_i|")
72
+ st.markdown("**Average absolute difference** between predicted and actual values.")
73
+ st.info("βœ”οΈ Easy to understand. Less sensitive to outliers.")
74
 
75
  with st.expander("🎯 Mean Squared Error (MSE)"):
76
  st.latex(r"MSE = \frac{1}{n} \sum_{i=1}^{n} (y_i - \hat{y}_i)^2")
77
+ st.markdown("**Average of squared differences** between predicted and actual values.")
78
+ st.info("βœ”οΈ Penalizes large errors more than MAE.")
79
 
80
  with st.expander("🎯 Root Mean Squared Error (RMSE)"):
81
  st.latex(r"RMSE = \sqrt{MSE}")
82
+ st.markdown("**Square root of MSE**. Same unit as the target variable.")
83
+ st.info("βœ”οΈ More interpretable. Heavily penalizes large errors.")
84
 
85
  with st.expander("🎯 RΒ² Score (Coefficient of Determination)"):
86
  st.latex(r"R^2 = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2}")
87
+ st.markdown("**Proportion of variance in the target explained by the model.**")
88
+ st.info("βœ”οΈ Closer to 1 = better fit. Can be negative if model is worse than a mean predictor.")
89
 
90
  st.markdown("---")
91
+ st.success("πŸ“Œ Tip: Use **MAE** for average error insights, **RMSE** for large error sensitivity, and **RΒ²** for overall model fit.")