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
| Parameter | Description |
|---|---|
featureCols | The feature columns used for outlier detection. Accepts multiple column names. |
groupCols | The columns used to group data before detection. Outlier detection runs independently within each group. Accepts multiple column names. |
tensorCol | The tensor column. |
vectorCol | The vector column. |
Parameter Setting tab
| Parameter | Description | Default |
|---|---|---|
| Prediction Result Column | The name of the prediction result column. | — |
| Distance Measurement Method | The distance metric used to measure proximity between data points. Valid values: EUCLIDEAN, COSINE, INNERPRODUCT, CITYBLOCK, JACCARD, PEARSON. | EUCLIDEAN |
maxOutlierNumPerGroup | The maximum number of data points that can be labeled as outliers per group. | — |
maxOutlierRatio | The maximum proportion of data points that can be labeled as outliers. | — |
maxSampleNumPerGroup | The maximum number of samples per group. | — |
numNeighbors | The number of adjacent data points used to compute the LOF score for each point. | 5 |
outlierThreshold | If the score exceeds the specified threshold, an outlier is detected. | — |
| Column name of detail prediction information | The name of the prediction details column. | — |
numThreads | The number of threads for the component. | 1 |
Execute Tuning tab
| Parameter | Description |
|---|---|
| Number of Workers | The number of worker nodes. Valid values: 1–9999. Must be set together with Memory per worker. |
| Memory per worker | The 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
| Parameter | Required | Description | Default |
|---|---|---|---|
predictionCol | Yes | The name of the prediction results column. | — |
distanceType | No | The distance metric. Valid values: EUCLIDEAN, COSINE, INNERPRODUCT, CITYBLOCK, JACCARD, PEARSON. | EUCLIDEAN |
featureCols | No | The feature columns used for detection. | Select All |
groupCols | No | The columns used to group data. You can specify multiple columns. | — |
maxOutlierNumPerGroup | No | The maximum number of outliers per group. | — |
maxOutlierRatio | No | The maximum proportion of data points labeled as outliers. | — |
maxSampleNumPerGroup | No | The maximum number of samples per group. | — |
outlierThreshold | No | If the score exceeds the specified threshold, the data point is considered an anomalous point. | — |
predictionDetailCol | No | The name of the prediction details column. | — |
tensorCol | No | The tensor column. | — |
vectorCol | No | The vector column. | — |
numNeighbors | No | The number of adjacent data points used to compute the LOF score. | 5 |
numThreads | No | The 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)