Machine_Learning_Algorithims / pages /7Perfomancemetrix.py
Sathwikchowdary's picture
Create 7Perfomancemetrix.py
26d1e85 verified
import streamlit as st
# Page configuration
st.set_page_config(page_title="Performance Metrics", page_icon="🤖", layout="wide")
# Custom CSS for styling with updated colors
st.markdown("""
<style>
.stApp {
background-color: #FFFAF0; /* Light floral white background */
}
h1, h2, h3 {
color: #8B0000; /* Deep red headings for contrast */
}
.custom-font, p {
font-family: 'Arial', sans-serif;
font-size: 18px;
color: #333333; /* Dark gray text for readability */
line-height: 1.6;
}
</style>
""", unsafe_allow_html=True)
# Main title for the page
st.markdown("<h1 style='color: #8B0000;'>Performance Metrics in Machine Learning</h1>", unsafe_allow_html=True)
def main():
# Introductory explanation
st.write("Evaluating a machine learning model requires clear performance metrics. These metrics differ based on whether you're dealing with a classification or regression problem.")
st.image("metrics.png", width=700)
# Classification Metrics Section
st.markdown("<h2 style='color: #8B0000;'>Classification Metrics</h2>", unsafe_allow_html=True)
st.write("### 1. Accuracy")
st.write("Accuracy measures the proportion of correctly predicted examples out of all predictions.")
st.image("accuracy.png", width=400)
st.write("For instance, if a model correctly classifies 90 out of 100 cases, its accuracy is 90%. However, note that accuracy might not be ideal for imbalanced datasets or when the output is a probability score.")
st.write("### 2. Confusion Matrix")
st.write("A confusion matrix is a tabular summary that provides insight into the performance of a classification model. It shows the counts of true positives, false positives, true negatives, and false negatives.")
st.write("#### Example Confusion Matrix:")
st.image("classification.png", width=500)
st.write("This tool is particularly useful for imbalanced classes. Yet, if your model produces probability scores rather than discrete classes, a confusion matrix might not be applicable.")
st.write("### 3. Precision")
st.write("""Precision quantifies the accuracy of positive predictions. It represents the fraction of positive predictions that are actually correct.
- Precision values range between 0 and 1 (0 indicating poor performance and 1 indicating excellent performance).
""")
st.image("precission.png", width=400)
st.write("### 4. Recall")
st.write("""Recall (also known as sensitivity) gauges the model's ability to identify all relevant positive cases. It is defined as the number of true positives divided by the sum of true positives and false negatives.
- Like precision, recall values range from 0 to 1.
""")
st.image("recall.png", width=400)
st.write("For example, if the model has 80 true positives, 20 false positives, and 10 false negatives, then Precision = 80/100 = 0.8 and Recall = 80/90 ≈ 0.89.")
st.write("### 5. F1 Score")
st.write("The F1 Score is the harmonic mean of precision and recall, providing a single metric for model performance. A high F1 score indicates a balanced performance in terms of both precision and recall.")
st.image("F1score.jpg", width=400)
st.write("### 6. ROC Curve and AUC")
st.write("The ROC curve displays the relationship between the True Positive Rate (TPR) and False Positive Rate (FPR) as the decision threshold varies. The AUC (Area Under the Curve) quantifies the overall performance of the model; the closer the AUC is to 1, the better.")
st.image("auc-Roc.png", width=600)
st.write("### 7. Log-Loss")
st.write("Log Loss measures the performance of a classification model by penalizing false classifications based on the predicted probabilities. A lower log-loss indicates more accurate probability estimates.")
st.image("Log-loss.png", width=600)
st.write("""
- It is best used when your model outputs probability scores.
- A perfect model would have a log loss of 0. However, because it can theoretically range up to infinity, it's best to compare against a baseline (or 'dumb') model.
""")
# Regression Metrics Section
st.markdown("<h2 style='color: #8B0000;'>Regression Metrics</h2>", unsafe_allow_html=True)
st.write("### 1. Mean Squared Error (MSE)")
st.write("MSE measures the average of the squared differences between the actual and predicted values.")
st.image("mse.jpg", width=400)
st.write("### 2. Mean Absolute Error (MAE)")
st.write("MAE calculates the average of the absolute differences between the actual values and the model's predictions.")
st.image("mae.png", width=400)
st.write("### 3. Root Mean Squared Error (RMSE)")
st.write("RMSE is the square root of MSE, providing an error metric in the same unit as the target variable.")
st.image("rmse.png", width=400)
st.write("### 4. R-Squared (R²)")
st.write("R² indicates the proportion of variance in the target variable that the model explains.")
st.image("r2score.png", width=400)
st.write("It is computed based on the sum of squared residuals (SSR) and the total sum of squares (SST).")
st.write("""
**Interpretation:**
- **R² = 1:** Perfect fit.
- **0 < R² < 1:** The model explains some, but not all, of the variance.
- **R² = 0:** The model's predictions are no better than simply using the mean of the target variable.
- **R² < 0:** The model performs worse than the mean predictor.
""")
st.write("""
Selecting the appropriate performance metric is key:
- For **classification**, consider F1 Score, Log Loss, and the Confusion Matrix.
- For **regression**, metrics like R², MAE, and MSE are often more relevant.
- Additionally, consider data imbalance when deciding whether to use Accuracy.
By understanding these metrics, you can make better-informed decisions to improve and evaluate your model.
""")
if __name__ == "__main__":
main()