Phaneendrabayi's picture
Update pages/SVM_Algorithm.py
3dc553d verified
Raw History Blame Contribute Delete
3.34 kB
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.
""")