Search⌘ K
AI Features

Solution Review: Create Local Outlier Factor Model

Understand how to create and use a Local Outlier Factor model in PyCaret for anomaly detection. This lesson guides you through building the model, assigning anomaly labels and scores to the dataset, and extracting instances identified as outliers for further analysis.

We'll cover the following...

Solution

Python 3.5
# Create Local Outlier Factor model with an outlier proportion of 10%
# and assign it to model variable
model = create_model('lof', fraction = 0.10)
# Assign anomaly labels and scores to the data_assigned variable
data_assigned = assign_model(model)
# Create new dataset of outliers named data_outliers
data_outliers = data_assigned.query('Anomaly == 1')
# Print first 5 instances of the outlier dataset
data_outliers.head(5)

Explanation

  • Line 4: We create a local outlier factor model with an outlier proportion of 10% by ...