LoslegenKostenlos loslegen

Using modified z-scores with PyOD

It is time to unleash pyod on outliers. We use the MAD estimator from pyod to utilize modified z-scores. The estimator already uses the median_abs_deviation function under the hood, so it is unnecessary to repeat the previous steps.

The MAD estimator has already been loaded from pyod.models.mad and the data is available as prices.

Diese Übung ist Teil des Kurses

Anomaly Detection in Python

Kurs anzeigen

Anleitung zur Übung

  • Initialize MAD() with a threshold of 3.5.
  • Reshape prices to make it 2D.
  • Generate inlier/outlier labels on prices by fitting and predicting using mad simultaneously.
  • Subset labels for outliers, which are denoted as 1.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Initialize with a threshold of 3.5
mad = ____(____=____)

# Reshape prices to make it 2D
prices_reshaped = ____.____(-1, 1)

# Fit and predict outlier labels on prices_reshaped
labels = ____

# Filter for outliers
outliers = ____[____ == ____]

print(len(outliers))
Code bearbeiten und ausführen