Choosing contamination
Even though the code implementation only takes a few lines, finding the suitable contamination requires attention.
Recall that contamination parameter only affects the results of IForst. Once IForest generates raw anomaly scores, contamination is used to chose the top n% of anomaly scores as outliers. For example, 5% contamination will choose the observations with the highest 5% of anomaly scores as outliers.
Although we will discuss some tuning methods in the following video, for now, you will practice setting an arbitrary value to the parameter.
The data is loaded as big_mart.
Questo esercizio fa parte del corso
Anomaly Detection in Python
Istruzioni dell'esercizio
- Instantiate an
IForest()estimator with 5%contamination. - Fit the instance to the Big Mart sales data.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
from pyod.models.iforest import IForest
# Instantiate an instance with 5% contamination
iforest = ____
# Fit IForest to Big Mart sales data
____