-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from IBM/get_dataset
Get dataset
- Loading branch information
Showing
5 changed files
with
350 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# %% | ||
import pandas as pd | ||
|
||
from tsfm_public.toolkit.time_series_preprocessor import TimeSeriesPreprocessor | ||
|
||
|
||
split_config = {"train": [0, 8640], "valid": [8640, 11520], "test": [11520, 14400]} | ||
|
||
|
||
dataset_path = ( | ||
"https://raw.githubusercontent.com/zhouhaoyi/ETDataset/main/ETT-small/ETTh1.csv" | ||
) | ||
|
||
timestamp_column = "date" | ||
|
||
df = pd.read_csv( | ||
dataset_path, | ||
parse_dates=[timestamp_column], | ||
) | ||
|
||
tsp = TimeSeriesPreprocessor( | ||
id_columns=[], | ||
timestamp_column=timestamp_column, | ||
target_columns=["HUFL", "HULL", "MUFL", "MULL", "LUFL", "LULL", "OT"], | ||
observable_columns=[], | ||
control_columns=[], | ||
conditional_columns=[], | ||
static_categorical_columns=[], | ||
scaling=True, | ||
scaler_type="standard", | ||
encode_categorical=False, | ||
prediction_length=10, | ||
context_length=96, | ||
) | ||
|
||
train, valid, test = tsp.get_datasets(df, split_config) | ||
|
||
# %% | ||
split_config = {"train": [0, 0.7], "valid": [0.7, 0.9], "test": [0.9, 1]} | ||
|
||
train, valid, test = tsp.get_datasets(df, split_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Tests for util functions""" | ||
|
||
import pytest | ||
|
||
from tsfm_public.toolkit.util import get_split_params | ||
|
||
|
||
split_cases = [ | ||
(0, 1, "select_by_index"), | ||
(0, 0.1, "select_by_relative_fraction"), | ||
(0.0, 0.1, "select_by_relative_fraction"), | ||
(0.0, 200.0, "select_by_index"), | ||
(0.0, 200, "select_by_index"), | ||
(0.5, 1, "select_by_relative_fraction"), | ||
(0.5, 1.0, "select_by_relative_fraction"), | ||
(10, 100.0, "select_by_index"), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize("left_arg,right_arg,expected", split_cases) | ||
def test_get_split_params(left_arg, right_arg, expected): | ||
"""Test that get_split_params gives the right split function""" | ||
|
||
split_config, split_function = get_split_params({"train": [left_arg, right_arg], "valid": [0, 1], "test": [0, 1]}) | ||
|
||
assert split_function["train"].__name__ == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.