Layer 1: Tabular Anomaly Detection ==================================== PyOD has 43 tabular detectors covering probabilistic, linear, proximity, ensemble, and deep learning approaches. All use the same ``fit``/``predict``/``decision_function`` API. .. code-block:: python from pyod.models.iforest import IForest clf = IForest() clf.fit(X_train) y_train_scores = clf.decision_scores_ y_test_scores = clf.decision_function(X_test) ---- Recommended Starting Points ---------------------------- Based on `ADBench `__ (NeurIPS 2022, 57 datasets, 30 algorithms): * `ECOD `__ -- parameter-free, highly interpretable, top ADBench performance * `IForest `__ -- tree ensemble, scales to high dimensions * `KNN `__ -- proximity-based, good baseline * `LOF `__ -- density-based, good for local anomalies * `COPOD `__ -- copula-based, fast ---- All Tabular Examples -------------------- **Probabilistic:** `ECOD `__, `COPOD `__, `ABOD `__, `MAD `__, `SOS `__, `QMCD `__, `KDE `__, `Sampling `__, `GMM `__ **Linear Models:** `PCA `__, `KPCA `__, `MCD `__, `CD `__, `OCSVM `__, `LMDD `__ **Proximity-Based:** `LOF `__, `COF `__, `CBLOF `__, `LOCI `__, `HBOS `__, `HDBSCAN `__, `KNN `__, `SOD `__, `ROD `__ **Outlier Ensembles:** `IForest `__, `INNE `__, `DIF `__, `Feature Bagging `__, `LSCP `__, `XGBOD `__, `LODA `__, `SUOD `__ **Neural Networks:** `AutoEncoder `__, `VAE `__, `DeepSVDD `__, `SO_GAAL `__, `MO_GAAL `__, AnoGAN, `ALAD `__, `AE1SVM `__, `DevNet `__ ---- Example Walkthrough ------------------- Full example: `knn_example.py `__ 1. Import and generate data: .. code-block:: python from pyod.models.knn import KNN from pyod.utils.data import generate_data, evaluate_print contamination = 0.1 X_train, X_test, y_train, y_test = generate_data( n_train=200, n_test=100, contamination=contamination) 2. Fit and predict: .. code-block:: python clf = KNN() clf.fit(X_train) y_train_pred = clf.labels_ # 0: inlier, 1: outlier y_train_scores = clf.decision_scores_ # raw scores y_test_pred = clf.predict(X_test) y_test_scores = clf.decision_function(X_test) 3. Evaluate: .. code-block:: python evaluate_print('KNN', y_test, y_test_scores) # KNN ROC:0.9989, precision @ rank n:0.9