Skip to main content

Classifier based non-parametric change point detection

Project description

Classifier based non-parametric change point detection

Change point detection tries to identify times when the probability distribution of a stochastic process or time series changes. Existing methods either assume a parametric model for within-segment distributions or a based on ranks or distances, and thus fail in scenarios with reasonably large dimensionality.

changeforest implements a classifier based algorithm that consistently estimates change points without any parametric assumptions even in high-dimensional scenarios. See [1] for details.

Installation

changeforest is available on PyPI and conda-forge. To install from conda-forge (recommended), simply run

conda install -c conda-forge changeforest

Example

The following example performs random forest based change point detection on the iris dataset. This includes three classes setosa, versicolor and virginica with 50 observations each. We interpret this as a simulated time series with change points at t = 50, 100.

In [1]: from changeforest import changeforest
   ...: from sklearn.datasets import fetch_openml
   ...:
   ...: iris = fetch_openml(data_id=61)["frame"].drop(columns="class").to_numpy()
   ...: result = changeforest(iris, "random_forest", "bs")
   ...: result
Out[1]:
                    best_split max_gain p_value
(0, 150]                    50   96.212    0.01
 ¦--(0, 50]                 34    -4.65       1
 °--(50, 150]              100   51.557    0.01
     ¦--(50, 100]           80   -3.068       1
     °--(100, 150]         134   -2.063       1

In [2]: result.split_points()
Out[2]: [50, 100]

changeforest also implements methods change_in_mean and knn. While random_forest and knn implement the TwoStepSearch optimizer as described in [1], for change_in_mean the optimizer GridSearch is used. Both random_forest and knn perform model selection via a pseudo-permutation test (see [1]). For change_in_mean split candidates are kept whenever max_gain > control.minimal_gain_to_split.

The iris dataset allows for rather simple classification due to large mean shifts between classes. As a result, both change_in_mean and knn also correctly identify die true change points.

In [3]: result = changeforest(iris, "change_in_mean", "bs")
   ...: result.split_points()
Out[3]: [50, 100]

In [4]: result = changeforest(iris, "knn", "bs")
   ...: result.split_points()
Out[4]: [50, 100]

changeforest returns a tree-like object with attributes start, stop, best_split, max_gain, p_value, is_significant, optimizer_result, model_selection_result, left, right and segments. These can be interesting to further investigate the output of the algorithm. Here we plot the approximated gain curves of the first three segments:

In [5]: import matplotlib.pyplot as plt
   ...: result = changeforest(iris, "change_in_mean", "bs")
   ...: plt.plot(range(150), result.optimizer_result.gain_results[-1].gain)
   ...: plt.plot(range(50), result.left.optimizer_result.gain_results[-1].gain)
   ...: plt.plot(range(50, 150), result.right.optimizer_result.gain_results[-1].gain)
   ...: plt.legend([f"approx. gain for {x}" for x in ["(0, 150]", "(0, 50]", "(50, 150"]])
   ...: plt.show()

One can clearly observe that the approx. gain curves are piecewise linear, with maxima at the true underlying change points.

The changeforest algorithm can be tuned with hyperparameters. See here for their descriptions and default values. In Python, the parameters can be specified with the Control class which can be passed to changeforest. The following will build random forests with very few trees:

In [6]: from changeforest import Control
   ...: changeforest(iris, "random_forest", "bs", Control(random_forest_n_trees=10))
Out[6]:
                    best_split max_gain p_value
(0, 150]                    50   96.071    0.01
 ¦--(0, 50]                 16   -3.788       1
 °--(50, 150]              100   46.544    0.01
     ¦--(50, 100]           66   -7.793    0.43
     °--(100, 150]         134   -9.329       1

References

[1] M. Londschien, S. Kovács and P. Bühlmann (2021), "Random Forests and other nonparametric classifiers for multivariate change point detection", working paper.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

changeforest-0.4.0.tar.gz (123.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

changeforest-0.4.0-cp310-none-win_amd64.whl (302.9 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

changeforest-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

changeforest-0.4.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (822.8 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

changeforest-0.4.0-cp310-cp310-macosx_10_7_x86_64.whl (424.4 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.4.0-cp39-none-win_amd64.whl (302.9 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

changeforest-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

changeforest-0.4.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (822.8 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

changeforest-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl (424.4 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.4.0-cp38-none-win_amd64.whl (303.1 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

changeforest-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

changeforest-0.4.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (822.8 kB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

changeforest-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl (424.4 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.4.0-cp37-none-win_amd64.whl (303.2 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

changeforest-0.4.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

changeforest-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl (424.4 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

Details for the file changeforest-0.4.0.tar.gz.

File metadata

  • Download URL: changeforest-0.4.0.tar.gz
  • Upload date:
  • Size: 123.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2d734f2383d08631352170df470485e9d739cac709d36d832e425158da0c4d46
MD5 0925d36ec2d1c44e7d0da397c96b3877
BLAKE2b-256 433e8e9ec6378b4ec8b9758eb0e61d79892609cbf5a84e29446540335f6852e9

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp310-none-win_amd64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 302.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 664a1c6039e2198ea7575f168ba7c99df1f9b68b4b6a23c51d38e0c0ef018483
MD5 a65d53f9635eae7a56b7bc7c65b1ee56
BLAKE2b-256 3f60e4375842b59cf9d993bc513791d1d572aa0b4a49430d28e32a203864313f

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3257034f86ccaa6370d4e0a2d71d12cec81cef57a9dd9d7be17c5bfc434eb218
MD5 3ab18007415c95011ca21bf6f2231018
BLAKE2b-256 c155775b15efa87653997d57c08394eaff1c7e6ac4d89c64f8ce3dcbe52133a3

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2c997244d042277e9d1165b9506a473f85467fde183aff9644ff11673d9bc745
MD5 4cca007740612f18c8b86ddd71f168ef
BLAKE2b-256 e636e1699ffa82463cc10741d9022a89279f169b98152785cd5936ddcd76a015

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c99b23f09bb45768019cd33804fc4dcede3ed1973329f1f4c533cd55ec531832
MD5 59b37b91dc0789bd8a01da32587719d2
BLAKE2b-256 fc3ea5b35789fa634bf1f9ecb8cca1266059c0c944806e532e551899eb0a703b

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp310-cp310-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 424.4 kB
  • Tags: CPython 3.10, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 21c20794c34bae2556c0847bab200a7a5e6f290c551d38939a51c548a74cb7d0
MD5 af885b7bc414d0a1c486c028f096f611
BLAKE2b-256 e92f2cc3451d461d38cf860056339786c85912206d8382d8173709a0865f72f7

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp39-none-win_amd64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 302.9 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 9121c6b4fbc8ec1e21036f7d7b545e114289e0fede70614fb49f517f7979429a
MD5 522dd9b319a81efd47b12f2e9a7f703c
BLAKE2b-256 1e56567124f1fa832c69d3acd3c2c413b2af182d13a8d3e264136d24defdc8bd

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 85add3207dc13afa0f867d4b10aaa3d81e10a2df3280db5864ecb5da32a898e8
MD5 fb33d8d6ffb3df47351860eea1d0cabe
BLAKE2b-256 3ce4312bcffde4fb6bc5c3804e3b05b8879eb806008afa302482cc4760329c32

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 be303441e60352fbc5a292996968a5d5c56ed524c7b0221af85be0900fb2ce9f
MD5 f7f44576c6f6695b773ab69685908ae6
BLAKE2b-256 b378ced2cdaa6f0db303172793669133afec4008cace9269fa1c2817790f5735

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 99cdfef655c1ab2a40151a53046a719e58b3c6a9d8f5f39c8401cd1783c4d069
MD5 d04de70c17e12a8d2cb2773ebf238680
BLAKE2b-256 257668e7df00b1c2c91a73744af1b9f2a0b4a59dae2bc59f475ca5cd76dee372

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 424.4 kB
  • Tags: CPython 3.9, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 39f54c74676a682b9fb7ef8a263b1a910f20266e060057c932ab4a557a6c2ea6
MD5 a70fe0f1026b04375afa9ce3ac5a1b50
BLAKE2b-256 269d7760630c81c12c9ee3101f107dc93bca78ef09f773c527f5cac61cd1257d

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp38-none-win_amd64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 303.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 7ef36c6218e5ca75bb8276d1615788449ad87967a6ca78f018e2b9c2851a7fb8
MD5 416bcb1dcdacfe9296cd5af90948e398
BLAKE2b-256 459c088b1b2b2c2fdf5e25e30634cb82062ee0254612a251027c88cbfd476972

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 46e55b65e1220b078ad50d4f4310698b050f2e3fccd1b836c2857291543f629b
MD5 7ebf111d48e903cf87bd8a2d6987f4aa
BLAKE2b-256 b27d086c82185bce7eaa40c568eeb73b3526194873283376cd45b6b6f96dc0f1

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7b1ae7ebc0785e77e135ba96d5c4ddd158b3477d8aef6eb7ab35747b9246dbbc
MD5 92681958209ff11b50a17650c5a11843
BLAKE2b-256 0db19fc4c8afb4f131c283a85aa21da1c4abec0d2813e55f4eec364aebb237ab

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ad5c3ba7228eb697e9c9a9b76f5878fc7803ffa290ae1b1fcb23c48507bd47dd
MD5 810f77d06527ea3d36644b179008a512
BLAKE2b-256 bfb5532d23a68ab1b160e429334cbf709dea40b404fe33b2495a1b7c3c80c4cd

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 424.4 kB
  • Tags: CPython 3.8, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 d9af229e21166e3bda9a390ec789caa5b8c73bcd628209f8ac3a18d5fbebc2e7
MD5 de24d2b7df60fbad7863e77ccddd8243
BLAKE2b-256 2faf4204ec529342a09b58ce89b55a42b8e5a8abd132f96102f3885171ac69d1

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp37-none-win_amd64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 303.2 kB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 2ad0e0b37441d6c937cb70fdd4f6d67b5635b95d4aa2ba5211de103abd9ea153
MD5 24a51b9065b444e8096c353b9ee50e11
BLAKE2b-256 694aaecfea97f30f4994af38607cc9ac21290b964d173c6a69278189d3183975

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6398043dc615270cee6d64020cbb7b635800d336e2c1416e8e0d9d86e19ff215
MD5 89d2954037331e6f11faec396fcf485f
BLAKE2b-256 ce24f75f5161d846ca854fe38da47bc9158169207141116cba62366cbbe0085c

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for changeforest-0.4.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b11d351c339d282631499cba1368bb04b5f68af4fca08aa72559a1e603b51d05
MD5 6c8f6af72fbe37c6c4273a91a5fdc8f0
BLAKE2b-256 22226d87defe678144db532d1c38ff52351407d6bdd5bc5b38571226b7a507f0

See more details on using hashes here.

File details

Details for the file changeforest-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: changeforest-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 424.4 kB
  • Tags: CPython 3.7m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for changeforest-0.4.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c9fd1ad0b201d30b951a41664116a461e7655f4ea084fc05b11e2d125bbb5722
MD5 c9d89ddb8985719a9e40ad6e7bed1af7
BLAKE2b-256 fdc94641ecc9c3ff8c259932aa5553b8aa18714d1ce01ef12c2e759108ac9652

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page