One-Class Support Vector Machine (SVM) is an unsupervised machine learning algorithm that is different from traditional SVM algorithms. When your dataset consists of only normal samples and you need to flag new observations that deviate from learned patterns, use the One-Class SVM Outlier component. It trains a decision boundary on a single class of data, then classifies points outside that boundary as outliers.
Supported computing resources
The One-Class SVM Outlier component runs on MaxCompute computing resources only.
Configure the component
Two methods are available: visual configuration in the PAI console, or Python code via PyAlink.
Method 1: Configure in the PAI console
On the pipeline page of Machine Learning Designer, configure the component parameters across three tabs.
Field setting
| Parameter | Description |
|---|---|
featureCols | The names of the feature columns (array). |
groupCols | The names of the group columns (array). |
tensorCol | The tensor column. |
vectorCol | The name of the vector column. |
Parameter setting
| Parameter | Description | Default |
|---|---|---|
| Prediction Result Column | The name of the prediction result column. | — |
kernelType | The kernel function type. Valid values: RBF, POLY, SIGMOID, LINEAR. | — |
nu | The nu parameter of the kernel function. This parameter is positively correlated with the number of support vectors. Valid values: (0, 1). | 0.01 |
gamma | The kernel coefficient for RBF, POLY, and SIGMOID kernels. If not set, the value 1/data dimension is used. | -1.0 |
coef0 | The independent term in the kernel function. Applies only to POLY and SIGMOID kernels. | 0.0 |
degree | The degree of the polynomial. Applies only to the POLY kernel. | — |
epsilon | The value that you want to obtain from the training results before the iteration stops. | 1.0E-6 |
maxOutlierRatio | The maximum ratio of outliers the algorithm detects. | — |
outlierThreshold | Data points with a score exceeding this threshold are classified as anomalous. | — |
maxOutlierNumPerGroup | The maximum number of outliers per group. | — |
maxSampleNumPerGroup | The maximum number of samples per group. | — |
| Column name of detail prediction information | The name of the prediction details column. | — |
numThreads | The number of threads for the component. | — |
Execute tuning
| Parameter | Description | Valid values |
|---|---|---|
| Number of Workers | The number of worker nodes. Must be set together with Memory per worker. | Positive integer, 1–9999 |
| Memory per worker | The memory allocated to each worker node, in MB. | Positive integer, 1024–65536 |
Method 2: Configure using Python
Use the PyAlink Script component to configure the One-Class SVM Outlier component with OcsvmOutlierBatchOp().
Parameters
| Parameter | Required | Description | Default |
|---|---|---|---|
predictionCol | Yes | The name of the prediction result column. | — |
featureCols | No | The names of the feature columns (array). | Select all |
groupCols | No | The names of the group columns (array). | — |
kernelType | No | The kernel function type. Valid values: RBF, POLY, SIGMOID, LINEAR. | RBF |
nu | No | The nu parameter of the kernel function. This parameter is positively correlated with the number of support vectors. Valid values: (0, 1). | 0.01 |
gamma | No | The kernel coefficient for RBF, POLY, and SIGMOID kernels. If not set, 1/data dimension is used. | -1.0 |
coef0 | No | The independent term in the kernel function. Applies only to POLY and SIGMOID kernels. | 0.0 |
degree | No | The degree of the polynomial. Applies only to the POLY kernel. | 2 |
epsilon | No | The value that you want to obtain from the training results before the iteration stops. | 1.0E-6 |
maxOutlierRatio | No | The maximum ratio of outliers detected by the algorithm. | — |
outlierThreshold | No | Data points with a score exceeding this threshold are classified as anomalous. | — |
maxOutlierNumPerGroup | No | The maximum number of outliers per group. | — |
maxSampleNumPerGroup | No | The maximum number of samples per group. | — |
predictionDetailCol | No | The name of the prediction details column. | — |
tensorCol | No | The name of the tensor column. | — |
vectorCol | No | The name of the vector column. | — |
numThreads | No | The number of threads for the component. | 1 |
Example
The following example trains a One-Class SVM model on a dataset with four numeric features, using an RBF kernel with gamma=0.5 and nu=0.1.
import pandas as pd
from pyalink.alink import *
df = pd.DataFrame([
[0.730967787376657, 0.24053641567148587, 0.6374174253501083, 0.5504370051176339],
[0.7308781907032909, 0.41008081149220166, 0.20771484130971707, 0.3327170559595112],
[0.7311469360199058, 0.9014476240300544, 0.49682259343089075, 0.9858769332362016],
[0.731057369148862, 0.07099203475193139, 0.06712000939049956, 0.768156984078079],
[0.7306094602878371, 0.9187140138555101, 0.9186071189908658, 0.6795571637816596],
[0.730519863614471, 0.08825840967622589, 0.4889045498516358, 0.461837214623537],
[0.7307886238322471, 0.5796252073129174, 0.7780122870716483, 0.11499709190022733],
[0.7306990420600421, 0.7491696031336331, 0.34830970303125697, 0.8972771427421047],
])
# Load data with schema
data = BatchOperator.fromDataframe(df, schemaStr="x1 double, x2 double, x3 double, x4 double")
# Run One-Class SVM outlier detection
OcsvmOutlierBatchOp() \
.setFeatureCols(["x1", "x2", "x3", "x4"]) \
.setGamma(0.5) \
.setNu(0.1) \
.setKernelType("RBF") \
.setPredictionCol("pred") \
.linkFrom(data) \
.print()