import streamlit as st st.set_page_config(page_title="Support Vector Machine", page_icon="๐Ÿง ", layout="wide") # Title st.markdown("

๐Ÿง  Support Vector Machine (SVM)

", unsafe_allow_html=True) # Introduction st.markdown("### ๐Ÿ“š What is SVM?") st.markdown(""" Support Vector Machine (SVM) is a powerful **supervised learning algorithm** used for both **classification** and **regression**, though it is mostly used for classification tasks. The core idea is to find the **optimal hyperplane** that best separates the data points of different classes by maximizing the **margin** between them. """) # Use Cases st.markdown("### ๐ŸŽฏ Where is SVM Used?") st.markdown(""" - Face Recognition - Handwriting Recognition - Bioinformatics (e.g., gene classification) - Email Spam Detection - Image Classification """) # How It Works st.markdown("### โš™๏ธ How Does SVM Work?") with st.expander("๐Ÿ”น Step 1: Find a Hyperplane"): st.markdown(""" A **hyperplane** is a decision boundary that separates the data points of different classes. SVM tries to find the hyperplane that **maximizes the margin** between classes. """) with st.expander("๐Ÿ”น Step 2: Identify Support Vectors"): st.markdown(""" **Support vectors** are the data points that lie closest to the hyperplane. These points are critical in defining the position and orientation of the hyperplane. """) with st.expander("๐Ÿ”น Step 3: Handle Non-Linearly Separable Data"): st.markdown(""" When the data is not linearly separable, SVM uses the **kernel trick** to project it into a higher-dimensional space where it becomes separable. """) # Kernel Functions st.markdown("### ๐Ÿงช Kernels in SVM") with st.expander("๐Ÿ“Œ Common Kernel Functions"): st.markdown(""" - **Linear Kernel**: For linearly separable data - **Polynomial Kernel**: For curved decision boundaries - **RBF (Radial Basis Function)**: Most popular, handles complex data - **Sigmoid Kernel**: Similar to neural networks """) # Mathematical Intuition st.markdown("### ๐Ÿง  Mathematical Formulation") with st.expander("๐Ÿ“Œ Decision Function"): st.latex(r"f(x) = w \cdot x + b") with st.expander("๐Ÿ“Œ Classification Rule"): st.markdown(""" - If \\( f(x) > 0 \\): Predict **Class 1** - If \\( f(x) < 0 \\): Predict **Class 0** """) with st.expander("๐Ÿ“Œ Optimization Objective"): st.latex(r"\text{Maximize Margin} = \frac{2}{\|w\|}") st.markdown("We want to maximize the margin between support vectors and the hyperplane.") with st.expander("๐Ÿ“Œ Soft Margin & C Parameter"): st.latex(r" \min \frac{1}{2} \|w\|^2 + C \sum \xi_i ") st.markdown(""" - The **C parameter** balances margin maximization vs classification error. - A **small C** allows for a wider margin but more errors. - A **large C** aims for perfect classification but might overfit. """) # Evaluation Metrics st.markdown("### ๐Ÿ“ Evaluation Metrics") st.markdown("#### โœ… Accuracy") st.latex(r"Accuracy = \frac{TP + TN}{TP + TN + FP + FN}") st.markdown("The percentage of correct predictions.") st.markdown("#### ๐ŸŽฏ Precision") st.latex(r"Precision = \frac{TP}{TP + FP}") st.markdown("Out of all predicted positives, how many are actually positive?") st.markdown("#### ๐Ÿ“ฃ Recall (Sensitivity)") st.latex(r"Recall = \frac{TP}{TP + FN}") st.markdown("Out of all actual positives, how many did we correctly predict?") st.markdown("#### โš–๏ธ F1 Score") st.latex(r"F1 = 2 \cdot \frac{Precision \cdot Recall}{Precision + Recall}") st.markdown("Balances precision and recall โ€” especially useful in imbalanced datasets.") st.markdown("#### ๐Ÿ“ˆ ROC-AUC") st.markdown(""" - Plots True Positive Rate (TPR) vs False Positive Rate (FPR). - **AUC (Area Under Curve)** closer to 1 indicates a better model. """) # Pros and Cons st.markdown("### โœ… Advantages of SVM") st.markdown(""" - Effective in high-dimensional spaces - Works well even when features > samples - Memory efficient (uses support vectors) - Handles non-linearity with kernels """) st.markdown("### โŒ Limitations of SVM") st.markdown(""" - Not ideal for large datasets (computationally expensive) - Requires careful parameter tuning (C, kernel) - Hard to interpret compared to decision trees """) # Summary st.markdown("### ๐Ÿ”š Summary") st.markdown(""" Support Vector Machine is a **robust**, **flexible**, and **accurate** classification algorithm. Great for: - Text data - Image recognition - Biomedical data Make sure to: - Scale your features - Use kernel wisely - Tune the **C** and **gamma** parameters โœ… Powerful for **both linear and non-linear** decision boundaries! """)