Skip to content

Commit

Permalink
Merge branch 'main' into neuralforcast
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavvp16 committed Apr 8, 2024
2 parents fe8147d + 0026957 commit da47457
Show file tree
Hide file tree
Showing 24 changed files with 806 additions and 108 deletions.
18 changes: 18 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,15 @@
"doc"
]
},
{
"login": "MMTrooper",
"name": "Michael Mwimali",
"avatar_url": "https://avatars.githubusercontent.com/u/89777534?v=4",
"profile": "https://github.com/MMTrooper",
"contributions": [
"code"
]
},
{
"login": "manuel-munoz-aguirre",
"name": "Manuel Muñoz Aguirre",
Expand All @@ -2725,6 +2734,15 @@
"contributions": [
"doc"
]
},
{
"login": "anteemony",
"name": "Anthony Okonneh",
"avatar_url": "https://avatars.githubusercontent.com/u/90141191?v=4",
"profile": "https://github.com/Anteemony",
"contributions": [
"doc"
]
}
]
}
64 changes: 33 additions & 31 deletions CONTRIBUTORS.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions docs/source/api_reference/split.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Time index splitters

Time index splitters split one or multiple time series by temporal order.
They are typically used in both evaluation and tuning of forecasters.
They have tag ``"split_type"="temporal"``.

.. currentmodule:: sktime.split

Expand Down Expand Up @@ -72,3 +73,20 @@ more complex time index based splitting strategies.

SameLocSplitter
TestPlusTrainSplitter


Instance splitters
------------------

Instance splitters split panels or hierarchical time series by
the instance index, i.e., identifiers for entire series.
Train and test sets contain entire series from the original panel.
Instance splitters have tag ``"split_type"="instance"``.

.. currentmodule:: sktime.split

.. autosummary::
:toctree: auto_generated/
:template: class.rst

InstanceSplitter
2 changes: 1 addition & 1 deletion examples/02_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@
"X_test, y_test = load_italy_power_demand(split=\"test\", return_type=\"numpy3D\")\n",
"\n",
"# step 3-5 are the same\n",
"from sktime.classification.distance_based import KNeighborsTimeSeriesClassifier\n",
"\n",
"from sktime.dists_kernels import FlatDist, ScipyDist\n",
"\n",
"eucl_dist = FlatDist(ScipyDist())\n",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ regression = [
transformations = [
'esig<0.10,>=0.9.7; python_version < "3.11"',
"filterpy<1.5,>=1.4.5",
"holidays>=0.29,<0.46",
"holidays>=0.29,<0.47",
"mne>=1.5,<1.7",
'numba<0.60,>=0.53',
"pycatch22>=0.4,<0.4.4",
Expand Down
10 changes: 10 additions & 0 deletions sktime/classification/deep_learning/inceptiontime.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class InceptionTimeClassifier(BaseDeepClassifier):
Adapted from the implementation from Fawaz et. al
https://github.com/hfawaz/InceptionTime/blob/master/classifiers/inception.py
Examples
--------
>>> from sktime.classification.deep_learning import InceptionTimeClassifier
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test(split="train")
>>> X_test, y_test = load_unit_test(split="test")
>>> clf = InceptionTimeClassifier() # doctest: +SKIP
>>> clf.fit(X_train, y_train) # doctest: +SKIP
InceptionTimeClassifier(...)
"""

_tags = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,7 @@ def get_test_params(cls, parameter_set="default"):
instance.
``create_test_instance`` uses the first (or only) dictionary in ``params``.
"""
return {"subsequence_length": 4}
return [
{"subsequence_length": 4},
{"subsequence_length": 6, "estimator": KNeighborsClassifier(n_neighbors=3)},
]
87 changes: 68 additions & 19 deletions sktime/forecasting/base/adapters/_neuralforecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@
"""Implements adapter for NeuralForecast models."""
import abc
import functools
import typing

from inspect import signature
from typing import List, Literal, Optional, Union

import numpy as np
import pandas

from sktime.forecasting.base import BaseForecaster, ForecastingHorizon
from sktime.utils.warnings import warn

__all__ = ["_NeuralForecastAdapter"]
__author__ = ["yarnabrina", "pranavvp16"]
__author__ = ["yarnabrina", "geetu040", "pranavvp16"]



class _NeuralForecastAdapter(BaseForecaster):
"""Base adapter class for NeuralForecast models.
Parameters
----------
freq : str (default="auto")
freq : Union[str, int] (default="auto")
frequency of the data, see available frequencies [1]_ from ``pandas``
use int freq when using RangeIndex in ``y``
default ("auto") interprets freq from ForecastingHorizon in ``fit``
local_scaler_type : str (default=None)
Expand Down Expand Up @@ -70,11 +74,11 @@ class _NeuralForecastAdapter(BaseForecaster):

def __init__(
self: "_NeuralForecastAdapter",
freq: str = "auto",
local_scaler_type: typing.Optional[
typing.Literal["standard", "robust", "robust-iqr", "minmax", "boxcox"]
freq: Union[str, int] = "auto",
local_scaler_type: Optional[
Literal["standard", "robust", "robust-iqr", "minmax", "boxcox"]
] = None,
futr_exog_list: typing.Optional[typing.List[str]] = None,
futr_exog_list: Optional[List[str]] = None,
verbose_fit: bool = False,
verbose_predict: bool = False,
) -> None:
Expand Down Expand Up @@ -191,7 +195,7 @@ def _instantiate_model(self: "_NeuralForecastAdapter", fh: ForecastingHorizon):
def _fit(
self: "_NeuralForecastAdapter",
y: pandas.Series,
X: typing.Optional[pandas.DataFrame],
X: Optional[pandas.DataFrame],
fh: ForecastingHorizon,
) -> "_NeuralForecastAdapter":
"""Fit forecaster to training data.
Expand Down Expand Up @@ -224,15 +228,60 @@ def _fit(
if not fh.is_all_out_of_sample(cutoff=self.cutoff):
raise NotImplementedError("in-sample prediction is currently not supported")

if self.freq == "auto" and fh.freq is None:
# when freq cannot be interpreted from ForecastingHorizon
raise ValueError(
f"Error in {self.__class__.__name__}, "
f"could not interpret freq, "
f"try passing freq in model initialization"
)

self._freq = fh.freq if self.freq == "auto" else self.freq
# A. freq is given {use this}
# B. freq is auto
# B1. freq is infered from fh {use this}
# B2. freq is not infered from fh
# B2.1. y is date-like {raise exception}
# B2.2. y is not date-like
# B2.2.1 equispaced integers {use diff in time}
# B2.2.2 non-equispaced integers {raise exception}

# behavior of different indexes when freq="auto"
# | Indexes | behavior |
# | ----------------------- | --------- |
# | PeriodIndex | B1 |
# | PeriodIndex (Missing) | B1 |
# | DatetimeIndex | B1 |
# | DatetimeIndex (Missing) | B2.1 |
# | RangeIndex | B2.2.1 |
# | RangeIndex (Missing) | B2.2.2 |
# | Index | B2.2.1 |
# | Index (Missing) | B2.2.2 |
# | Other | unreached |

if self.freq != "auto":
# A
self._freq = self.freq
else:
# B
if fh.freq:
# B1
self._freq = fh.freq
else:
# B2
if isinstance(y.index, pandas.DatetimeIndex):
# B2.1
raise ValueError(
f"Error in {self.__class__.__name__}, "
"could not interpret freq, "
"try passing freq in model initialization "
"or use a valid offset in index"
)
else:
# B2.2
diffs = np.unique(np.diff(y.index))
if diffs.shape[0] > 1:
# B2.2.1
raise ValueError(
f"Error in {self.__class__.__name__}, "
"could not interpret freq, "
"try passing integer freq in model initialization "
"or use a valid integer offset in index"
)
else:
# B2.2.2
self._freq = int(diffs[-1]) # converts numpy.int64 to int

train_indices = y.index
if isinstance(train_indices, pandas.PeriodIndex):
Expand Down Expand Up @@ -262,8 +311,8 @@ def _fit(

def _predict(
self: "_NeuralForecastAdapter",
fh: typing.Optional[ForecastingHorizon],
X: typing.Optional[pandas.DataFrame],
fh: Optional[ForecastingHorizon],
X: Optional[pandas.DataFrame],
) -> pandas.Series:
"""Forecast time series at future horizon.
Expand Down

0 comments on commit da47457

Please sign in to comment.