Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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("
|
| 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("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
with st.expander("π― Accuracy"):
|
| 20 |
st.latex(r"Accuracy = \frac{TP + TN}{TP + TN + FP + FN}")
|
| 21 |
-
st.markdown("
|
| 22 |
-
st.info("βοΈ Best
|
| 23 |
|
| 24 |
with st.expander("π― Precision"):
|
| 25 |
st.latex(r"Precision = \frac{TP}{TP + FP}")
|
| 26 |
-
st.markdown("
|
| 27 |
-
st.info("βοΈ
|
| 28 |
|
| 29 |
-
with st.expander("π― Recall (Sensitivity)"):
|
| 30 |
st.latex(r"Recall = \frac{TP}{TP + FN}")
|
| 31 |
-
st.markdown("
|
| 32 |
-
st.info("βοΈ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
with st.expander("π― F1 Score"):
|
| 35 |
st.latex(r"F1 = 2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}")
|
| 36 |
-
st.markdown("
|
| 37 |
-
st.info("βοΈ
|
| 38 |
-
|
| 39 |
-
with st.expander("π― ROC
|
| 40 |
-
st.markdown("
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
st.markdown("---")
|
| 45 |
-
st.success("π Tip:
|
| 46 |
|
| 47 |
# ======================== REGRESSION ========================
|
| 48 |
with tab2:
|
| 49 |
st.header("π Regression Metrics")
|
| 50 |
-
st.markdown("
|
| 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
|
| 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
|
| 60 |
-
st.info("βοΈ
|
| 61 |
|
| 62 |
with st.expander("π― Root Mean Squared Error (RMSE)"):
|
| 63 |
st.latex(r"RMSE = \sqrt{MSE}")
|
| 64 |
-
st.markdown("Square root of MSE
|
| 65 |
-
st.info("βοΈ
|
| 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("
|
| 70 |
-
st.info("βοΈ
|
| 71 |
|
| 72 |
st.markdown("---")
|
| 73 |
-
st.success("π Tip: Use MAE
|
|
|
|
| 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.")
|