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.1.tar.gz (125.1 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.1-cp310-none-win_amd64.whl (302.7 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.4.1-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.1-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.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (823.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.1-cp310-cp310-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.4.1-cp39-none-win_amd64.whl (302.8 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.4.1-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.1-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.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (823.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.1-cp39-cp39-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.4.1-cp38-none-win_amd64.whl (303.0 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.4.1-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.1-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.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (823.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.1-cp38-cp38-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.4.1-cp37-none-win_amd64.whl (303.0 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.4.1-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.1-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.1-cp37-cp37m-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: changeforest-0.4.1.tar.gz
  • Upload date:
  • Size: 125.1 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.1.tar.gz
Algorithm Hash digest
SHA256 45cae9a2c4fa5913f002ba59f43167d2e9d33170a610b11ad7418d145cd4e122
MD5 e6223f5fba560cdf33af19ffced304ef
BLAKE2b-256 618ce017e6299fd4028d6258c1093c3fdd3d742b14641b31118b6881e6e507e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 302.7 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.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 23279cacc466f116ba840472e5e9eda04e98f0d08f04f7b556789178c985d6dc
MD5 8d1a573b132daebf1719282ef3f9d321
BLAKE2b-256 e1d699315b07150b8867ec5916be6baa9ec146d323010ab270f87b6fad2914e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb2bff34a5253b7f4be0f018c4f4e51d41530addb27ed075b66080c77f317731
MD5 003690a10f00c05b955d680adfa657b5
BLAKE2b-256 7dcc84797d6a973a5e4ad903ab64cb6aa31fb761d30b668e807fd07a891a1bc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dfd9d557d3c1e5b57ba8ad681f1ac6d3cf8b433aaa4a5afee611b52b0d42f293
MD5 c2ec760f1fe88613d0bd9797dfa27808
BLAKE2b-256 51278c6231f56e5fabadcaf36bf2c8de6964bf0c52256b52e0674cd8c8cbadd9

See more details on using hashes here.

File details

Details for the file changeforest-0.4.1-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.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 e287685b71cd290d445903c1316fdd8eec6aad132dc422fdea8313071faf5745
MD5 46e83c7dde6b1c78608ee969850f0c62
BLAKE2b-256 ef0028053fe52a2449f4a80dafb7ac9d708b221d2ad798103bc6913728a32516

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp310-cp310-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 425.8 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.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 f6a751d74e6d2e5558c35f32b24ac30afae14a16d242238e96bc71087e9ff4ed
MD5 60d605b2f384795aeff60eb388f9f60e
BLAKE2b-256 24fdc51da111157746122127940b3cd306fcfb5dd73bba78c55272fd89c8f3ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 302.8 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.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 5f79cea28df05dc5c237ee2992642c20bc21051ca180874fa06bf08eca1861ba
MD5 5f957a1db896a5a3f5baef8c0021e60c
BLAKE2b-256 85389fc663446e0a10fd849fe2e9ecedfd51ae82f31268ef1f176bf8ad7b5412

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34536a06a29bb81f1a59c730d24075c9672b724463acc863ee1a9a654d8e1f1e
MD5 2b932356542faefdb289d991a2a74f6e
BLAKE2b-256 7590029096a2b0ac4a12b01ccef0af736845964aaafa38d72e75d2b0d9665e47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7977a0f92e7529d78180777051672b47e267016f2618edfad100c942f5db5516
MD5 2e00381ab0e0697bf6e2db0309fa4729
BLAKE2b-256 95a4180aec7eb0ef057ceac74df435f71dbe9ca1f8414912fb4ea5240e15c975

See more details on using hashes here.

File details

Details for the file changeforest-0.4.1-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.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0b13fcbe49d129432df4740e8a3017a32a6578daf5f383683a7f0ec9a2bc0d01
MD5 fe9aa45531903e25a2da53ead9ddbbc9
BLAKE2b-256 ba50498d56413858a6c7ba61b8c9194048dac8f183858e8926ec426ceba76054

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp39-cp39-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 425.8 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.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 2483340e6ebd6fb8f89d70a53cae59476594aab5b0b4f8b123a636c91aad8491
MD5 3314715a9479cd1ec5b0dabbeaf59ad7
BLAKE2b-256 48adcca53397c3430df066faaeb24b216834c5bdbd48cee7f0769509d8064b50

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 303.0 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.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 caa249b90f5289cfff18cfd659e21fde3f29f13085f04539b197e4534516ac1e
MD5 39cae7b8217e618fc8cd983b4a4c2a50
BLAKE2b-256 f1a9afb344b0aac45087c384927064213a51e324e70e5ff3f70214043f857d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b469c16e82c9adbe97f390951508ba1b3699f87dc95e63326eabe0c9b3a1a383
MD5 dc099f45ffacab1049bfef64896a8f2a
BLAKE2b-256 c58210772f3c5f11594780ece954a0449eb2ae845f652e1124bf6a68d2399853

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 15a1e36b6c44b5a0a84fa9064abd9069e95f6d5c4a747070ba32436da7feee92
MD5 1ca4a06b71321cfc7c407326ac18d01b
BLAKE2b-256 a5f387c556fc5f5b8f8dbac4c9e277239e1030731f5adaffef8e6ea4f96f1f90

See more details on using hashes here.

File details

Details for the file changeforest-0.4.1-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.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 690a9bbb6d91e2c4db62ab5c6b99887c07885daf7b44f3001bc9b3df84fbb2a2
MD5 4b890dc8d7b9e606a4ffc7b6685f93b5
BLAKE2b-256 03bfb19c2d13ed6c639ec59a6c03f09b3bb784e53a7de9f5e2b42ef1e42132ee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 425.8 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.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 69dfaf529e8fff37a89d67ecbf4bacf372d809144b202b5b9936d4ffe7ee0c54
MD5 cd617807ea2cad1c5517c9961b10ef9f
BLAKE2b-256 a1356abfcd9ecace60cfcf5c32382379027ca2e8539a48a0289efb6ece3976f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 303.0 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.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 ff5d9f913568dc4aa05b30dc7a2ba5880d731c597b1370e64cb44014aecd8846
MD5 4ff17e687f48cffdce22d7784bc5ead4
BLAKE2b-256 8ae784159208507d1ccf12ee7274f1c4b22fc60344c254e6cf4fc165c9823f45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30295e65fbd9929accb73f672c1f3ffb402c67f7441787a918c04d3650f935dd
MD5 d962d5d27d409fee56cc9087883a541d
BLAKE2b-256 bcf2b64776a79e0496dfd7162441c8e225b7851dbd7231b38075fd23310655e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fe47c57189955c1bacf5fdd0cdbfc0c734a8bed2659fe2639bcd32e6ea4280a4
MD5 5faf2e574766b6fb9bb099684976e0c4
BLAKE2b-256 081b067bf841cab956992e341ea364a71fccfbc3522f18737aeacff1bf85f360

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.1-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 425.8 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.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8dc9acc465d2c07c2e487eb0f3bf44fafb00ed618304c609e6bf8b7eeaccd2e0
MD5 38e06aacd7b6804f8633fe488ebf2dd5
BLAKE2b-256 c07cb48bc86848c9c5f1025928dfa38ab2abf861c7f897a940baaec945cd7eb1

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