Segment statistics¶
segment_statistics describes the segments between detected changepoints:
their mean and spread, and the direction and size of each change.
Describe the segments between detected changepoints.
The detectors say where a series changes; segment_statistics says
how: the mean and spread of every segment, and for each changepoint the
direction and size of the change in mean (issue #42).
SegmentStatistics
¶
Bases: NamedTuple
Per-segment summaries returned by segment_statistics.
All fields are CPU tensors; the statistics are float64. For K
changepoints there are K + 1 segments. means and
stds have shape [K + 1] for univariate data and [K + 1, D]
for [T, D] data; the change fields have K rows.
Attributes:
| Name | Type | Description |
|---|---|---|
starts, ends |
Tensor
|
First index and one-past-last index of each segment ( |
lengths |
Tensor
|
Number of observations in each segment ( |
means |
Tensor
|
Sample mean of each segment. |
stds |
Tensor
|
Sample standard deviation of each segment ( |
mean_changes |
Tensor
|
|
z_scores |
Tensor
|
|
segment_statistics(data, starts)
¶
Mean, spread and direction of change for the segments between changepoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Tensor or array - like
|
The series, |
required |
starts
|
torch.Tensor or sequence of int
|
Index of the first observation of each new segment, as returned by
|
required |
Returns:
| Type | Description |
|---|---|
SegmentStatistics
|
See the class for the fields. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> stats = segment_statistics(data, get_map_changepoints(R))
>>> stats.mean_changes # tensor([ 3.1, -2.9]): up at the first change, down at the second