lsanomaly is a flexible, fast, probabilistic method for calculating outlier scores on test data, given training examples of inliers. Out of the box it works well with scikit-learn packages. See the features section for why you might chose this model over other options.
Table of Contents
- Compatible with scikit-learn package modules
- Probabilistic outlier detection model
- Robust classifier when given multiple inlier classes
- Easy to install and get started
The best way to install lsanomaly is to:
pip install lsanomaly
An alternative is to download the source code and
python setup.py install
Tests can be run from setup if pytest is installed:
python setup.py test
For those familiar with scikit-learn the interface will be familiar, in fact lsanomaly was built to be compatible with sklearn modules where applicable. Here is basic usage of lsanomaly to get started quick as possible.
Configuring the Model
LSAD provides reasonable default parameters when given an empty init or it can be passed values for rho and sigma. The value rho controls sensitivity to outliers and sigma determines the ‘smoothness’ of the boundary. These values can be tuned to improve your results using lsanomaly.
from lsanomaly import LSAnomaly # At train time lsanomaly calculates parameters rho and sigma lsanomaly = LSAnomaly() # or lsanomaly = LSAnomaly(sigma=3, rho=0.1, seed=42)
Training the Model
After the model is configured the training data can be fit.
import numpy as np lsanomaly = LSAnomaly(sigma=3, rho=0.1, seed=42) lsanomaly.fit(np.array([,,,,,]))
Now that the data is fit, we will probably want to try and predict on some data not in the training set.
>>> lsanomaly.predict(np.array([])) [0.0] >>> lsanomaly.predict_proba(np.array([])) array([[ 0.7231233, 0.2768767]])
Check out the latest docs here: https://lsanomaly.readthedocs.io/en/latest/
See notebooks/ for sample applications.
J.A. Quinn, M. Sugiyama. A least-squares approach to anomaly detection in static and sequential data. Pattern Recognition Letters 40:36-40, 2014.
The MIT License (MIT)
Copyright (c) 2016 John Quinn
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.