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.2.tar.gz (125.3 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.2-cp310-none-win_amd64.whl (305.3 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.4.2-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.2-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.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.2 kB view details)

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

changeforest-0.4.2-cp310-cp310-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

changeforest-0.4.2-cp39-none-win_amd64.whl (305.2 kB view details)

Uploaded CPython 3.9Windows x86-64

changeforest-0.4.2-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.2-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.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.2 kB view details)

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

changeforest-0.4.2-cp39-cp39-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.4.2-cp38-none-win_amd64.whl (305.2 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.4.2-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.2-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.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (835.2 kB view details)

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

changeforest-0.4.2-cp38-cp38-macosx_10_7_x86_64.whl (425.8 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

changeforest-0.4.2-cp37-none-win_amd64.whl (305.3 kB view details)

Uploaded CPython 3.7Windows x86-64

changeforest-0.4.2-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.2-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.2-cp37-cp37m-macosx_10_7_x86_64.whl (425.9 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

  • Download URL: changeforest-0.4.2.tar.gz
  • Upload date:
  • Size: 125.3 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.2.tar.gz
Algorithm Hash digest
SHA256 f37810e12c04135b9404036864db3a7fc67e651530c54b2cea3bd5b14215164b
MD5 c27af474b2a4fe19fa1cf92e7c3e7868
BLAKE2b-256 365ad2866c202edbca7541569237b6e45cfc8ae64940e251ce6636dae5461f05

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 305.3 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.2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 bbdb91c61e470c868223661b79a6c3556d6b9b38c3c207599af30a42a7c5e8ae
MD5 24e44939770f9c528bce33d92e029d13
BLAKE2b-256 25db8e08688e839087d26444c99a7681ab976050296676047a433a93cb8714d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 613a303b65176b2f8efa6fff095c82bd6b81f89309e10f3c6875e6191323bcae
MD5 993cb5ad0de90c1fb12f2fce91f628af
BLAKE2b-256 d4ef39022fd4548137e505cb8df28fcdb2f596cae3dd7204672f5a1b4968a77e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fa1e892b49dd59422cf70b187a835de9239728e6e176c85643abe85eff8b6a39
MD5 dcc6e6bccb171d44c8ce969a2917e947
BLAKE2b-256 575b1683a7c690285ecee3e84ea90b64d7d5a4c0712b82079b976e555d423092

See more details on using hashes here.

File details

Details for the file changeforest-0.4.2-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.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 656c9c745f15347591687517b7831207b4aec08265ac5ea906c6fed9b9d18ea0
MD5 2d163086f290f8cb989bfb0160212a19
BLAKE2b-256 2e9f56a46e4e9172083aedb3b0af5ba8672c69dd4077cb8700134d224abdf087

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-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.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.2-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 6e7765410dab79b45da82a088b354325567cdff134bebd6e99b0e17a7d1564bb
MD5 8b1afa8b1d4c7970de628091193db7a3
BLAKE2b-256 a564b41424b4617682bfb78d9820b035325bd192f80bc17468b9d8f0fd9bb3d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 305.2 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.2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 5010a12ecae246ac6484b61884f6b3cb2aab9f2d6f8b3b33ce0e82696a37dd19
MD5 e667a0226746e64d100af15cf52119cd
BLAKE2b-256 b7e850de1c6dab421bc0a9cc4ed88275abc44564d978fc0a456273282bd269c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3c2c64c1e5aaa67cce3563e34614765c1b93cba042c3ec5afeae0ed6f07d74e
MD5 6e10464e9fa4c46440a4cbecd5d7c631
BLAKE2b-256 17e2268840d79d233d974ee3e7cbcf96493ad498a983fb31ee95a1420f9b03af

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 add22afc860459e64271ed9af411307abb6e43f4d383c6f927d0a1349c3a7a07
MD5 4977ff0af980251b2ab8671935fd3677
BLAKE2b-256 efd53e7e28758b1282927d835d353b0730acbba76df8795836bdcc7859c1e6be

See more details on using hashes here.

File details

Details for the file changeforest-0.4.2-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.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 008e19a2c64069ee7f9559d2e87244556a4d7320eb7b04aa321463d158b1e1f8
MD5 6a528d6f62178fdd43bcc3a43ea3ade7
BLAKE2b-256 34eb431ac30f086474f95cd0a6b591c0658b82d93429e24365a392a882481307

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-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.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.2-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 54967b68ba6691f1c4ce75d882c20a8b794269bf9c428c4e16c5ced01606ffa8
MD5 523d99f559a405aaf1c5c9fd9069eed3
BLAKE2b-256 dd8079ef84d68cbb76a5d9d3d35351359f3d5719313fa488c76c60feeb505392

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 305.2 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.2-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 1da82a4217cd57b453dffea7709bdc975b2a89ea32cf761f7490e7ba784daa0c
MD5 4d4397f096c4b355f46400063bb9e755
BLAKE2b-256 78a836bacfd8a59adb119f379df681ffdeb2d2a93ad72db5110693286841e8f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66f17be5967a99eb495c24cdf39e1f44443e514c14a86177ce93a4ffd2c29531
MD5 9ce63d8cee16adf60715431f3a70a0a0
BLAKE2b-256 637f9cbd997a4c924e28a4297f502f6981ff66fdff14f73e4b834d1cebdff245

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4332a0c07ae627daedbff86ede205c9781a3abc58944d79b979538b9c0016487
MD5 f1bb6f46bc587a17c51809e9c97bdba3
BLAKE2b-256 9037abc7fe705ebb16c2ea754e0cff7ad2e579285d68c4cb33c2f05251c8f5ad

See more details on using hashes here.

File details

Details for the file changeforest-0.4.2-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.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2ede0f83487f70fadbf47034bf1da2b55374da99c98d01eaf3701e1c5aa82ff9
MD5 19b0eca63a092101d3a123e1bcb6cd3c
BLAKE2b-256 4910262d21ca9726fbc83c74b29247ca731c86e6ec3ba9301ecd2e98ad4b30fd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-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.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.2-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 5d0cbd8cc003bb88743fb4bdfc0c4bc9490ca3e6d0392ca07a56684948a2177d
MD5 0ebab6e7c895f906953ea4891636ae02
BLAKE2b-256 d0309589e07ffc0907569a64d595b8354db00deb9cc1f5dffe5eddad4b62cd4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 305.3 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.2-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 37bf981c271b9fe98a7e8a189feedb8c4638d9559188a0f50c76c1d4127622b7
MD5 348d6fb4b889f92242bd479431c8ddf6
BLAKE2b-256 93a9b82c09fbaab0bd705e66088151300e3a55a05fd7f294e644aaeec7e0f6fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bafe00bfb8ba1375c03d54f0c00abc67ff2c9d622814f578475805042023b17a
MD5 cea14ce1bf770ea49f2902e031795730
BLAKE2b-256 e32191b5077c8b03677ffde083253698b75173b33994c7fe24d5268ce747906b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.4.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6c0b3f67425580849bae0606ec6aeb22f6cb5a3924dd390def0b6ef5b754088a
MD5 e32494191e2f175b82ca118c78fb7d41
BLAKE2b-256 03644798acd4043eb361064211fc6bc67622d59de4186f95be3afaec64e20a4a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.4.2-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 425.9 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.2-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 966e3869b3c31dcd6b4f6f8d7cc07ac4ef9f42980d3250e5b6ab2f6d64cc3347
MD5 73c1c8a7b424ff095ec2b80fc4686090
BLAKE2b-256 abbaa6299c5182a55b99cf105135836ae7e7cd0bc23c1ff7d48e92b479165b2e

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