-
Notifications
You must be signed in to change notification settings - Fork 0
/
one_class_svm.py
35 lines (28 loc) · 1.42 KB
/
one_class_svm.py
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
"""
one_class_svm.py
This module defines a One-Class SVM model for anomaly detection.
One-Class SVM identifies a decision boundary that separates normal data points from potential outliers
in a high-dimensional feature space.
Key Features:
- Effective for detecting anomalies in high-dimensional datasets.
- Flexible kernel options for nonlinear decision boundaries.
- Suitable for datasets with a small proportion of outliers.
Parameters:
- kernel (str): Specifies the kernel type used in the algorithm.
- Common options: 'linear', 'poly', 'rbf' (default), and 'sigmoid'.
- gamma (str or float): Kernel coefficient. Determines the influence of each sample.
- Default: 'scale' (1 / (n_features * X.var())).
- nu (float): Approximate fraction of outliers in the dataset.
- Must be in the range (0, 1]. Default: 0.05 (5% of data considered outliers).
Default Configuration:
- kernel='rbf': Radial Basis Function for nonlinear separation.
- gamma='scale': Automatically adjusts kernel influence based on dataset features.
- nu=0.05: Assumes approximately 5% of data points are outliers.
"""
from sklearn.svm import OneClassSVM
# Define the One-Class SVM estimator
estimator = OneClassSVM(
kernel='rbf', # Radial Basis Function kernel for nonlinear boundaries
gamma='scale', # Adjusts kernel influence based on dataset variance
nu=0.05 # Assumes 5% of the data are outliers
)