A set of python modules for anomaly detection
Project description
kenchi
This is a set of python modules for anomaly detection.
Requirements
Python (>=3.5)
matplotlib (>=2.0.2)
numpy (>=1.11.2)
pandas (>=0.20.3)
scipy (>=0.18.1)
scikit-learn (>=0.18.0)
Installation
You can install via pip.
pip install kenchi
Usage
>>> import numpy as np
>>> from kenchi.outlier_detection import GaussianOutlierDetector
>>> train_size = 1000
>>> test_size = 100
>>> n_outliers = 10
>>> n_features = 10
>>> rnd = np.random.RandomState(0)
>>> mean = np.zeros(n_features)
>>> cov = np.eye(n_features)
>>> # Generate the training data
>>> X_train = rnd.multivariate_normal(
... mean = mean,
... cov = cov,
... size = train_size
... )
>>> # Generate the test data that contains outliers
>>> X_test = np.concatenate((
... rnd.multivariate_normal(
... mean = mean,
... cov = cov,
... size = test_size - n_outliers
... ),
... rnd.uniform(-10.0, 10.0, size=(n_outliers, n_features))
... ))
>>> # Fit the model according to the given training data
>>> det = GaussianOutlierDetector().fit(X_train)
>>> # Detect if a particular sample is an outlier or not
>>> det.detect(X_test)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1], dtype=int32)
License
The MIT License (MIT)
Copyright (c) 2017 Kon
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kenchi-0.4.0.tar.gz
(9.3 kB
view hashes)
Built Distribution
kenchi-0.4.0-py3-none-any.whl
(30.8 kB
view hashes)