import streamlit as st import pandas as pd st.set_page_config(page_title="ML Model Explorer") st.title("๐Ÿค– Support Vector Machine (SVM) - In Depth") st.markdown(""" Support Vector Machine (SVM) is a **supervised learning algorithm** used for both **classification** and **regression** tasks. It finds the optimal hyperplane that best separates data points of different classes (in classification) or fits the best margin for predicting continuous values (in regression). --- ## ๐Ÿ” Key Concepts ### 1. **Hyperplane** A decision boundary that separates different classes. In higher dimensions, it's a plane or manifold. ### 2. **Support Vectors** The data points that are closest to the hyperplane and influence its position. ### 3. **Margin** The distance between the hyperplane and the nearest data points (support vectors). SVM maximizes this margin. --- ## ๐Ÿ“ Mathematical Formulation ### Classification Objective: For a binary classification task with input vector `x`, label `y โˆˆ {-1, 1}`: SVM aims to solve: \[ \min_{w, b} \ \frac{1}{2} \|w\|^2 \quad \text{subject to} \quad y_i(w^T x_i + b) \geq 1 \] ### Regression (SVR) Objective: Support Vector Regression (SVR) aims to find a function that deviates from the actual values by a margin \( \varepsilon \): \[ \min_{w, b} \ \frac{1}{2} \|w\|^2 \quad \text{subject to} \quad |y_i - (w^T x_i + b)| \leq \varepsilon \] --- ## โš™๏ธ SVM Kernels Kernels transform data into higher dimensions to make it linearly separable: - **Linear Kernel**: \( K(x, x') = x^T x' \) - **Polynomial Kernel**: \( K(x, x') = (\gamma x^T x' + r)^d \) - **RBF (Gaussian) Kernel**: \( K(x, x') = \exp(-\gamma \|x - x'\|^2) \) - **Sigmoid Kernel**: \( K(x, x') = \tanh(\gamma x^T x' + r) \) --- ## ๐Ÿ“Š Hyperparameters of SVM (`sklearn.svm.SVC` and `SVR`) | Parameter | Description | |----------------|-------------| | `C` | Regularization parameter. High value = low bias, high variance | | `kernel` | Type of kernel function (linear, poly, rbf, sigmoid) | | `degree` | Degree for polynomial kernel | | `gamma` | Kernel coefficient for 'rbf', 'poly', and 'sigmoid' | | `coef0` | Independent term in kernel function (used with 'poly' and 'sigmoid') | | `epsilon` | (SVR only) Epsilon-tube within which no penalty is associated | | `shrinking` | Whether to use shrinking heuristic | | `probability` | Enable probability estimates (slower) | --- ### ๐Ÿงช Hyperparameter Tuning with Optuna (Conceptual) Optuna can help optimize: - `C` and `gamma` values - Kernel type - `degree` and `coef0` for poly/sigmoid kernels - Cross-validation scores (accuracy, RMSE) Optuna uses **Bayesian Optimization** to efficiently explore the parameter space. --- ### โœ… Advantages - Effective in high-dimensional spaces - Memory efficient (uses support vectors only) - Works with nonlinear data using kernels ### ๐Ÿšซ Limitations - Not suitable for very large datasets - Choosing the right kernel and parameters can be tricky - Less interpretable compared to tree-based models --- ### ๐Ÿ’ก Real-World Applications - Email spam detection - Image classification - Stock price prediction (SVR) - Face and handwriting recognition ๐Ÿ“Œ **Tip**: Always scale features (e.g., StandardScaler) before using SVM for optimal performance. """)