Skip to content

Commit

Permalink
Merge pull request #12 from IBM/encode_features
Browse files Browse the repository at this point in the history
Add support for exogenous, encoding of categorical
  • Loading branch information
wgifford authored Mar 21, 2024
2 parents 98bfa05 + a643d5f commit 1bb542b
Show file tree
Hide file tree
Showing 26 changed files with 1,867 additions and 985 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# python -m pip install flake8 pytest
# if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install ".[dev]"
- name: Ruff quality checks
run: |
# use hf-style check
make quality
- name: Test with pytest
run: |
pytest
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
"source.organizeImports": "explicit"
}
},
"isort.args": [
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Adapted from HF Transformers: https://github.com/huggingface/transformers/tree/main
.PHONY: quality style

check_dirs := tests src tsfm notebooks
check_dirs := tests tsfm_public tsfmhfdemos notebooks


# this target runs checks on all files

quality:
ruff check $(check_dirs) setup.py
ruff format --check $(check_dirs) setup.py
ruff check $(check_dirs)
ruff format --check $(check_dirs)

# this target runs checks on all files and potentially modifies some of them

style:
ruff check $(check_dirs) setup.py --fix
ruff format $(check_dirs) setup.py
ruff check $(check_dirs) --fix
ruff format $(check_dirs)

24 changes: 8 additions & 16 deletions notebooks/hfdemo/patch_tsmixer_blog.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp = tsp.train(train_data)"
Expand All @@ -257,26 +256,23 @@
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down Expand Up @@ -862,8 +858,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp = tsp.train(train_data)"
Expand All @@ -878,24 +873,21 @@
"train_dataset = ForecastDFDataset(\n",
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down
12 changes: 4 additions & 8 deletions notebooks/hfdemo/patch_tsmixer_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp.train(train_data)"
Expand All @@ -275,24 +274,21 @@
"train_dataset = ForecastDFDataset(\n",
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down
24 changes: 8 additions & 16 deletions notebooks/hfdemo/patch_tsmixer_transfer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@
" tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
" )\n",
" tsp.train(train_data)"
Expand All @@ -207,26 +206,23 @@
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )\n",
" valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )\n",
" test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )"
Expand Down Expand Up @@ -869,8 +865,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp.train(train_data)"
Expand All @@ -885,24 +880,21 @@
"train_dataset = ForecastDFDataset(\n",
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down
12 changes: 4 additions & 8 deletions notebooks/hfdemo/patch_tst_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp.train(train_data)"
Expand All @@ -263,24 +262,21 @@
"train_dataset = ForecastDFDataset(\n",
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down
24 changes: 8 additions & 16 deletions notebooks/hfdemo/patch_tst_transfer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@
" tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
" )\n",
" tsp.train(train_data)"
Expand All @@ -193,26 +192,23 @@
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )\n",
" valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )\n",
" test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" timestamp_column=\"date\",\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
" )"
Expand Down Expand Up @@ -584,8 +580,7 @@
"tsp = TimeSeriesPreprocessor(\n",
" timestamp_column=timestamp_column,\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" scaling=True,\n",
")\n",
"tsp.train(train_data)"
Expand All @@ -600,24 +595,21 @@
"train_dataset = ForecastDFDataset(\n",
" tsp.preprocess(train_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"valid_dataset = ForecastDFDataset(\n",
" tsp.preprocess(valid_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")\n",
"test_dataset = ForecastDFDataset(\n",
" tsp.preprocess(test_data),\n",
" id_columns=id_columns,\n",
" input_columns=forecast_columns,\n",
" output_columns=forecast_columns,\n",
" target_columns=forecast_columns,\n",
" context_length=context_length,\n",
" prediction_length=forecast_horizon,\n",
")"
Expand Down
Loading

0 comments on commit 1bb542b

Please sign in to comment.