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.
Bu egzersiz
Anomaly Detection in Python
kursunun bir parçasıdırEgzersiz talimatları
- Import the
KNNestimator from the relevantpyodmodule. - Instantiate a
KNN()estimator with 0.5% contamination and 20 neighbors asknn. - Create a boolean index named
is_outlierthat returnsTruewhen thelabels_ofknnreturn 1. - Isolate the outliers from
femalesusingis_outlierintooutliers.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# 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))