-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
*Description of changes:* Add electricity transformer datasets from https://github.com/zhouhaoyi/ETDataset By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. **Please tag this pr with at least one of these labels to make our release process faster:** BREAKING, new feature, bug fix, other change, dev setup
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 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,69 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
|
||
from pathlib import Path | ||
|
||
import pandas as pd | ||
from gluonts.dataset import DatasetWriter | ||
from gluonts.dataset.common import MetaData, TrainDatasets | ||
|
||
|
||
# Currently data from only two regions are made public. | ||
NUM_REGIONS = 2 | ||
|
||
|
||
def generate_ett_small_dataset( | ||
dataset_path: Path, | ||
dataset_writer: DatasetWriter, | ||
base_file_name: str, | ||
freq: str, | ||
prediction_length: int, | ||
): | ||
dfs = [] | ||
for i in range(NUM_REGIONS): | ||
df = pd.read_csv( | ||
f"https://raw.githubusercontent.com/zhouhaoyi/ETDataset" | ||
f"/main/ETT-small/{base_file_name}{i+1}.csv" | ||
) | ||
df["date"] = df["date"].astype("datetime64[ms]") | ||
dfs.append(df) | ||
|
||
test = [] | ||
for df in dfs: | ||
start = pd.Period(df["date"][0], freq=freq) | ||
for col in df.columns: | ||
if col in ["date"]: | ||
continue | ||
test.append( | ||
{ | ||
"start": start, | ||
"target": df[col].values, | ||
} | ||
) | ||
|
||
train = [] | ||
for df in dfs: | ||
start = pd.Period(df["date"][0], freq=freq) | ||
for col in df.columns: | ||
if col in ["date"]: | ||
continue | ||
train.append( | ||
{ | ||
"start": start, | ||
"target": df[col].values[:-prediction_length], | ||
} | ||
) | ||
|
||
metadata = MetaData(freq=freq, prediction_length=prediction_length) | ||
dataset = TrainDatasets(metadata=metadata, train=train, test=test) | ||
dataset.save(str(dataset_path), writer=dataset_writer, overwrite=True) |
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