Skip to content

Commit

Permalink
Updated requirements
Browse files Browse the repository at this point in the history
Signed-off-by: Stefano Savare <[email protected]>
  • Loading branch information
deatinor committed Jul 21, 2020
1 parent 901736c commit 9c84a8f
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
61 changes: 61 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pandas as pd
from sklearn.linear_model import LinearRegression

from gtime.feature_extraction import Shift
from gtime.time_series_models.base import TimeSeriesForecastingModel


class TimeSeries(pd.DataFrame):
def plot(self):
pass


time_series = TimeSeries()

# You can plot
time_series.plot()

# Decomposition
## Un peu bizarre le plot_stl() et deux fois stl_decomposition
time_series = time_series.stl_decomposition()
time_series.plot_stl()
time_series = time_series.recompose() # Choose a good name

# Box-Cox
time_series = time_series.box_cox(lambda_=0.3)

# Feature forecasting
features = [("shift", Shift(1), "time_series")]
automatic_features = get_features() # Similar to fast.ai get_transforms()
gar_forecaster = LinearRegression()
# This object TimeSeriesForecastingModel keeps into account all the intermediate steps.
# You don't need to manually deal with train/test split, etc..
forecasting_model = TimeSeriesForecastingModel(
features=features, horizon=3, model=gar_forecaster
)
forecasting_model = forecasting_model.fit(time_series)
forecasting_model.predict()
forecasting_model.cross_validate() # Is cross validation also on multiple time series?

# Residuals analysis
forecasting_model.residuals_.acf()

# Questions
"""
How to implement ARIMA? I think that a GAR forecaster with MA should work, but we should check.
It helps that the user can't customize the feature matrix.
Exponential Smoothing? Maybe it could work also? Not clear if it is possible with additional
features
Add a learner object?
"""

time_series = TimeSeries(pandas_dataframe)

arima = ARIMA(time_series)
arima.fit(time_series,,
preds = arima.predict(time_series)


time_series.to_pandas()
5 changes: 4 additions & 1 deletion gtime/explainability/tests/test_explainer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import hypothesis.strategies as st
import numpy as np
import pandas as pd
import pytest
from hypothesis import given
from hypothesis import given, settings
from hypothesis.strategies import floats, sampled_from, data, lists, text
from lime.explanation import Explanation
from shap.explainers.explainer import Explainer
Expand Down Expand Up @@ -130,6 +131,7 @@ def _check_predict_output(
]
)

@settings(deadline=pd.Timedelta(milliseconds=5000), max_examples=7)
@pytest.mark.parametrize(
"explainer", lazy_fixtures([lime_explainer, shap_explainer])
)
Expand All @@ -153,6 +155,7 @@ def test_error_predict_not_fit(self, explainer, X):


class TestLime:
@settings(deadline=pd.Timedelta(milliseconds=10000), max_examples=7)
@given(regressor=models(), X_y=numpy_X_y_matrices(min_value=-100, max_value=100))
def test_predict(self, lime_explainer, regressor, X_y):
X, y = X_y
Expand Down
2 changes: 1 addition & 1 deletion gtime/feature_extraction/tests/test_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_polynomial_detrend():
columns=[f"0__{feature_name}"],
index=time_index,
)
pd.testing.assert_frame_equal(ts_t, expected_ts)
pd.testing.assert_frame_equal(ts_t, expected_ts, check_less_precise=3)


def test_exponential_detrend():
Expand Down
2 changes: 1 addition & 1 deletion gtime/hierarchical/tests/test_top_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_error_predict_not_fitted(self, hierarchical_basic_top_down_model):
with pytest.raises(sklearn.exceptions.NotFittedError):
hierarchical_basic_top_down_model.predict()

@given(dataframes=n_time_series_with_same_index())
@given(dataframes=n_time_series_with_same_index(min_n=5))
def test_error_with_bad_predict_key(
self, dataframes, hierarchical_basic_top_down_model
):
Expand Down
3 changes: 2 additions & 1 deletion gtime/regressors/tests/test_explainable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

import pytest
from hypothesis import given
from hypothesis import given, settings
from sklearn import clone
from sklearn.base import BaseEstimator
from sklearn.cluster import DBSCAN, KMeans, SpectralClustering
Expand Down Expand Up @@ -85,6 +85,7 @@ def test_fit_values(self, estimator, explainer_type, X_y):
estimator_fit_attributes, cloned_estimator_fit_attributes
)

@settings(deadline=pd.Timedelta(milliseconds=5000), max_examples=7)
@pytest.mark.parametrize("explainer_type", ["lime", "shap"])
@given(
estimator=regressors(), X_y=numpy_X_y_matrices(min_value=-100, max_value=100)
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ scikit-learn>=0.22.0
matplotlib>=3.1.0
lime>=0.2.0.0
shap>=0.35
holidays>=0.10.2
lunarcalendar>=0.0.9

0 comments on commit 9c84a8f

Please sign in to comment.