LoslegenKostenlos loslegen

KNN for the first time

You will practice KNN for the first time on a version of the Ansur Body Measurements dataset for females. The female version also contains 95 columns but only 1.9k observations.

The dataset has been loaded as females into the environment.

Diese Übung ist Teil des Kurses

Anomaly Detection in Python

Kurs anzeigen

Anleitung zur Übung

  • Import the KNN estimator from the relevant pyod module.
  • Instantiate a KNN() estimator with 0.5% contamination and 20 neighbors as knn.
  • Create a boolean index named is_outlier that returns True when the labels_ of knn return 1.
  • Isolate the outliers from females using is_outlier into outliers.

Interaktive Übung

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

# Import KNN from the relevant pyod module
from pyod.____ import ____

# Instantiate KNN and fit to females
knn = KNN(____, ____, n_jobs=-1)
knn.____

# Create a boolean index that checks for outliers
is_outlier = ____

# Isolate the outliers
outliers = ____

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