Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Seasonal PAC features #31

Merged
merged 3 commits into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions tsfeatures/tests/test_pacf_features.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
#!/usr/bin/env python
# coding: utf-8

from math import isclose
import numpy as np
from tsfeatures import pacf_features
from tsfeatures.utils import WWWusage, USAccDeaths

def test_pacf_features_seasonal():
z = pacf_features(USAccDeaths, 12)
assert isclose(len(z), 4)
assert isclose(z['x_pacf5'], 0.63, abs_tol=0.01)
assert isclose(z['diff1x_pacf5'], 0.09, abs_tol=0.01)
assert isclose(z['diff2x_pacf5'], 0.38, abs_tol=0.01)
assert isclose(z['seas_pacf'], 0.12, abs_tol=0.01)

def test_pacf_features_non_seasonal():
z = pacf_features(WWWusage, 1)
assert isclose(len(z), 3)
assert isclose(z['x_pacf5'], 1.03, abs_tol=0.01)
assert isclose(z['diff1x_pacf5'], 0.80, abs_tol=0.01)
assert isclose(z['diff2x_pacf5'], 0.22, abs_tol=0.01)
def test_pacf_features_seasonal_short():
z = np.random.normal(size=15)
pacf_features(z, freq=7)
5 changes: 4 additions & 1 deletion tsfeatures/tsfeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,10 @@ def pacf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
}

if m > 1:
output['seas_pacf'] = pacfx[m] if len(pacfx) > m else np.nan
try:
output['seas_pacf'] = pacfx[m] if len(pacfx) > m else np.nan
except:
output['seas_pacf'] = np.nan

return output

Expand Down