File size: 3,336 Bytes
f1eb840
 
 
3dc553d
f1eb840
 
 
3dc553d
f1eb840
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3dc553d
f1eb840
 
 
 
 
 
 
 
 
 
 
3dc553d
f1eb840
 
 
 
3dc553d
f1eb840
 
 
 
 
 
3dc553d
f1eb840
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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.
""")