This is the implementation of RecForest for anomaly detection, proposed in the paper “Reconstruction-based Anomaly Detection with Completely Random Forest,” SIAM International Conference on Data Mining (SDM), 2021. It is highly optimized and provides Scikit-Learn like APIs.
Installation
RecForest is available at PyPI:
$ pip install recforest
Build from Source
To use RecForest, you first need to install the package from source:
$ git clone https://github.com/xuyxu/RecForest.git
$ cd RecForest
$ python setup.py install
Notice that a C compiler is required to compile the pyx files (e.g., GCC on Linux, and MSVC on Windows). Please refer to Cython Installation for details.
Example
The code snippet below presents the minimal example on how to use RecForest for anomaly detection. Scripts on reproducing experiment results in the paper are available in the directory examples.
from recforest import RecForest
model = RecForest()
model.fit(X_train)
y_pred = model.predict(X_test)
Documentation
RecForest only has two hyper-parameters: n_estimators and max_depth. Docstrings on the input parameters are listed below.
n_estimators: Specify the number of decision trees in Recforest;
max_depth: Specify the maximum depth of decision trees in Recforest;
n_jobs: Specify the number of workers for joblib parallelization. -1 means using all processors;
random_state: Specify the random state for reproducibility.
RecForest has three public methods. Docstrings on these methods are listed below. Notice that for all methods, the accepted data format of input X is numpy array of the shape (n_samples, n_features).
fit(X): Fit a RecForest using the input data X;
apply(X): Return the leaf node ID of input data X in each decision tree;
predict(X): Return the anomaly score on the input data X.
Package Dependencies
numpy >= 1.13.3
scipy >= 0.19.1
joblib >= 0.12
cython >= 0.28.5
scikit-learn >= 0.22
A Python environment installed from conda is highly recommended. In this case, there is no need to install any package listed above.
Metadata
Release files for RecForest 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| RecForest-0.1.0-cp38-cp38-win_amd64.whl | CPython 3.8 | CPython 3.8 | Windows x86-64 | Details |
| RecForest-0.1.0-cp38-cp38-manylinux2010_x86_64.whl | CPython 3.8 | CPython 3.8 | Linux glibc 2.12+ x86-64 | Details |
| RecForest-0.1.0-cp38-cp38-manylinux1_x86_64.whl | CPython 3.8 | CPython 3.8 | Linux glibc 2.5+ x86-64 | Details |
| RecForest-0.1.0-cp37-cp37m-win_amd64.whl | CPython 3.7 | CPython 3.7 pymalloc | Windows x86-64 | Details |
| RecForest-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl | CPython 3.7 | CPython 3.7 pymalloc | Linux glibc 2.12+ x86-64 | Details |
| RecForest-0.1.0-cp37-cp37m-manylinux1_x86_64.whl | CPython 3.7 | CPython 3.7 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| RecForest-0.1.0-cp36-cp36m-win_amd64.whl | CPython 3.6 | CPython 3.6 pymalloc | Windows x86-64 | Details |
| RecForest-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.12+ x86-64 | Details |
| RecForest-0.1.0-cp36-cp36m-manylinux1_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.5+ x86-64 | Details |
Total release size: 2.3 MB
Release files / RecForest-0.1.0-cp38-cp38-win_amd64.whl
| Download URL | RecForest-0.1.0-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 76.2 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8324ff1188c4871f3d5877a638bfac10a79fef5ce7fdb668d553807b42521e9a
|
|
BLAKE2b-256 checksum How to use checksums |
9821bc4faa118ea67a45897d9551087ea70152850ec372bb35217a2a89ed2f17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp38-cp38-manylinux2010_x86_64.whl
| Download URL | RecForest-0.1.0-cp38-cp38-manylinux2010_x86_64.whl |
|---|---|
| Size | 370.9 kB |
| Tags | CPython 3.8 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
19416788bd2cc6ec73b65dd74a5bb23138606b8ad8c512e71bcdaffe6286658b
|
|
BLAKE2b-256 checksum How to use checksums |
9b1965c1fefb8024c497f4dbd400d6bb0774fd68bf9474efe9982b6980975f61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp38-cp38-manylinux1_x86_64.whl
| Download URL | RecForest-0.1.0-cp38-cp38-manylinux1_x86_64.whl |
|---|---|
| Size | 370.9 kB |
| Tags | CPython 3.8 Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
a5c3b556982c45903740f239c98126fec4178e0289e02f83c00ff262a4578067
|
|
BLAKE2b-256 checksum How to use checksums |
4bfb00f6a0095b4209416323f3fbccc4dcaa47488be76fe558593b94da4aa832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp37-cp37m-win_amd64.whl
| Download URL | RecForest-0.1.0-cp37-cp37m-win_amd64.whl |
|---|---|
| Size | 75.1 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ba9e55319e54a242527b345af7deef1d98ace4087a9dd7b8e4c44fac6cc7b1c4
|
|
BLAKE2b-256 checksum How to use checksums |
65a4d0174f1b6e4cdb3f4bef9d3851469198569874766f785f2de7a62dafda9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl
| Download URL | RecForest-0.1.0-cp37-cp37m-manylinux2010_x86_64.whl |
|---|---|
| Size | 335.6 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
42d6243541b98f3ec4c2e93680689b606b2144853c0b30731b2f1ac74568b306
|
|
BLAKE2b-256 checksum How to use checksums |
1b4ff87c621a7a8269569e33b361096ddf1f47d5d918d9a5ffc918cf0d4a594b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp37-cp37m-manylinux1_x86_64.whl
| Download URL | RecForest-0.1.0-cp37-cp37m-manylinux1_x86_64.whl |
|---|---|
| Size | 335.6 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
4beec717cdfdd9483d4da506f910e3582376c654c9bc345aa538969c600e22e1
|
|
BLAKE2b-256 checksum How to use checksums |
9d0fdb37102805f764fbd3ff06c4989f2386c2b9ae39467ff5176dd370bcaefb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp36-cp36m-win_amd64.whl
| Download URL | RecForest-0.1.0-cp36-cp36m-win_amd64.whl |
|---|---|
| Size | 75.1 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Windows x86-64 |
|
SHA-256 checksum How to use checksums |
865462add2483722dc3b281a2b0473ceefed443589f9e9a774b9738c77627a81
|
|
BLAKE2b-256 checksum How to use checksums |
33bdd1431eff315e61e7039131b605575510b94bf735688136d3cb0e71738338
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl
| Download URL | RecForest-0.1.0-cp36-cp36m-manylinux2010_x86_64.whl |
|---|---|
| Size | 335.5 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
162570715e4fc1ccda5ebc97cfb8502d1405b873cf5b85448739c886999f1cbe
|
|
BLAKE2b-256 checksum How to use checksums |
24c29fc728bd5fba1460082a4b8886fa3973b22c21362b490e995bddb705fe60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|
Release files / RecForest-0.1.0-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | RecForest-0.1.0-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 335.5 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
1725d3291f081678ad8649aff0e88b62f880d10065d2ddc6656a33b9b458a22d
|
|
BLAKE2b-256 checksum How to use checksums |
ff0c6ffc6b8456a433e17c3bed01d7217d277bcc4f3aac2f789e9570e976a5de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.1.post20201107 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5
|