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.3.tar.gz (125.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.4.3-cp310-none-win_amd64.whl (304.9 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.4.3-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.3-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.3-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.7 kB view details)

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

changeforest-0.4.3-cp310-cp310-macosx_10_7_x86_64.whl (426.0 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.4.3-cp39-none-win_amd64.whl (305.0 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.4.3-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.3-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.3-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.7 kB view details)

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

changeforest-0.4.3-cp39-cp39-macosx_10_7_x86_64.whl (426.0 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.4.3-cp38-none-win_amd64.whl (304.9 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.4.3-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.3-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.3-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.7 kB view details)

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

changeforest-0.4.3-cp38-cp38-macosx_10_7_x86_64.whl (426.0 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.4.3-cp37-none-win_amd64.whl (305.2 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.4.3-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.3-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.3-cp37-cp37m-macosx_10_7_x86_64.whl (426.0 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.4.3.tar.gz
Algorithm Hash digest
SHA256 9e5692399779fcef35999e0d11904ca89455508308ee2cffbdc98f5c2d05572a
MD5 4e1e1bccfdcb5aa3a3e2cf6393ea81bb
BLAKE2b-256 03cb7e70f4164ac093876a500bec27874214c88707b7a5b8c331c1eaa3770038

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.4.3-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 6f23be54072524fd2f67792e3445d4c039d62650b0454b2f137696a5ca64619f
MD5 432a6194838791a8c828d44d77e813bc
BLAKE2b-256 83517af3b6dd9d8232cd0c86ba991bda7a281a04fb1fa3a76a320d130f27539c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 038b264e90ba66860b42b9f1290f64a0513f6ab094b01832575e453242545464
MD5 4c06a95c8a2517041d7f330664efdfaa
BLAKE2b-256 de414c9025526b4209827b427841e4dc3a6c114e9918aa4213519c139b08d83b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a4bdcf92a929d0d8f65ce9ec637db7eb0bf042a7189fdfc14acd6e297e9e1ae8
MD5 1be9ae19a2273240bed362e84b3e970c
BLAKE2b-256 f726af6ab5f8d6e988e96f122a55edda9e5612eac6853b92ae8e066b717008b7

See more details on using hashes here.

File details

Details for the file changeforest-0.4.3-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.3-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6c20cbf4c4674f5189d21b3d9fad84722e44804f2cb8c4d978d80ca486eed910
MD5 4dc42b8aa740139a016cb85a420abdf2
BLAKE2b-256 baf580d84c0e179e026f3b0664edac823abf05f08fa6be02cbbfb8bd0b765c86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.3-cp310-cp310-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 426.0 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.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for changeforest-0.4.3-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 cdd84cba29e794e90ada2ebe2235ba626b9927f320aa663fcacc6aa69083ddb8
MD5 378c1121f05029b9ec5fd154ff8fdbb0
BLAKE2b-256 06cc05e4b8a271da5a2f7046ae3ffe12b6847a42f0d9c3914c6cc6e0b45d563a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.4.3-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 15e28aa7dd807e54a801af77af61ab4c391e936d5c65fa6fe0f843a2f89a47cc
MD5 4528e98cc9174c86c1a61cbef398452d
BLAKE2b-256 e30dc58bfcb2edde6d47d8e771e31ab3b34e0a18e5a698bd74872d846fd1cb89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 022a321de72839f1af7332d821e306746f433723cc6329fa8c26705bc3449950
MD5 64774d53b6a7f1390318e6d8a90b0193
BLAKE2b-256 924d17b205b7ee941d8dc10ea1c812cebbf8754cc845fb60e0e6a76b316ffdb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 64a663e1eeb01dbb87865b49b581f88e73f7a2e676c87055b586c74d07a08106
MD5 0430667bf672dd64a915f6c2327fb5ec
BLAKE2b-256 8c2656cf28c3469b096e33d0458cda6d4858d8d6115baf0f013a5f8ab778df4a

See more details on using hashes here.

File details

Details for the file changeforest-0.4.3-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.3-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 4c520250b74c41a4a4104c556db056099ac7fac781e2b25d712d2d65c6872787
MD5 8906aa87340cefee7bc932039e4913ed
BLAKE2b-256 d669b7f1b2b756c58c34209f52a19fb62b47a40c519710617385d2d53f240cea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.3-cp39-cp39-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 426.0 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.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for changeforest-0.4.3-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ae475c88d116b41ad051ed3fb947489f5d4e8a9cf0922ae75737133389050d63
MD5 572a9bef934360e1dafa54de4dc2eadd
BLAKE2b-256 5215086a28026e73a70ff5ca59947e55276a9209970962ed7b7df5885bccf3da

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.4.3-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 f8f3b3401289fbbe7a541dfe5f5d9b3e6edd88663a23f3a227e6e0998bac7920
MD5 cea9501c6947366d8d2b4b2a35353793
BLAKE2b-256 7693f3c4dd76a384c2b1347267404003e19eaae2a80c2c2cfa9f5acb2cafc493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6beb6bc0fcf8e24739eef22d4201a40275f4d03f5eb84ff57adf38f7f6efa856
MD5 acaad622a0917a359810f2cc8d09f3dc
BLAKE2b-256 c9f0e79b23317f6f0d76722524ff6ac5d4cdfc4b81ea32945d56d033473e56f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 55496dbf70022807913337190d5371475e74dcd5c6ff540c8b914443be8495bb
MD5 9e4b1e567c3408ed1f082c9c26e10270
BLAKE2b-256 c48bd20e586ca6667b6581e0c84c94ffe90b6168179203323423ee6acf7302e0

See more details on using hashes here.

File details

Details for the file changeforest-0.4.3-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.3-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 bdf4135f10a038990d0865cb88a764f124ce52c1f73796a399a59b9a753deed6
MD5 3ee94016e49388111de551c7fa09105e
BLAKE2b-256 40e360a68ef6282ffe9b722fd76dba1416cc8c3295eb5b6ec6d3f862a6d67720

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.3-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 426.0 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.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for changeforest-0.4.3-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8cc1c88496837f8b7dc554b7ae4edc1a95eb235e1068630dc437b82f9440f227
MD5 0a2cb41a59d56ee83d0f0bc2dc0c6f39
BLAKE2b-256 aa28605f45e8aa6e29989269c3f23988a3fc4a8fe74fef297b9d417169820c39

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.4.3-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 52f585376abaf9e1e53ef3cbacb56fcf247ea2361c3387d3f8ed3ff56a5bcd8f
MD5 8333a1ae291f6de6d76f19fe87b4c41c
BLAKE2b-256 e574ae15c56e4efa7c66102e51b27b0796d5d70c07bc162ce16e0f2b852911e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bac0700e2297f6e24ea84debb2f354b9644b579f518dab6f82fd205f921cad7f
MD5 be0080b9e7c70ef0dcafa99f55c4d2cb
BLAKE2b-256 a864de1a99fa235941ef6baeac4aa22898832413cfa3cdfc0d927bb10bcb275a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4fed1ff3b908ff4e40a8e84461cb057e6941c56d92b434a87f8e1e2d37efb326
MD5 bfb0c8b7a85c0f982e9bfbc88bbd1d11
BLAKE2b-256 597238bd921d1ef83d92bc02ea9ae2b1ee7614c1c75c487733213319022b2212

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.3-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 426.0 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.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for changeforest-0.4.3-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 4ef1da852a5faff8cbe60e1a7b4b46b11e7243fa380a893024cc925fdd9772d6
MD5 19c42a1b332f83d5d9d5b9ea91b4ad08
BLAKE2b-256 f388a2f26daa69c5e62c1c8d246be2d9878c96cc1c2d9c30a1529be2f76e3a39

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