-
Notifications
You must be signed in to change notification settings - Fork 45
convert tsfeatures lib to nbdev framework #39
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
base: main
Are you sure you want to change the base?
Changes from 13 commits
8f0c1cc
61112fc
a8d3b1e
527f3d9
3dd8d5f
5e03313
2101882
528b541
846508e
bf80383
ed0266f
ddabac9
5d420e0
5fe9589
cb60c1b
c0eb867
0135e1b
2dd6a65
e9c1b94
29c2a98
022858c
be7efc9
74bf82f
b7b671f
424331c
cbdb352
3a57f9c
2968544
5245275
00de734
28f400d
4cd2e2c
cf77218
824d7ce
88ae6b7
8704297
22a1767
02f1a6b
936f0ec
d679122
80f5d96
bff351c
8b9a01f
9409776
7e92696
00a9b9d
b437028
903876d
523ccf5
d3c4324
233ea75
180136a
dbd5047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| *.ipynb merge=nbdev-merge |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Generated by nbdev_install_hooks | ||
| # | ||
| # If you need to disable this instrumentation do: | ||
| # git config --local --unset include.path | ||
| # | ||
| # To restore: | ||
| # git config --local include.path ../.gitconfig | ||
| # | ||
| [merge "nbdev-merge"] | ||
| name = resolve conflicts with nbdev_fix | ||
| driver = nbdev_merge %O %A %B %P |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,4 +134,6 @@ Untitle*.ipynb | |
|
|
||
| #files | ||
| *.csv | ||
| *.ipynb | ||
|
|
||
|
|
||
| _proc | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| include settings.ini | ||
| include LICENSE | ||
| include CONTRIBUTING.md | ||
| include README.md | ||
| recursive-exclude * __pycache__ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,75 +1,86 @@ | ||
| [](https://github.com/FedericoGarza/tsfeatures/tree/master) | ||
| [](https://pypi.python.org/pypi/tsfeatures/) | ||
| [](https://pepy.tech/project/tsfeatures) | ||
| [](https://www.python.org/downloads/release/python-370+/) | ||
| [](https://github.com/FedericoGarza/tsfeatures/blob/master/LICENSE) | ||
| # tsfeatures | ||
|
|
||
|
|
||
| <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! --> | ||
|
|
||
| # tsfeatures | ||
|
|
||
| Calculates various features from time series data. Python implementation of the R package _[tsfeatures](https://github.com/robjhyndman/tsfeatures)_. | ||
| Calculates various features from time series data. Python implementation | ||
| of the R package | ||
| *[tsfeatures](https://github.com/robjhyndman/tsfeatures)*. | ||
|
|
||
| # Installation | ||
|
|
||
| You can install the *released* version of `tsfeatures` from the [Python package index](pypi.org) with: | ||
| You can install the *released* version of `tsfeatures` from the [Python | ||
| package index](pypi.org) with: | ||
|
|
||
| ``` python | ||
| pip install tsfeatures | ||
| ``` | ||
|
|
||
| # Usage | ||
|
|
||
| The `tsfeatures` main function calculates by default the features used by Montero-Manso, Talagala, Hyndman and Athanasopoulos in [their implementation of the FFORMA model](https://htmlpreview.github.io/?https://github.com/robjhyndman/M4metalearning/blob/master/docs/M4_methodology.html#features). | ||
| The `tsfeatures` main function calculates by default the features used | ||
| by Montero-Manso, Talagala, Hyndman and Athanasopoulos in [their | ||
| implementation of the FFORMA | ||
| model](https://htmlpreview.github.io/?https://github.com/robjhyndman/M4metalearning/blob/master/docs/M4_methodology.html#features). | ||
|
|
||
| ```python | ||
| ``` python | ||
| from tsfeatures import tsfeatures | ||
| ``` | ||
|
|
||
| This function receives a panel pandas df with columns `unique_id`, `ds`, `y` and optionally the frequency of the data. | ||
| This function receives a panel pandas df with columns `unique_id`, `ds`, | ||
| `y` and optionally the frequency of the data. | ||
|
|
||
| <img src=https://raw.githubusercontent.com/FedericoGarza/tsfeatures/master/.github/images/y_train.png width="152"> | ||
|
|
||
| ```python | ||
| ``` python | ||
| tsfeatures(panel, freq=7) | ||
| ``` | ||
|
|
||
| By default (`freq=None`) the function will try to infer the frequency of each time series (using `infer_freq` from `pandas` on the `ds` column) and assign a seasonal period according to the built-in dictionary `FREQS`: | ||
| By default (`freq=None`) the function will try to infer the frequency of | ||
| each time series (using `infer_freq` from `pandas` on the `ds` column) | ||
| and assign a seasonal period according to the built-in dictionary | ||
| `FREQS`: | ||
|
|
||
| ```python | ||
| ``` python | ||
| FREQS = {'H': 24, 'D': 1, | ||
| 'M': 12, 'Q': 4, | ||
| 'W':1, 'Y': 1} | ||
| ``` | ||
|
|
||
| You can use your own dictionary using the `dict_freqs` argument: | ||
|
|
||
| ```python | ||
| ``` python | ||
| tsfeatures(panel, dict_freqs={'D': 7, 'W': 52}) | ||
| ``` | ||
|
|
||
| ## List of available features | ||
|
|
||
| | Features ||| | ||
| |:--------|:------|:-------------| | ||
| |acf_features|heterogeneity|series_length| | ||
| |arch_stat|holt_parameters|sparsity| | ||
| |count_entropy|hurst|stability| | ||
| |crossing_points|hw_parameters|stl_features| | ||
| |entropy|intervals|unitroot_kpss| | ||
| |flat_spots|lumpiness|unitroot_pp| | ||
| |frequency|nonlinearity|| | ||
| |guerrero|pacf_features|| | ||
| | Features | | | | ||
| |:----------------|:----------------|:--------------| | ||
| | acf_features | heterogeneity | series_length | | ||
| | arch_stat | holt_parameters | sparsity | | ||
| | count_entropy | hurst | stability | | ||
| | crossing_points | hw_parameters | stl_features | | ||
| | entropy | intervals | unitroot_kpss | | ||
| | flat_spots | lumpiness | unitroot_pp | | ||
| | frequency | nonlinearity | | | ||
| | guerrero | pacf_features | | | ||
|
|
||
| See the docs for a description of the features. To use a particular feature included in the package you need to import it: | ||
| See the docs for a description of the features. To use a particular | ||
| feature included in the package you need to import it: | ||
|
|
||
| ```python | ||
| ``` python | ||
| from tsfeatures import acf_features | ||
|
|
||
| tsfeatures(panel, freq=7, features=[acf_features]) | ||
| ``` | ||
|
|
||
| You can also define your own function and use it together with the included features: | ||
| You can also define your own function and use it together with the | ||
| included features: | ||
|
|
||
| ```python | ||
| ``` python | ||
| def number_zeros(x, freq): | ||
|
|
||
| number = (x == 0).sum() | ||
|
|
@@ -78,36 +89,41 @@ def number_zeros(x, freq): | |
| tsfeatures(panel, freq=7, features=[acf_features, number_zeros]) | ||
| ``` | ||
|
|
||
| `tsfeatures` can handle functions that receives a numpy array `x` and a frequency `freq` (this parameter is needed even if you don't use it) and returns a dictionary with the feature name as a key and its value. | ||
| `tsfeatures` can handle functions that receives a numpy array `x` and a | ||
| frequency `freq` (this parameter is needed even if you don’t use it) and | ||
| returns a dictionary with the feature name as a key and its value. | ||
|
|
||
| ## R implementation | ||
|
|
||
| You can use this package to call `tsfeatures` from R inside python (you need to have installed R, the packages `forecast` and `tsfeatures`; also the python package `rpy2`): | ||
| You can use this package to call `tsfeatures` from R inside python (you | ||
| need to have installed R, the packages `forecast` and `tsfeatures`; also | ||
| the python package `rpy2`): | ||
|
|
||
| ```python | ||
| ``` python | ||
| from tsfeatures.tsfeatures_r import tsfeatures_r | ||
|
|
||
| tsfeatures_r(panel, freq=7, features=["acf_features"]) | ||
| ``` | ||
|
|
||
| Observe that this function receives a list of strings instead of a list of functions. | ||
| Observe that this function receives a list of strings instead of a list | ||
| of functions. | ||
|
|
||
| ## Comparison with the R implementation (sum of absolute differences) | ||
|
|
||
| ### Non-seasonal data (100 Daily M4 time series) | ||
|
|
||
| | feature | diff | feature | diff | feature | diff | feature | diff | | ||
| |:----------------|-------:|:----------------|-------:|:----------------|-------:|:----------------|-------:| | ||
| | e_acf10 | 0 | e_acf1 | 0 | diff2_acf1 | 0 | alpha | 3.2 | | ||
| | seasonal_period | 0 | spike | 0 | diff1_acf10 | 0 | arch_acf | 3.3 | | ||
| | nperiods | 0 | curvature | 0 | x_acf1 | 0 | beta | 4.04 | | ||
| | linearity | 0 | crossing_points | 0 | nonlinearity | 0 | garch_r2 | 4.74 | | ||
| | hw_gamma | 0 | lumpiness | 0 | diff2x_pacf5 | 0 | hurst | 5.45 | | ||
| | hw_beta | 0 | diff1x_pacf5 | 0 | unitroot_kpss | 0 | garch_acf | 5.53 | | ||
| | hw_alpha | 0 | diff1_acf10 | 0 | x_pacf5 | 0 | entropy | 11.65 | | ||
| | trend | 0 | arch_lm | 0 | x_acf10 | 0 | | ||
| | flat_spots | 0 | diff1_acf1 | 0 | unitroot_pp | 0 | | ||
| | series_length | 0 | stability | 0 | arch_r2 | 1.37 | | ||
| | feature | diff | feature | diff | feature | diff | feature | diff | | ||
| |:----------------|-----:|:----------------|-----:|:--------------|-----:|:----------|------:| | ||
| | e_acf10 | 0 | e_acf1 | 0 | diff2_acf1 | 0 | alpha | 3.2 | | ||
| | seasonal_period | 0 | spike | 0 | diff1_acf10 | 0 | arch_acf | 3.3 | | ||
| | nperiods | 0 | curvature | 0 | x_acf1 | 0 | beta | 4.04 | | ||
| | linearity | 0 | crossing_points | 0 | nonlinearity | 0 | garch_r2 | 4.74 | | ||
| | hw_gamma | 0 | lumpiness | 0 | diff2x_pacf5 | 0 | hurst | 5.45 | | ||
| | hw_beta | 0 | diff1x_pacf5 | 0 | unitroot_kpss | 0 | garch_acf | 5.53 | | ||
| | hw_alpha | 0 | diff1_acf10 | 0 | x_pacf5 | 0 | entropy | 11.65 | | ||
| | trend | 0 | arch_lm | 0 | x_acf10 | 0 | | | | ||
| | flat_spots | 0 | diff1_acf1 | 0 | unitroot_pp | 0 | | | | ||
| | series_length | 0 | stability | 0 | arch_r2 | 1.37 | | | | ||
|
|
||
| To replicate this results use: | ||
|
|
||
|
|
@@ -118,33 +134,126 @@ python -m tsfeatures.compare_with_r --results_directory /some/path | |
|
|
||
| ### Sesonal data (100 Hourly M4 time series) | ||
|
|
||
| | feature | diff | feature | diff | feature | diff | feature | diff | | ||
| |:------------------|-------:|:-------------|-----:|:----------|--------:|:-----------|--------:| | ||
| | series_length | 0 |seas_acf1 | 0 | trend | 2.28 | hurst | 26.02 | | ||
| | flat_spots | 0 |x_acf1|0| arch_r2 | 2.29 | hw_beta | 32.39 | | ||
| | nperiods | 0 |unitroot_kpss|0| alpha | 2.52 | trough | 35 | | ||
| | crossing_points | 0 |nonlinearity|0| beta | 3.67 | peak | 69 | | ||
| | seasonal_period | 0 |diff1_acf10|0| linearity | 3.97 | | ||
| | lumpiness | 0 |x_acf10|0| curvature | 4.8 | | ||
| | stability | 0 |seas_pacf|0| e_acf10 | 7.05 | | ||
| | arch_lm | 0 |unitroot_pp|0| garch_r2 | 7.32 | | ||
| | diff2_acf1 | 0 |spike|0| hw_gamma | 7.32 | | ||
| | diff2_acf10 | 0 |seasonal_strength|0.79| hw_alpha | 7.47 | | ||
| | diff1_acf1 | 0 |e_acf1|1.67| garch_acf | 7.53 | | ||
| | diff2x_pacf5 | 0 |arch_acf|2.18| entropy | 9.45 | | ||
| | feature | diff | feature | diff | feature | diff | feature | diff | | ||
| |:----------------|-----:|:------------------|-----:|:----------|-----:|:--------|------:| | ||
| | series_length | 0 | seas_acf1 | 0 | trend | 2.28 | hurst | 26.02 | | ||
| | flat_spots | 0 | x_acf1 | 0 | arch_r2 | 2.29 | hw_beta | 32.39 | | ||
| | nperiods | 0 | unitroot_kpss | 0 | alpha | 2.52 | trough | 35 | | ||
| | crossing_points | 0 | nonlinearity | 0 | beta | 3.67 | peak | 69 | | ||
| | seasonal_period | 0 | diff1_acf10 | 0 | linearity | 3.97 | | | | ||
| | lumpiness | 0 | x_acf10 | 0 | curvature | 4.8 | | | | ||
| | stability | 0 | seas_pacf | 0 | e_acf10 | 7.05 | | | | ||
| | arch_lm | 0 | unitroot_pp | 0 | garch_r2 | 7.32 | | | | ||
| | diff2_acf1 | 0 | spike | 0 | hw_gamma | 7.32 | | | | ||
| | diff2_acf10 | 0 | seasonal_strength | 0.79 | hw_alpha | 7.47 | | | | ||
| | diff1_acf1 | 0 | e_acf1 | 1.67 | garch_acf | 7.53 | | | | ||
| | diff2x_pacf5 | 0 | arch_acf | 2.18 | entropy | 9.45 | | | | ||
|
|
||
| To replicate this results use: | ||
| [](https://github.com/FedericoGarza/tsfeatures/tree/master) | ||
|
||
| [](https://pypi.python.org/pypi/tsfeatures/) | ||
| [](https://pepy.tech/project/tsfeatures) | ||
| [](https://www.python.org/downloads/release/python-370+/) | ||
| [](https://github.com/FedericoGarza/tsfeatures/blob/master/LICENSE) | ||
|
|
||
| ``` console | ||
| python -m tsfeatures.compare_with_r --results_directory /some/path \ | ||
| --dataset_name Hourly --num_obs 100 | ||
| # tsfeatures | ||
|
|
||
| Calculates various features from time series data. Python implementation | ||
| of the R package | ||
| *[tsfeatures](https://github.com/robjhyndman/tsfeatures)*. | ||
|
|
||
| # Installation | ||
|
|
||
| You can install the *released* version of `tsfeatures` from the [Python | ||
| package index](pypi.org) with: | ||
|
|
||
| ``` python | ||
| pip install tsfeatures | ||
| ``` | ||
|
|
||
| # Usage | ||
|
|
||
| The `tsfeatures` main function calculates by default the features used | ||
| by Montero-Manso, Talagala, Hyndman and Athanasopoulos in [their | ||
| implementation of the FFORMA | ||
| model](https://htmlpreview.github.io/?https://github.com/robjhyndman/M4metalearning/blob/master/docs/M4_methodology.html#features). | ||
|
|
||
| ``` python | ||
| from tsfeatures import tsfeatures | ||
| ``` | ||
|
|
||
| This function receives a panel pandas df with columns `unique_id`, `ds`, | ||
| `y` and optionally the frequency of the data. | ||
|
|
||
| <img src=https://raw.githubusercontent.com/FedericoGarza/tsfeatures/master/.github/images/y_train.png width="152"> | ||
|
|
||
| ``` python | ||
| tsfeatures(panel, freq=7) | ||
| ``` | ||
|
|
||
| By default (`freq=None`) the function will try to infer the frequency of | ||
| each time series (using `infer_freq` from `pandas` on the `ds` column) | ||
| and assign a seasonal period according to the built-in dictionary | ||
| `FREQS`: | ||
|
|
||
| ``` python | ||
| FREQS = {'H': 24, 'D': 1, | ||
| 'M': 12, 'Q': 4, | ||
| 'W':1, 'Y': 1} | ||
| ``` | ||
|
|
||
| You can use your own dictionary using the `dict_freqs` argument: | ||
|
|
||
| ``` python | ||
| tsfeatures(panel, dict_freqs={'D': 7, 'W': 52}) | ||
| ``` | ||
|
|
||
| ## List of available features | ||
|
|
||
| | Features | | | | ||
| |:----------------|:----------------|:--------------| | ||
| | acf_features | heterogeneity | series_length | | ||
| | arch_stat | holt_parameters | sparsity | | ||
| | count_entropy | hurst | stability | | ||
| | crossing_points | hw_parameters | stl_features | | ||
| | entropy | intervals | unitroot_kpss | | ||
| | flat_spots | lumpiness | unitroot_pp | | ||
| | frequency | nonlinearity | | | ||
| | guerrero | pacf_features | | | ||
|
|
||
| See the docs for a description of the features. To use a particular | ||
| feature included in the package you need to import it: | ||
|
|
||
| ``` python | ||
| from tsfeatures import acf_features | ||
|
|
||
| tsfeatures(panel, freq=7, features=[acf_features]) | ||
| ``` | ||
|
|
||
| You can also define your own function and use it together with the | ||
| included features: | ||
|
|
||
| ``` python | ||
| def number_zeros(x, freq): | ||
|
|
||
| number = (x == 0).sum() | ||
| return {'number_zeros': number} | ||
|
|
||
| tsfeatures(panel, freq=7, features=[acf_features, number_zeros]) | ||
| ``` | ||
|
|
||
| `tsfeatures` can handle functions that receives a numpy array `x` and a | ||
| frequency `freq` (this parameter is needed even if you don’t use it) and | ||
| returns a dictionary with the feature name as a key and its value. | ||
|
|
||
| # Authors | ||
|
|
||
| * **Federico Garza** - [FedericoGarza](https://github.com/FedericoGarza) | ||
| * **Kin Gutierrez** - [kdgutier](https://github.com/kdgutier) | ||
| * **Cristian Challu** - [cristianchallu](https://github.com/cristianchallu) | ||
| * **Jose Moralez** - [jose-moralez](https://github.com/jose-moralez) | ||
| * **Ricardo Olivares** - [rolivaresar](https://github.com/rolivaresar) | ||
| * **Max Mergenthaler** - [mergenthaler](https://github.com/mergenthaler) | ||
| - **Federico Garza** - [FedericoGarza](https://github.com/FedericoGarza) | ||
| - **Kin Gutierrez** - [kdgutier](https://github.com/kdgutier) | ||
| - **Cristian Challu** - | ||
| [cristianchallu](https://github.com/cristianchallu) | ||
| - **Jose Moralez** - [jose-moralez](https://github.com/jose-moralez) | ||
| - **Ricardo Olivares** - [rolivaresar](https://github.com/rolivaresar) | ||
| - **Max Mergenthaler** - [mergenthaler](https://github.com/mergenthaler) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /.quarto/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| project: | ||
| type: website | ||
|
|
||
| format: | ||
| html: | ||
| theme: cosmo | ||
| css: styles.css | ||
| toc: true | ||
|
|
||
| website: | ||
| twitter-card: true | ||
| open-graph: true | ||
| repo-actions: [issue] | ||
| navbar: | ||
| background: primary | ||
| search: true | ||
| sidebar: | ||
| style: floating | ||
|
|
||
| metadata-files: [nbdev.yml, sidebar.yml] |
Uh oh!
There was an error while loading. Please reload this page.