LOF with outlier probabilities
As always, double-check that the chosen contamination level is trustworthy by filtering the outliers with a probability threshold. The syntax is the same as with KNN.
LOF estimator has already been imported, and the females_transformed dataset is also available.
Este ejercicio forma parte del curso
Anomaly Detection in Python
Instrucciones del ejercicio
- Instantiate
LOF()with 20 neighbors. - Calculate outlier probabilities into
probs. - Create a boolean mask named
is_outlierthat returns true values where the outlier probability is over 50%. - Use
is_outlierto filter the outliers fromfemales_transformed.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Instantiate an LOF with 20 neighbors and fit to the data
lof = ____
lof.____
# Calculate probabilities
probs = ____
# Create a boolean mask
is_outlier = ____
# Use the boolean mask to filter the outliers
outliers = ____
print(len(outliers))