Skip to content

Commit e9c1b94

Browse files
committed
run nbdev_export
1 parent 2dd6a65 commit e9c1b94

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

tsfeatures/_modidx.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
'doc_host': 'https://Nixtla.github.io',
66
'git_url': 'https://github.com/Nixtla/tsfeatures',
77
'lib_path': 'tsfeatures'},
8-
'syms': { 'tsfeatures.m4_data': { 'tsfeatures.m4_data.m4_parser': ('m4_data.html#m4_parser', 'tsfeatures/m4_data.py'),
8+
'syms': { 'tsfeatures.compare_with_r': {},
9+
'tsfeatures.m4_data': { 'tsfeatures.m4_data.m4_parser': ('m4_data.html#m4_parser', 'tsfeatures/m4_data.py'),
910
'tsfeatures.m4_data.maybe_download': ('m4_data.html#maybe_download', 'tsfeatures/m4_data.py'),
1011
'tsfeatures.m4_data.prepare_m4_data': ('m4_data.html#prepare_m4_data', 'tsfeatures/m4_data.py')},
1112
'tsfeatures.tsfeatures': { 'tsfeatures.tsfeatures._get_feats': ('tsfeatures.html#_get_feats', 'tsfeatures/tsfeatures.py'),
@@ -34,6 +35,7 @@
3435
'tsfeatures.tsfeatures.tsfeatures': ('tsfeatures.html#tsfeatures', 'tsfeatures/tsfeatures.py'),
3536
'tsfeatures.tsfeatures.unitroot_kpss': ('tsfeatures.html#unitroot_kpss', 'tsfeatures/tsfeatures.py'),
3637
'tsfeatures.tsfeatures.unitroot_pp': ('tsfeatures.html#unitroot_pp', 'tsfeatures/tsfeatures.py')},
38+
'tsfeatures.tsfeatures_r': {},
3739
'tsfeatures.utils': { 'tsfeatures.utils.embed': ('utils.html#embed', 'tsfeatures/utils.py'),
3840
'tsfeatures.utils.hurst_exponent': ('utils.html#hurst_exponent', 'tsfeatures/utils.py'),
3941
'tsfeatures.utils.lambda_coef_var': ('utils.html#lambda_coef_var', 'tsfeatures/utils.py'),

tsfeatures/tsfeatures.py

+41-33
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/tsfeatures.ipynb.
22

33
# %% auto 0
4-
__all__ = ['FREQS', 'acf_features', 'arch_stat', 'count_entropy', 'crossing_points', 'entropy', 'flat_spots', 'frequency',
5-
'guerrero', 'heterogeneity', 'holt_parameters', 'hurst', 'hw_parameters', 'intervals', 'lumpiness',
6-
'nonlinearity', 'pacf_features', 'series_length', 'sparsity', 'stability', 'stl_features', 'unitroot_kpss',
7-
'unitroot_pp', 'tsfeatures']
4+
__all__ = ['acf_features', 'arch_stat', 'count_entropy', 'crossing_points', 'entropy', 'flat_spots', 'frequency', 'guerrero',
5+
'heterogeneity', 'holt_parameters', 'hurst', 'hw_parameters', 'intervals', 'lumpiness', 'nonlinearity',
6+
'pacf_features', 'series_length', 'sparsity', 'stability', 'stl_features', 'unitroot_kpss', 'unitroot_pp',
7+
'tsfeatures']
88

99
# %% ../nbs/tsfeatures.ipynb 3
1010
import os
@@ -45,9 +45,6 @@
4545
from .utils import *
4646

4747
# %% ../nbs/tsfeatures.ipynb 7
48-
FREQS = {"H": 24, "D": 1, "M": 12, "Q": 4, "W": 1, "Y": 1}
49-
50-
# %% ../nbs/tsfeatures.ipynb 8
5148
def acf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
5249
"""Calculates autocorrelation function features.
5350
@@ -87,7 +84,12 @@ def acf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
8784
else:
8885
acfdiff2x = [np.nan] * 2
8986
# first autocorrelation coefficient
90-
acf_1 = acfx[1]
87+
88+
try:
89+
acf_1 = acfx[1]
90+
except:
91+
acf_1 = np.nan
92+
9193
# sum of squares of first 10 autocorrelation coefficients
9294
sum_of_sq_acf10 = np.sum((acfx[1:11]) ** 2) if size_x > 10 else np.nan
9395
# first autocorrelation ciefficient of differenced series
@@ -113,7 +115,7 @@ def acf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
113115

114116
return output
115117

116-
# %% ../nbs/tsfeatures.ipynb 11
118+
# %% ../nbs/tsfeatures.ipynb 10
117119
def arch_stat(
118120
x: np.array, freq: int = 1, lags: int = 12, demean: bool = True
119121
) -> Dict[str, float]:
@@ -134,7 +136,7 @@ def arch_stat(
134136
if len(x) <= lags + 1:
135137
return {"arch_lm": np.nan}
136138
if demean:
137-
x -= np.mean(x)
139+
x = x - np.mean(x)
138140

139141
size_x = len(x)
140142
mat = embed(x**2, lags + 1)
@@ -148,7 +150,7 @@ def arch_stat(
148150

149151
return {"arch_lm": r_squared}
150152

151-
# %% ../nbs/tsfeatures.ipynb 14
153+
# %% ../nbs/tsfeatures.ipynb 13
152154
def count_entropy(x: np.array, freq: int = 1) -> Dict[str, float]:
153155
"""Count entropy.
154156
@@ -169,7 +171,7 @@ def count_entropy(x: np.array, freq: int = 1) -> Dict[str, float]:
169171

170172
return {"count_entropy": entropy}
171173

172-
# %% ../nbs/tsfeatures.ipynb 15
174+
# %% ../nbs/tsfeatures.ipynb 14
173175
def crossing_points(x: np.array, freq: int = 1) -> Dict[str, float]:
174176
"""Crossing points.
175177
@@ -194,7 +196,7 @@ def crossing_points(x: np.array, freq: int = 1) -> Dict[str, float]:
194196

195197
return {"crossing_points": cross.sum()}
196198

197-
# %% ../nbs/tsfeatures.ipynb 16
199+
# %% ../nbs/tsfeatures.ipynb 15
198200
def entropy(x: np.array, freq: int = 1, base: float = e) -> Dict[str, float]:
199201
"""Calculates sample entropy.
200202
@@ -218,7 +220,7 @@ def entropy(x: np.array, freq: int = 1, base: float = e) -> Dict[str, float]:
218220

219221
return {"entropy": entropy}
220222

221-
# %% ../nbs/tsfeatures.ipynb 17
223+
# %% ../nbs/tsfeatures.ipynb 16
222224
def flat_spots(x: np.array, freq: int = 1) -> Dict[str, float]:
223225
"""Flat spots.
224226
@@ -240,8 +242,9 @@ def flat_spots(x: np.array, freq: int = 1) -> Dict[str, float]:
240242
return {"flat_spots": np.nan}
241243

242244
rlex = np.array([sum(1 for i in g) for k, g in groupby(cutx)]).max()
245+
return {"flat_spots": rlex}
243246

244-
# %% ../nbs/tsfeatures.ipynb 18
247+
# %% ../nbs/tsfeatures.ipynb 17
245248
def frequency(x: np.array, freq: int = 1) -> Dict[str, float]:
246249
"""Frequency.
247250
@@ -260,7 +263,7 @@ def frequency(x: np.array, freq: int = 1) -> Dict[str, float]:
260263

261264
return {"frequency": freq}
262265

263-
# %% ../nbs/tsfeatures.ipynb 19
266+
# %% ../nbs/tsfeatures.ipynb 18
264267
def guerrero(
265268
x: np.array, freq: int = 1, lower: int = -1, upper: int = 2
266269
) -> Dict[str, float]:
@@ -295,7 +298,7 @@ def guerrero(
295298

296299
return {"guerrero": min_}
297300

298-
# %% ../nbs/tsfeatures.ipynb 20
301+
# %% ../nbs/tsfeatures.ipynb 19
299302
def heterogeneity(x: np.array, freq: int = 1) -> Dict[str, float]:
300303
"""Heterogeneity.
301304
@@ -358,7 +361,7 @@ def heterogeneity(x: np.array, freq: int = 1) -> Dict[str, float]:
358361

359362
return output
360363

361-
# %% ../nbs/tsfeatures.ipynb 21
364+
# %% ../nbs/tsfeatures.ipynb 20
362365
def holt_parameters(x: np.array, freq: int = 1) -> Dict[str, float]:
363366
"""Fitted parameters of a Holt model.
364367
@@ -386,7 +389,7 @@ def holt_parameters(x: np.array, freq: int = 1) -> Dict[str, float]:
386389

387390
return params
388391

389-
# %% ../nbs/tsfeatures.ipynb 22
392+
# %% ../nbs/tsfeatures.ipynb 21
390393
def hurst(x: np.array, freq: int = 1) -> Dict[str, float]:
391394
"""Hurst index.
392395
@@ -409,7 +412,7 @@ def hurst(x: np.array, freq: int = 1) -> Dict[str, float]:
409412

410413
return {"hurst": hurst_index}
411414

412-
# %% ../nbs/tsfeatures.ipynb 23
415+
# %% ../nbs/tsfeatures.ipynb 22
413416
def hw_parameters(x: np.array, freq: int = 1) -> Dict[str, float]:
414417
"""Fitted parameters of a Holt-Winters model.
415418
@@ -441,7 +444,7 @@ def hw_parameters(x: np.array, freq: int = 1) -> Dict[str, float]:
441444

442445
return params
443446

444-
# %% ../nbs/tsfeatures.ipynb 24
447+
# %% ../nbs/tsfeatures.ipynb 23
445448
def intervals(x: np.array, freq: int = 1) -> Dict[str, float]:
446449
"""Intervals with demand.
447450
@@ -465,7 +468,7 @@ def intervals(x: np.array, freq: int = 1) -> Dict[str, float]:
465468

466469
return {"intervals_mean": np.mean(y), "intervals_sd": np.std(y, ddof=1)}
467470

468-
# %% ../nbs/tsfeatures.ipynb 25
471+
# %% ../nbs/tsfeatures.ipynb 24
469472
def lumpiness(x: np.array, freq: int = 1) -> Dict[str, float]:
470473
"""lumpiness.
471474
@@ -499,7 +502,7 @@ def lumpiness(x: np.array, freq: int = 1) -> Dict[str, float]:
499502

500503
return {"lumpiness": lumpiness}
501504

502-
# %% ../nbs/tsfeatures.ipynb 26
505+
# %% ../nbs/tsfeatures.ipynb 25
503506
def nonlinearity(x: np.array, freq: int = 1) -> Dict[str, float]:
504507
"""Nonlinearity.
505508
@@ -524,7 +527,7 @@ def nonlinearity(x: np.array, freq: int = 1) -> Dict[str, float]:
524527

525528
return {"nonlinearity": test}
526529

527-
# %% ../nbs/tsfeatures.ipynb 27
530+
# %% ../nbs/tsfeatures.ipynb 26
528531
def pacf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
529532
"""Calculates partial autocorrelation function features.
530533
@@ -595,7 +598,7 @@ def pacf_features(x: np.array, freq: int = 1) -> Dict[str, float]:
595598

596599
return output
597600

598-
# %% ../nbs/tsfeatures.ipynb 28
601+
# %% ../nbs/tsfeatures.ipynb 27
599602
def series_length(x: np.array, freq: int = 1) -> Dict[str, float]:
600603
"""Series length.
601604
@@ -614,7 +617,7 @@ def series_length(x: np.array, freq: int = 1) -> Dict[str, float]:
614617

615618
return {"series_length": len(x)}
616619

617-
# %% ../nbs/tsfeatures.ipynb 29
620+
# %% ../nbs/tsfeatures.ipynb 28
618621
def sparsity(x: np.array, freq: int = 1) -> Dict[str, float]:
619622
"""Sparsity.
620623
@@ -633,7 +636,7 @@ def sparsity(x: np.array, freq: int = 1) -> Dict[str, float]:
633636

634637
return {"sparsity": np.mean(x == 0)}
635638

636-
# %% ../nbs/tsfeatures.ipynb 30
639+
# %% ../nbs/tsfeatures.ipynb 29
637640
def stability(x: np.array, freq: int = 1) -> Dict[str, float]:
638641
"""Stability.
639642
@@ -667,7 +670,7 @@ def stability(x: np.array, freq: int = 1) -> Dict[str, float]:
667670

668671
return {"stability": stability}
669672

670-
# %% ../nbs/tsfeatures.ipynb 31
673+
# %% ../nbs/tsfeatures.ipynb 30
671674
def stl_features(x: np.array, freq: int = 1) -> Dict[str, float]:
672675
"""Calculates seasonal trend using loess decomposition.
673676
@@ -785,8 +788,14 @@ def stl_features(x: np.array, freq: int = 1) -> Dict[str, float]:
785788
time_x = add_constant(poly_m)
786789
coefs = OLS(trend0, time_x).fit().params
787790

788-
linearity = coefs[1]
789-
curvature = -coefs[2]
791+
try:
792+
linearity = coefs[1]
793+
except:
794+
linearity = np.nan
795+
try:
796+
curvature = -coefs[2]
797+
except:
798+
curvature = np.nan
790799
# ACF features
791800
acfremainder = acf_features(remainder, m)
792801
# Assemble features
@@ -808,7 +817,7 @@ def stl_features(x: np.array, freq: int = 1) -> Dict[str, float]:
808817

809818
return output
810819

811-
# %% ../nbs/tsfeatures.ipynb 32
820+
# %% ../nbs/tsfeatures.ipynb 31
812821
def unitroot_kpss(x: np.array, freq: int = 1) -> Dict[str, float]:
813822
"""Unit root kpss.
814823
@@ -834,7 +843,7 @@ def unitroot_kpss(x: np.array, freq: int = 1) -> Dict[str, float]:
834843

835844
return {"unitroot_kpss": test_kpss}
836845

837-
# %% ../nbs/tsfeatures.ipynb 33
846+
# %% ../nbs/tsfeatures.ipynb 32
838847
def unitroot_pp(x: np.array, freq: int = 1) -> Dict[str, float]:
839848
"""Unit root pp.
840849
@@ -884,7 +893,6 @@ def _get_feats(
884893
],
885894
dict_freqs=FREQS,
886895
):
887-
print("dict_freq")
888896
if freq is None:
889897
inf_freq = pd.infer_freq(ts["ds"])
890898
if inf_freq is None:

0 commit comments

Comments
 (0)