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_ntrees=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.3.0.tar.gz (322.6 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.3.0-cp310-none-win_amd64.whl (241.6 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

changeforest-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

changeforest-0.3.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (681.4 kB view details)

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

changeforest-0.3.0-cp310-cp310-macosx_10_7_x86_64.whl (351.7 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.3.0-cp39-none-win_amd64.whl (241.6 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

changeforest-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

changeforest-0.3.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (681.4 kB view details)

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

changeforest-0.3.0-cp39-cp39-macosx_10_7_x86_64.whl (351.7 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.3.0-cp38-none-win_amd64.whl (241.5 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

changeforest-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

changeforest-0.3.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (681.4 kB view details)

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

changeforest-0.3.0-cp38-cp38-macosx_10_7_x86_64.whl (351.7 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.3.0-cp37-none-win_amd64.whl (241.6 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ x86-64

changeforest-0.3.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.1 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.17+ ARM64

changeforest-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl (351.7 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0.tar.gz
Algorithm Hash digest
SHA256 058cae79cb932df61697523e908272f02bc021e5f8bbfe3ebf8cdd646f6388a9
MD5 88c6e22670ac90b8f01a225811930eab
BLAKE2b-256 69deac3fa68517de546db1903ea84712fa1f8372e0400319e837f87c0a6459aa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 b36b3dbddebc36c852969144d3ab151629cf683d3e101e6fa89f834e59ef42bd
MD5 d6ab4456869fa766965f5ca44bddd4d1
BLAKE2b-256 0a40d283498f44569266ce7600898cd6390f768b05e3938c3abfaff83cea0268

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d93eb6323a9446b2b2885e5f227ee5aea8e4abfde78be28f87d8d326890527e
MD5 6429b1772ad0191e5842a5201f514476
BLAKE2b-256 d809de41c0f8f4012b591d117034ad6200fe6246c072600df09ab9d474486c6f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 12fd5991ae9b23979ae0751caee987d3a67276b1d2df48bd3bdfa91d7169cfda
MD5 60f6ad70eb12f3968a6f6e8d1a898170
BLAKE2b-256 1f1a7728fd5762910284d28cd3f60e5e5ac6f37bac748b46a00f342655e56569

See more details on using hashes here.

File details

Details for the file changeforest-0.3.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.3.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 cd269f3ebb00d9962cb860ebc8946782b61d0b0c7306e44e5531c547156bcd4d
MD5 5788e73843b51fc3c5d691800c6b9909
BLAKE2b-256 a865e2ba7af4d9b0d89aabc9366cfe52f5070c95c5bfc526d04aebe0798f19f1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 39ace07065d20b2b748678825f374bd4969b7dffd596e05cd73e5b8669a77dc6
MD5 eae5c3b3408970a454e94bc7a02a5452
BLAKE2b-256 e5c0ba8fb04c56e01e663e593229df42178441f5a8b71066992f1c4740ea5aa4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 92af480ed95603e07aa6f3d5645b0d46d9616a91a1e63292d25af51e2d8d21e9
MD5 375e92997908b996f089e70f349f9df4
BLAKE2b-256 233b207f6a09506f0683e16d3758b541ff01b9fea5a32730b65909be4801f5f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49af8e9805ccee6577c52606e6ef1a604b59e1f10b64cfd204a901f6a4910e1d
MD5 4c29bfa6212469239294a34e44741bcb
BLAKE2b-256 9f261b8e6da854966628b5ee3b2a115b652fcade4eba2a7c9e78e38465b9d895

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bec83b6bbcf1deffb6f478bdca45757a69046e404538ce872d8cfd8572a1da4c
MD5 6f4b8fc501f9dcc31af5824d0c87d3ab
BLAKE2b-256 d1dabd34ff1a78a94f9ac6b7d939b9b7d7af20517e70413a2aa9097583380114

See more details on using hashes here.

File details

Details for the file changeforest-0.3.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.3.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 ccd0f57a7abe08cf7053f68d5e28deb5641e20ed969668bc0b56efeb3ee6e63d
MD5 1c1d94e6fe2c676930b0282cad9c24b4
BLAKE2b-256 52ae3885af5ba2daafbc7e0f02b9542f03700fb44e7de8e3adb6bdf00c9957b9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ac5802a3c219f3671df2424b91bd305702a2c0d0b1428ec4e72cb8d45ca482bd
MD5 d5606eabc636b64b1c7103424c0c9f78
BLAKE2b-256 659a7297d33b757190e04b6d52ff5bed2dca40a0197b1e176752988c098e1f3a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 22479742b8f115d05f9edd2ca89b909e16cf5db5ce1fb85f78450879eca7c317
MD5 c8e26ce5bc43187a6624a1ff79f25837
BLAKE2b-256 65c0b6b3d046905a8ff21ccd77a546265d70260326ac3b5da46cc230bceb797e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9a3c5b3e1b4f3f88dc2e56ae6bf3bc6f81b33bb0d379ec109bac2884c336294
MD5 e6ee267fc8916e05ca945f71c9a43fd8
BLAKE2b-256 29d08074912ca4d4ade9f97007fd461b0973559553072aafcc573f32ff1efa85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ab7832205b7c23dc6017b301cf2c13944d24b651e5d993800edd2d26c0dd3443
MD5 7d680d68668be330aeb8fac06a0f8c2f
BLAKE2b-256 07f77c1ec6376eb4004c989575514a387c138db9b9b3e0f6bed47025cf000b22

See more details on using hashes here.

File details

Details for the file changeforest-0.3.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.3.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 679e128b21b19c0c699b96c5f8dc187741a17d8de3aee01199483ab8ff657c69
MD5 c0e74c012f604dba251ff2b9cda936b2
BLAKE2b-256 3d6f78a87681f18513b2bf32c81150f4589ff199951686d152c86f41f6c6c1fd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 418095a37053cecbf458ebf0124b9f5df208f051203c89ff9b5d9e6fc9461c9b
MD5 7374628d1eab1a11a042098b0d4ae7c1
BLAKE2b-256 0f9d21266d10029562d19a2a2adc4d0e95c3ecebd1f5b95ab66f2203fb82ef7f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 fc8f9a0a287b7f9ff2bd78b9c69fe34bcf01239cbdfb82d1f46a866c90aaf8d6
MD5 0880dd38557d6c5552c5fc870e7ab1dd
BLAKE2b-256 4b390432d19136ec73ff2f723c190a212747d5ca9dd2a3afc5045bd04408563c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3da3846533aa22cd2e8152bf22292dc068aa57f2f406e4b08afa7a934553f32d
MD5 0a3743a15330cb3215f10585b51eaf19
BLAKE2b-256 fa65fd3a6e1c73e637fc1b6f20955d276f6be56ccbc1f65b2bc7e64f84aef6d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.3.0-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bbf314b78be5d9073c0a34e8504ca5e25d5c5cbd9ab6b066a53085c760e497df
MD5 c15c8352ef89746d98009d9978c26866
BLAKE2b-256 35becafc8f0935121e9bcf628a3dcb85f90fcba41daf75991f6a1a03e837d0a5

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.3.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5dc1152177b19729f92117585da94420bbb1eb1a9fc25d8e873f523d20dc6733
MD5 705f864b96c61f6f1b2eab591fb8c4c7
BLAKE2b-256 d7620341dfa61079f7fe2ac04ddcb95389f7a3b0f9ba73e9004a02813a69ea1f

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