Get startedGet started for free

LoF contamination

Your medical advisor at the arrhythmia startup informs you that your training data might not contain all possible types of arrhythmia. How on earth will you detect these other types without any labeled examples? Could an anomaly detector tell the difference between healthy and unhealthy without access to labels? But first, you experiment with the contamination parameter to see its effect on the confusion matrix. You have LocalOutlierFactor as lof, numpy as np, the labels as ground_truth encoded in -1and 1 just like local outlier factor output, and the unlabeled training data as X.

This exercise is part of the course

Designing Machine Learning Workflows in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Fit the local outlier factor and output predictions
preds = lof().____(X)

# Print the confusion matrix
print(____(ground_truth, preds))
Edit and Run Code