Forecastability Measure. Args: ts: time series Returns: 1 - the entropy of the fourier transformation of time series / entropy of white noise
(ts)
| 4 | |
| 5 | |
| 6 | def forecastabilty(ts): |
| 7 | """Forecastability Measure. |
| 8 | |
| 9 | Args: |
| 10 | ts: time series |
| 11 | |
| 12 | Returns: |
| 13 | 1 - the entropy of the fourier transformation of |
| 14 | time series / entropy of white noise |
| 15 | """ |
| 16 | ts = (ts - ts.min())/(ts.max()-ts.min()+0.1) |
| 17 | # fourier_ts = np.fft.rfft(ts).real |
| 18 | fourier_ts = abs(np.fft.rfft(ts)) |
| 19 | fourier_ts = (fourier_ts - fourier_ts.min()) / ( |
| 20 | fourier_ts.max() - fourier_ts.min()) |
| 21 | fourier_ts /= fourier_ts.sum() |
| 22 | entropy_ts = entropy(fourier_ts) |
| 23 | fore_ts = 1-entropy_ts/(np.log(len(ts))) |
| 24 | if np.isnan(fore_ts): |
| 25 | return 0 |
| 26 | return fore_ts |
| 27 | |
| 28 | |
| 29 | def forecastabilty_moving(ts, window, jump=1): |
no outgoing calls
no test coverage detected