Skip to main content

Classifier based non-parametric change point detection

Project description

Random Forests for Change Point Detection

Change point detection aims to identify structural breaks in the probability distribution of a time series. Existing methods either assume a parametric model for within-segment distributions or are based on ranks or distances and thus fail in scenarios with a reasonably large dimensionality.

changeforest implements a classifier-based algorithm that consistently estimates change points without any parametric assumptions, even in high-dimensional scenarios. It uses the out-of-bag probability predictions of a random forest to construct a pseudo-log-likelihood that gets optimized using a computationally feasible two-step method.

See [1] for details.

Installation

To install from conda-forge (recommended), run

conda install -c conda-forge changeforest

To install from PyPI, run

pip install changeforest

Example

In the following example, we perform random forest-based change point detection on a simulated dataset with n=600 observations and covariance shifts at t=200, 400.

In [1]: import numpy as np
   ...: 
   ...: Sigma = np.full((5, 5), 0.7)
   ...: np.fill_diagonal(Sigma, 1)
   ...: 
   ...: rng = np.random.default_rng(12)
   ...: X = np.concatenate(
   ...:     (
   ...:         rng.normal(0, 1, (200, 5)),
   ...:         rng.multivariate_normal(np.zeros(5), Sigma, 200),
   ...:         rng.normal(0, 1, (200, 5)),
   ...:     ),
   ...:     axis=0,
   ...: )

The simulated dataset X coincides with the change in covariance (CIC) setup described in [1]. Observations in the first and last segment are independently drawn from a standard multivariate Gaussian distribution. Observations in the second segment are i.i.d. normal with mean zero and unit variance, but with a covariance of ρ = 0.7 between coordinates. This is a challenging scenario.

In [2]: from changeforest import changeforest
   ...: 
   ...: result = changeforest(X, "random_forest", "bs")
   ...: result
Out[2]: 
                    best_split max_gain p_value
(0, 600]                   412   19.603   0.005
 ¦--(0, 412]               201   62.981   0.005
 ¦   ¦--(0, 201]           194  -12.951    0.76
 ¦   °--(201, 412]         211   -9.211   0.545
 °--(412, 600]             418  -37.519   0.915

In [3]: result.split_points()
Out[3]: [201, 412]

changeforest correctly identifies the change point around t=200 but is slightly off at t=412. The changeforest function returns a BinarySegmentationResult. We use its plot method to investigate the gain curves maximized by the change point estimates:

In [4]: result.plot().show()

Change point estimates are marked in red.

For method="random_forest" and method="knn", the changeforest algorithm uses a two-step approach to find an optimizer of the gain. This fits a classifier for three split candidates at the segment's 1/4, 1/2 and 3/4 quantiles, computes approximate gain curves using the resulting pseudo-log-likelihoods and selects the overall optimizer as a second guess. We can investigate the gain curves from the optimizer using the plot method of OptimizerResult. The initial guesses are marked in blue.

In [5]: result.optimizer_result.plot().show()

One can observe that the approximate gain curves are piecewise linear, with maxima around the true underlying change points.

The BinarySegmentationResult returned by changeforest is 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 investigate the output of the algorithm further.

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 20 trees:

In [6]: from changeforest import Control
   ...: changeforest(X, "random_forest", "bs", Control(random_forest_n_estimators=20))
Out[6]: 
                            best_split max_gain p_value
(0, 600]                           592  -11.786    0.01
 ¦--(0, 592]                       121    -6.26   0.015
 ¦   ¦--(0, 121]                    13  -14.219   0.615
 ¦   °--(121, 592]                 416   21.272   0.005
 ¦       ¦--(121, 416]             201   37.157   0.005
 ¦       ¦   ¦--(121, 201]         192   -17.54    0.65
 ¦       ¦   °--(201, 416]         207   -6.701    0.74
 ¦       °--(416, 592]             584  -44.054   0.935
 °--(592, 600]     

The changeforest algorithm still detects change points around t=200, 400 but also returns two false positives.

Due to the nature of the change, method="change_in_mean" is unable to detect any change points at all:

In [7]: changeforest(X, "change_in_mean", "bs")
Out[7]: 
          best_split max_gain p_value
(0, 600]         589    8.318 

References

[1] M. Londschien, S. Kovács and P. Bühlmann (2022), "Random Forests for 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.7.1.tar.gz (374.7 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.7.1-cp310-none-win_amd64.whl (305.2 kB view details)

Uploaded CPython 3.10Windows x86-64

changeforest-0.7.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.7.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.7.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (818.1 kB view details)

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

changeforest-0.7.1-cp310-cp310-macosx_10_7_x86_64.whl (421.2 kB view details)

Uploaded CPython 3.10macOS 10.7+ x86-64

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

Uploaded CPython 3.9Windows x86-64

changeforest-0.7.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.7.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.7.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (818.2 kB view details)

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

changeforest-0.7.1-cp39-cp39-macosx_10_7_x86_64.whl (421.2 kB view details)

Uploaded CPython 3.9macOS 10.7+ x86-64

changeforest-0.7.1-cp38-none-win_amd64.whl (305.0 kB view details)

Uploaded CPython 3.8Windows x86-64

changeforest-0.7.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.7.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.7.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (818.2 kB view details)

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

changeforest-0.7.1-cp38-cp38-macosx_10_7_x86_64.whl (421.3 kB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

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

Uploaded CPython 3.7Windows x86-64

changeforest-0.7.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.7.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.7.1-cp37-cp37m-macosx_10_7_x86_64.whl (420.7 kB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

File details

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

File metadata

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

File hashes

Hashes for changeforest-0.7.1.tar.gz
Algorithm Hash digest
SHA256 7c8d2ab0543a78c1398803a91ef7729baa2336e43c92c5c942d38aed487b3292
MD5 a1ad6da4844f150f328cce0b3706d024
BLAKE2b-256 8f815cdf172cfb983558b76be89554d32c231426abbde3a99d6bc3699e1128ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 b645d65496363bc6129f0b3a4f08a52849d92eb23dc214ea7816ecc79ec0dc35
MD5 1f942ee7755ec7ccde3dce5f8c6465f9
BLAKE2b-256 9a3dde7948bb4576626c3d359f77530066fae2bef4d1bfa74ebe027d7c9defd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 017757dba1cbce10f0cc8952343f0372d9b7be17f5d36250e78ed44e5ee5cf3b
MD5 35b33ed44169bb6cc9b1defc71c14150
BLAKE2b-256 5fa0021743e6ab7b3e9fbc6bcffb87795dda57e6f7e15b567701cdeb0ad7046b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2931287c5746aba7295c2ec932d3a5b006c1df68309e780ca3a16d174bf23912
MD5 9d713f803d39fe8d9215fc8731055178
BLAKE2b-256 f279b9b3bf0a89efe45f23cd22ae02ad376da235542a1f19b7291a83e49e7451

See more details on using hashes here.

File details

Details for the file changeforest-0.7.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.7.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 26aee0d16c7e36179ffd93561c1ee5e1590826dee2ce0ece7cb8fb874fd9a0fc
MD5 a8a60970e1212a6559f986da8fd5fa9e
BLAKE2b-256 bb7bfa2087036923a35a0b19f5da8a59175c4f6a4d372c5367683f19211c7ceb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 d5ac928d4c851e6754f6fe00686bc46a033a62eb82ab2ab116632127056267c3
MD5 5572002418574580533031264f3b42db
BLAKE2b-256 17d8efe20b3897964e80decf48338869dd0002b54a4d542a4a11170866641e1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.7.1-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/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.7.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 da3f2657907ad0e5fb573027f484babe1b0c696d1331fc5c11a4258ecb8c8010
MD5 9e4c9604332c9d77adfc9b676d79cc25
BLAKE2b-256 1411a1f68e1356e78b049a351b33be2eef55c230adb3bb87693c5a76c3d52353

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a14bc197e5fd5480fa1795397248704730d110d593243349cdcc47f60a58d9f9
MD5 de21f1a5dad761ac2239f95725071f7c
BLAKE2b-256 5751be99906906d061bb60f8b8fa5e844365122086b16533404cd5169fa9aa1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a801df467cb26017f8f9460085166173059bf1ccf93b884ec058fc88441d487e
MD5 65a074ba6b539741ff369c2b6d22c23f
BLAKE2b-256 0c4a0535c9e5c025facaf025d74e65a665d1ba579e007645aab6ae01c75e5093

See more details on using hashes here.

File details

Details for the file changeforest-0.7.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.7.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b21f91a3957c6eef4d414089a43ebb4430a9623e49060fe0f4cd1f381773b99f
MD5 13c8213ce903d6423e219ac3d19baeb5
BLAKE2b-256 5fb675503539fb02a71557c8cd76d319e6f5911380cdaaee05b95b57c4fe433f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1574b062a6d34ecb32266ee7605f603df477e9dd443de6865b01574401430cd5
MD5 f4adbd037d393c120572d935a76a8edd
BLAKE2b-256 b3a3d29293f871e619720cd18dee2b26fb361b0c72baddcee70448798fcf2ebe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.7.1-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 305.0 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.7.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 a08989e49a05149eac93347764ae8bcad103525498fb70d9e198351fcc360c59
MD5 62004cdcb4e950696cf8c0f5e380adb1
BLAKE2b-256 6768274909c04b74a2fcca58ff1d320b2cd7294cd59df4b5e4dc554367f4dca0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3773eeaa8787ae6abfc0d619f066b5b9bc7d181021963438103972a2bfeb71ac
MD5 6e2367f3145c38ec747ab656f6134573
BLAKE2b-256 68c2ab26e611fd2e605a4301b3ba0d5f613f34c75ca3eb159fab3241e49d861e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8e18b3f6fe2181305d245586fd3e8a26110fea4b3926f87d841f0f1b0c7acc3a
MD5 00cefa4d4c1b92d0ba6cdbd0c460e68e
BLAKE2b-256 bb44507945e13eb9d05d0823a182324f264f8b063c25a99e839a6fbb7c5e802f

See more details on using hashes here.

File details

Details for the file changeforest-0.7.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.7.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 2053a254fe2981d79909ad0c7137fcc83ef3b28f8a8d649cf04f3bffa14457e9
MD5 5c45a2065468fa6b9b005c1cd37216fc
BLAKE2b-256 200826bb7abaeb3dfa926ee7fc0a8a65d9a739d9adad56afd2035e10eb3f33f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b00d554d450daf54d1cd29113daeedafcc427d73027ad809173508894185cad5
MD5 985b3b06d1c63f1553f99194bc6f9c0b
BLAKE2b-256 a9953320ae7821988755e3f24bc6a3d306c78014670833c0ace502eaa58eedfd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: changeforest-0.7.1-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/4.0.0 CPython/3.9.12

File hashes

Hashes for changeforest-0.7.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 3770771d710876b4cdda40e3da3fbef98f2f12150a3080ce7a9b0d7e40160b28
MD5 6219e7791815a63efa16e9255e8b358a
BLAKE2b-256 c8ce2e883e778c808c2232af9795dfedde044e336ec80a73884868c6fb11c831

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f3bdd2f19999786757b9dbad04dda9135ca58650075b87e99b6e6fe81d61731
MD5 24b9a23ed028f749832ba82028d2efe2
BLAKE2b-256 663bea5778b3b58356c38773627678bff1fb1e45bbe6612d909fdda505e2f1b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 61a277f02c32aa82126322295fd11c6499ea965a588d39053f88e91d59ce14b3
MD5 f4cb8f2373c6b0087ef0eeb743999783
BLAKE2b-256 ec7b2d0c06ecbb11c6f5f470d8af58772c6258b11edd7bf4ffb1a44aaf3b0bf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for changeforest-0.7.1-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 a4f70919150c3397c515fef5a1d5a34a4f353c4542d85d1134b99f38517f5e68
MD5 231b400b3a3dbbaf0aeddead8e447688
BLAKE2b-256 851d5cb2b3b75ae9805ae8e6583f910bf12eb44d7890fb9e044a822b8feddfaa

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