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_estimators=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.6.1.tar.gz (127.0 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.6.1-cp310-none-win_amd64.whl (297.9 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.6.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.6.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.6.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (796.6 kB view details)

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

changeforest-0.6.1-cp310-cp310-macosx_10_7_x86_64.whl (410.5 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.6.1-cp39-none-win_amd64.whl (298.3 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.6.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.6.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.6.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (796.3 kB view details)

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

changeforest-0.6.1-cp39-cp39-macosx_10_7_x86_64.whl (410.4 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.6.1-cp38-none-win_amd64.whl (298.2 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.6.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.6.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.6.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (797.1 kB view details)

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

changeforest-0.6.1-cp38-cp38-macosx_10_7_x86_64.whl (410.8 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.6.1-cp37-none-win_amd64.whl (298.1 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.6.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.6.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.6.1-cp37-cp37m-macosx_10_7_x86_64.whl (410.8 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: changeforest-0.6.1.tar.gz
  • Upload date:
  • Size: 127.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.6.1.tar.gz
Algorithm Hash digest
SHA256 74eee9a51ab37dcce263c7d4c3963dc11ae1587ce1ef23415f5a144b794b8513
MD5 67b95533379ec742f522ea68699df603
BLAKE2b-256 6bf52fa516db5bb466419123ad11d76d94276559d65be861ada599bc08a5b3db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 7e0cc595f9cd508224fd039a412bd0e18424015494815cc4cc18908ea292a277
MD5 21e5de8c79dd01cbb98c05854354f724
BLAKE2b-256 37cd772ea25cccf26d5ebc6e33ec3d6883f8103c578c6007504972c47992d90e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 682e927298757677e1a8dc86dd7461524e36aab238f2709f38a16ad85d67d0f0
MD5 6bfb31c4f1d3204fce4dcdcc985dd92c
BLAKE2b-256 a8d1ea80d79bc5f06ed7b78f8a72a37bdcc89c2874f352a94fee41c0de69537c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 595cbef060cf7fbdd208e6799afd80480bdb7872f315faf7d0db8dffd64761da
MD5 f326fccc8c7800e10d1497a9437723e7
BLAKE2b-256 4dce620d75fb0335d47358b8c69e49fe4d434766c1f9da0359dae3f95f99daae

See more details on using hashes here.

File details

Details for the file changeforest-0.6.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.6.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 23b314893defd67759b4548aadb4dd3c053f0b86ab0a32ea27b2281edd0b14d5
MD5 38f9515ca18483a0ab908a5d66867637
BLAKE2b-256 18780e6c63c0099d3d6036765bf81b27b9f872553570abe4f4ef95df2f3cf9e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 2ada611c92dcdea444bc3d0dea27b440f7ba977bfa7fad949ee9543638d2ce2f
MD5 64b8a25977d752d2e487114b8ed4f733
BLAKE2b-256 5754ea0c2646884832c66f3b0a5114eeedaa2bd7d60c044847aa2a5509a53571

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.6.1-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 298.3 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.6.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 ded2c971abb5ec45405ad870cf8e4f2bc0260fbae7a9935b4131ca297223da9c
MD5 dda7eae7351a6b0890e7366651256f2b
BLAKE2b-256 b6070115cfd867ec1b3c72f65f6c2ea100e0d0c90688c61c3ddc53a67ab14652

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fdb83afba2a32970dec0a94aaf0fee80e1f5e3c19164f19894aea3afabeb24b8
MD5 39e7b25fad4257d7ab09ca95df452207
BLAKE2b-256 25420f08babc90c897bc7a9bc78180797c219a05146d3ed5d7013d9139237f3e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 49d46b4c099efb1edec20cc82b8baba97aad1d2b2ef717616997ae1f0c64de8d
MD5 15263d76e86f1f919235fcc706770be4
BLAKE2b-256 2fa033e1db22cc11bf0e2e0d1c5da48a6009408966f5601f4942917dd346585a

See more details on using hashes here.

File details

Details for the file changeforest-0.6.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.6.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 810723367bd84baee7df7b181708c23c320ee0d376c88492fb80ffad8e3aa140
MD5 cce38feaca1b38925da03496102db2f8
BLAKE2b-256 2f5d38c4c592e8eb1d7c4ea4f16e2defcbe52b27f918af9fd8ec9ac6ed34c1d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a0cabac2d4d5c4719081f7cbe47a1170dbd0c24664c5b6fb765a9c1dbfe7a97e
MD5 8df1ba4014ee2cb11f81db15a2c1c130
BLAKE2b-256 43ad80033fb307a23ba91e7380fd55cd494fc584b8247c4498aee6f1e41eb9e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.6.1-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 298.2 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.6.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 134a0841bb7936b9664bab7b9116b815a298b72554e2f0b50aef4e2b5a8dfec1
MD5 53071f6aa90646ee901bdea552715a9c
BLAKE2b-256 2db93767b9cae89e54c5ff854403a9cc6836601a139bfde5936b045c7fe09b23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6fa80fffac39fad2b5d72bf476f5f1584fd2c9bed7f6b0883cfe85d126cd897b
MD5 e69e6dc4fb1890ba52401399efff2b13
BLAKE2b-256 698732db6c3454178c414b90a31c395c76675a5483f9907fc00d2576e91629e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4f52d2c8c20d3076e4b277c81929b2c26e211bacc7e6ff3e7a730c49603b932b
MD5 b0493347cc0fa2a091cd81e0e42d8272
BLAKE2b-256 a3f3eaec4997f6cb20c1d556557c11bb933d112440f8334413e041cc4b3360b2

See more details on using hashes here.

File details

Details for the file changeforest-0.6.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.6.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 867eefee62e2fdeb4affa5c8bb3d530e542c20733b68a4560dbecef98f88e8bd
MD5 da3c6c14474c9cda941c867070e23db6
BLAKE2b-256 f37e4bf3559dfde4c926c69647bbbbd92cece0c610229a749a2c7a7bd07d6d5b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 01b996930ed9dea17f3f75d054467f58f8f96e7456f23f2031fe8e4b2e23b722
MD5 f02036b2773747a2b703272ee086c9e2
BLAKE2b-256 53d0191ed06fd28593eb2e42c4bce169c5ca2d980152a76cdc13d0ea01846888

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.6.1-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 298.1 kB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.6.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 64a18b84f4e7184afb5ebd45f416c0391d460e71e9861e650ad1d6caa9db38b0
MD5 5316acc1de0e44d36aefbf37ffd2aacb
BLAKE2b-256 d0c9f9f310ea184b0b3210f28a289bdbf0d51172a771c5cdd17914b67f2d4641

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c0b16e5c39921b4ab8746f00eb9ba11b106aff783158032bfa9109eccf35eb72
MD5 a4a13a90a80a9fded484e24c1ea85852
BLAKE2b-256 683ae85437497d1f4724ea8476d80802f2789b5de3c246b833b5f919e13473d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c123b43a14c1ca9cf97ff66c8203eb4b73c851bffa45448d1f94548875dafb7b
MD5 309c9fad04f01cd31ae838aa4706dbe8
BLAKE2b-256 c73d66f053594906e45482aeca9af47a3f8c67cd21c78b7d149db17943f90545

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.6.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 d8f5f83f0ab58a0b770501bec8d1c7cafb414b462be867b122f0d8a91a9c686d
MD5 bfa0f6d13ae8e6baa976474a51ed6474
BLAKE2b-256 6c3d94d9dca5b0df783c3966fa151bb235c3e830579c62092958fd7ee2038560

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