Indhu27/MachineLearning_Algorithms
0
1import streamlit as st2 3st.set_page_config(page_title="Perfomance", page_icon="🤖", layout="wide")4st.markdown("""5 <style>6 .stApp {7 background-color: #4A90E2;8 }9 h1, h2, h3 {10 color: #003366; /* Adjust this if needed to match your background */11 }12 .custom-font, p {13 font-family: 'Arial', sans-serif;14 font-size: 18px;15 color: white; /* Making all inside text white */16 line-height: 1.6;17 }18 </style>19 """, unsafe_allow_html=True)20 21st.markdown("<h1 style='color: #003366'>Performance Metrics in Machine Learning</h1>",unsafe_allow_html=True)22 23def main():24 st.write("Performance metrics help evaluate how well a machine learning model is performing. They vary depending on whether the model is for classification or regression.")25 st.image("metrics.png",width=700)26 27 st.markdown("</h2 style='color:#003366;'>Classification Metrics</h2>",unsafe_allow_html=True)28 st.write("### 1. Accuracy")29 st.write("Accuracy is the ratio of correctly predicted instances to the total instances.")30 st.image("accuracy.png",width=400)31 st.write("Example: If a model correctly classifies 90 out of 100 samples, accuracy is 90%.")32 st.write("Dont use accuracy when your data having imbalance and when your prediction is probability score")33 34 st.write("### 2. Confusion Matrix")35 st.write("A confusion matrix helps in visualizing classification performance.")36 st.write("#### Example Confusion Matrix:")37 st.image("classification.png",width=500)38 st.write("confussion matrix will work well on imbalance data. But we cant use confussion metrix if our prediction is probability score")39 40 st.write("### 3. Precision")41 st.write("""Precision measures the accuracy of positive predictions. It means how many positive classes have been correctly classified by the maodel from total positive class it has predicted42 - The Precision lies between [0-1] 0 means bad model , 1 means good model""")43 st.image("precission.png",width=400)44 45 st.write("### 3. Recall")46 st.write("""Recall measures how well the model identifies positive instances. It means how many positive class have been correctly classified by the model from total actual positive class47 - The recall lies between [0-1] 0 means bad model , 1 means good model""")48 st.image("recall.png",width=400)49 st.write("Example: If TP=80, FP=20, FN=10, then Precision = 80/100 = 0.8 and Recall = 80/90 = 0.89.")50 51 52 st.write("### 4. F1 Score")53 st.write("F1 Score is the harmonic mean of Precision and Recall.If F1 score is high then the model is good model")54 st.image("F1score.jpg",width=400)55 56 57 st.write("### 5. ROC Curve and AUC")58 st.write("The ROC curve plots True Positive Rate (TPR) against False Positive Rate (FPR). AUC represents the area under this curve.")59 st.image("auc-Roc.png",width=600)60 61 st.write("### 6. Log-Loss")62 st.write("Log Loss evaluates classification models by penalizing incorrect predictions with their probability scores.")63 st.image("Log-loss.png",width=600)64 st.write("Lower log loss means better predictions.")65 st.write("""66 - use when your prediction is probability score67 - Loss starts from 0 it means perfect model but it can go infinity so we dont have maximum treshold value so to know is your model better or not compare with dumb model if your loss is greater than dumb model then your model is worest.If it is less than the dumb model than your model is better than dumb model68 """)69 70 st.markdown("<h2 style='color: #003366'>Regression Metrics</h2>",unsafe_allow_html=True)71 st.write("### 1. Mean Squared Error (MSE)")72 st.write("Measures the average squared difference between actual and predicted values.")73 st.image("mse.jpg",width=400)74 75 st.write("### 2. Mean Absolute Error (MAE)")76 st.write("Measures the average absolute difference between actual and predicted values.")77 st.image("mae.png",width=400)78 79 st.write("### 3. Root Mean Squared Error (RMSE)")80 st.write("RMSE is the square root of MSE, providing an error metric in the same unit as the target variable.")81 st.image("rmse.png",width=400)82 83 st.write("### 4. R-Squared (R²)")84 st.write("Represents how well the model explains variance in the target variable.")85 st.image("r2score.png",width=400)86 st.write("Where SSR is the sum of squared residuals and SST is the total sum of squares.")87 st.write("""88 **Cases Interpretation:**89 - **R² = 1** → Perfect model.90 - **0 < R² < 1** → Good model but not perfect.91 - **R² = 0** → Model is as good as predicting the mean.92 - **R² < 0** → Model is worse than a simple mean predictor.93 """)94 95 96 st.write("""97 - Choosing the right metric is crucial in machine learning evaluation:98 - For **classification**, use **F1-score**, **Log Loss**, and **Confusion Matrix**.99 - For **regression**, prefer **R² Score** and **MAE/MSE**.100 - **Consider data imbalance** before choosing accuracy.By understanding these metrics, we can make informed decisions about model performance and improvements!101 """)102 103if __name__ == "__main__":104 main()105 