One-class SVM outlier

更新时间:
复制 MD 格式

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

ParameterDescription
featureColsThe names of the feature columns (array).
groupColsThe names of the group columns (array).
tensorColThe tensor column.
vectorColThe name of the vector column.

Parameter setting

ParameterDescriptionDefault
Prediction Result ColumnThe name of the prediction result column.
kernelTypeThe kernel function type. Valid values: RBF, POLY, SIGMOID, LINEAR.
nuThe nu parameter of the kernel function. This parameter is positively correlated with the number of support vectors. Valid values: (0, 1).0.01
gammaThe kernel coefficient for RBF, POLY, and SIGMOID kernels. If not set, the value 1/data dimension is used.-1.0
coef0The independent term in the kernel function. Applies only to POLY and SIGMOID kernels.0.0
degreeThe degree of the polynomial. Applies only to the POLY kernel.
epsilonThe value that you want to obtain from the training results before the iteration stops.1.0E-6
maxOutlierRatioThe maximum ratio of outliers the algorithm detects.
outlierThresholdData points with a score exceeding this threshold are classified as anomalous.
maxOutlierNumPerGroupThe maximum number of outliers per group.
maxSampleNumPerGroupThe maximum number of samples per group.
Column name of detail prediction informationThe name of the prediction details column.
numThreadsThe number of threads for the component.

Execute tuning

ParameterDescriptionValid values
Number of WorkersThe number of worker nodes. Must be set together with Memory per worker.Positive integer, 1–9999
Memory per workerThe 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

ParameterRequiredDescriptionDefault
predictionColYesThe name of the prediction result column.
featureColsNoThe names of the feature columns (array).Select all
groupColsNoThe names of the group columns (array).
kernelTypeNoThe kernel function type. Valid values: RBF, POLY, SIGMOID, LINEAR.RBF
nuNoThe nu parameter of the kernel function. This parameter is positively correlated with the number of support vectors. Valid values: (0, 1).0.01
gammaNoThe kernel coefficient for RBF, POLY, and SIGMOID kernels. If not set, 1/data dimension is used.-1.0
coef0NoThe independent term in the kernel function. Applies only to POLY and SIGMOID kernels.0.0
degreeNoThe degree of the polynomial. Applies only to the POLY kernel.2
epsilonNoThe value that you want to obtain from the training results before the iteration stops.1.0E-6
maxOutlierRatioNoThe maximum ratio of outliers detected by the algorithm.
outlierThresholdNoData points with a score exceeding this threshold are classified as anomalous.
maxOutlierNumPerGroupNoThe maximum number of outliers per group.
maxSampleNumPerGroupNoThe maximum number of samples per group.
predictionDetailColNoThe name of the prediction details column.
tensorColNoThe name of the tensor column.
vectorColNoThe name of the vector column.
numThreadsNoThe 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()