Outlier detection using One-class classifier.
pythonsetup.pyinstallfromocc.occimport*## Load dataocsvm=occ()
ocsvm.load_data_mat(file)
"""Orocsvm.load_data_csv(file)Orocsvm.X = some_np_array ##(n_samples, n_features)"""## Train the model and get resultsocsvm.train(model='ocsvm', kernel='rbf', norm=True) # If norm=True, data will be normalized(L2)Y_scores=ocsvm.get_score(norm=True)
Y_hat=ocsvm.predict(norm=True)
## Visualization of the resultsocc.show_projection(ocsvm.X, Y_scores, title="Score ocsvm with rbf kernel", markersize=100)
occ.show_projection(ocsvm.X, Y_hat, title="Prediction ocsvm with rbf kernel", markersize=100)
## Export the result score and outliersocsvm.export_outliers("outliers.csv", Y_hat) ## Raw data of outliersocsvm.export_csv("scores.csv", Y_scores) ## Raw data with scoresocsvm.export_csv("predictions.csv", Y_hat) ## Raw data with predictionsfew_outliers=ocsvm.train(model='ocsvm', nu=0.01) ## 1% outliers assumedmany_outliers=ocsvm.train(model='ocsvm', nu=0.2) ## 20% outliers assumedocsvm=occ()
ocsvm.X=some_np_arrayocsvm.train(model='isolationForest', sampling=0.1) ## Only 10% of data will be used for trainingocc=occ()
occ.X=some_np_arrayocc.train(model='SOMEMODEL')- deepsvdd : Deep-SVDD; Deep One-Class Classification [ICML2018; Ruff, Lukas et al.,] ; Tensorflow2 implementation
- autoEncoder : AutoEncoder and reconstruction loss; pyod library
- vae : Variational AutoEncoder and reconstruction loss; pyod library
- isoForest : Isolation Forest; Isolation Forest[IEEE data mining conf 2008; Liu, Fei Tony, Kai Ming Ting, and Zhi-Hua Zhou.]; scikit-learn library
- ocnn : One-Class Neural Networks; Anomaly Detection Using One-Class Neural Networks [Chalapathy, R., Menon, A. K., & Chawla, S.]; Tensorflow2 implementation
- ocsvm : One-Class SVM; Support Vector Method for Novelty Detection [NIPS2000; Schölkopf, Bernhard, et al.]; scikit-learn library
- This module needs the Tensorflow 2.X.X version.