All Products
Search
Document Center

Platform For AI:LOF outlier

Last Updated:Apr 01, 2026

The LOF Outlier component detects anomalous data points in a dataset using the Local Outlier Factor (LOF) algorithm. LOF measures the local density deviation of a data point relative to its neighbors: points in sparse regions score higher than those in dense regions, and points with scores exceeding your configured outlierThreshold are flagged as outliers.

Use this component when your data may contain noise or anomalous records that should be identified before downstream processing — such as fraud detection, sensor fault detection, or data quality filtering.

Limits

The LOF Outlier component supports only MaxCompute computing resources.

Configure the LOF Outlier component

You can configure the component in the PAI console using Machine Learning Designer, or programmatically using Python code via the PyAlink Script component.

Configure the component in the PAI console

Configure the component on the pipeline canvas in Machine Learning Designer. Parameters are organized across three tabs.

Field Setting tab

ParameterDescription
featureColsThe feature columns used for outlier detection. Accepts multiple column names.
groupColsThe columns used to group data before detection. Outlier detection runs independently within each group. Accepts multiple column names.
tensorColThe tensor column.
vectorColThe vector column.

Parameter Setting tab

ParameterDescriptionDefault
Prediction Result ColumnThe name of the prediction result column.
Distance Measurement MethodThe distance metric used to measure proximity between data points. Valid values: EUCLIDEAN, COSINE, INNERPRODUCT, CITYBLOCK, JACCARD, PEARSON.EUCLIDEAN
maxOutlierNumPerGroupThe maximum number of data points that can be labeled as outliers per group.
maxOutlierRatioThe maximum proportion of data points that can be labeled as outliers.
maxSampleNumPerGroupThe maximum number of samples per group.
numNeighborsThe number of adjacent data points used to compute the LOF score for each point.5
outlierThresholdIf the score exceeds the specified threshold, an outlier is detected.
Column name of detail prediction informationThe name of the prediction details column.
numThreadsThe number of threads for the component.1

Execute Tuning tab

ParameterDescription
Number of WorkersThe number of worker nodes. Valid values: 1–9999. Must be set together with Memory per worker.
Memory per workerThe memory allocated to each worker node, in MB. Valid values: 1024–65536.

Configure the component using Python code

Use the PyAlink Script component to configure the LOF Outlier component programmatically. For more information, see the PyAlink script documentation.

Parameters

ParameterRequiredDescriptionDefault
predictionColYesThe name of the prediction results column.
distanceTypeNoThe distance metric. Valid values: EUCLIDEAN, COSINE, INNERPRODUCT, CITYBLOCK, JACCARD, PEARSON.EUCLIDEAN
featureColsNoThe feature columns used for detection.Select All
groupColsNoThe columns used to group data. You can specify multiple columns.
maxOutlierNumPerGroupNoThe maximum number of outliers per group.
maxOutlierRatioNoThe maximum proportion of data points labeled as outliers.
maxSampleNumPerGroupNoThe maximum number of samples per group.
outlierThresholdNoIf the score exceeds the specified threshold, the data point is considered an anomalous point.
predictionDetailColNoThe name of the prediction details column.
tensorColNoThe tensor column.
vectorColNoThe vector column.
numNeighborsNoThe number of adjacent data points used to compute the LOF score.5
numThreadsNoThe number of threads for the component.1

Example

The following example detects outliers in a small dataset, then evaluates the detection results against known labels.

import pandas as pd

# Sample data: feature column "val" and ground-truth label column "label"
# label=1 marks the known outlier in the ground truth
df = pd.DataFrame([
    [0.73, 0],
    [0.24, 0],
    [0.63, 0],
    [0.55, 0],
    [0.73, 0],
    [0.41, 0]
])

dataOp = BatchOperator.fromDataframe(df, schemaStr='val double, label int')

# Detect outliers: flag points with an LOF score above 3.0
# numNeighbors defaults to 5, which works for this small dataset
outlierOp = LofOutlierBatchOp()\
    .setFeatureCols(["val"])\
    .setOutlierThreshold(3.0)\
    .setPredictionCol("pred")\
    .setPredictionDetailCol("pred_detail")

# Evaluate detection results against the ground-truth label
# setOutlierValueStrings specifies which label value represents an outlier
evalOp = EvalOutlierBatchOp()\
    .setLabelCol("label")\
    .setPredictionDetailCol("pred_detail")\
    .setOutlierValueStrings(["1"])

metrics = dataOp\
    .link(outlierOp)\
    .link(evalOp)\
    .collectMetrics()

print(metrics)