strength_of_trend
timecave.data_characteristics.strength_of_trend(ts)
Compute the strength of trend of a time series.
This function computes the strength of trend of a given time series using the method employed by Cerqueira et. al (2020) (i.e. the ratio between the time series' standard deviation and that of the differenced time series).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts |
ndarray | Series
|
Univariate time series. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Strength of trend. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Notes
Let \(\sigma\) be the standard deviation of a given time series. The strength of trend of a series is defined by Cerqueira et al [1] as:
where \(ts\) stands for the time series itself and \(diff\) denotes the differenced time series.
References
1
Cerqueira, V., Torgo, L., Mozetiˇc, I., 2020. Evaluating time series forecasting models: An empirical study on performance estimation methods. Machine Learning 109, 1997–2028.
Examples:
>>> import numpy as np
>>> from timecave.data_characteristics import strength_of_trend
>>> rng = np.random.default_rng(seed=1);
>>> noise = rng.uniform(low=0, high=0.01, size=10);
>>> constant_series = np.ones(10);
>>> strength_of_trend(constant_series + noise)
0.5717034302917938
For a series with a strong trend, this value will be larger:
For pure trends, the strength of trend is infinite:
If the time series is neither an array nor a series, an exception is thrown:
>>> strength_of_trend([0, 1, 2])
Traceback (most recent call last):
...
TypeError: Time series must be either a Numpy array or a Pandas series.
Source code in timecave/data_characteristics.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |