Skip to content

Commit 101e0f8

Browse files
committed
Update and release a new version
1 parent 4336887 commit 101e0f8

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

.github/workflows/pypi-release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Upload to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.9'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install build twine
27+
28+
- name: Build package
29+
run: python -m build
30+
31+
- name: Publish to PyPI
32+
env:
33+
TWINE_USERNAME: __token__
34+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
35+
run: twine upload dist/*

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "tsmorph"
7-
version = "0.1.0"
7+
version = "0.1.1"
88
description = "A package for generating semi-synthetic time series using morphing techniques."
99
readme = "README.md"
1010
authors = [

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='tsmorph',
5-
version='0.1.0',
5+
version='0.1.1',
66
packages=find_packages(),
77
install_requires=[
88
'numpy',

tsmorph/tsmorph.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
import pandas as pd
33
import matplotlib.pyplot as plt
44
from pycatch22 import catch22_all
5-
from neuralforecast.losses.numpy import mase
6-
from .utils import plot_gradient_timeseries
5+
from .utils import plot_gradient_timeseries, nmae
76

87
class TSmorph:
98
"""
@@ -61,7 +60,7 @@ def analyze_morph_performance(self, df: pd.DataFrame, model, horizon: int, seaso
6160
horizon (int): Forecast horizon for testing.
6261
"""
6362
feature_values = []
64-
mase_values = []
63+
nmae_values = []
6564

6665
for col in df.columns:
6766
series = df[col].values
@@ -80,19 +79,19 @@ def analyze_morph_performance(self, df: pd.DataFrame, model, horizon: int, seaso
8079
forecast_df = model.predict(test)
8180
forecast = forecast_df[forecast_df['unique_id'] == col][model.models[0].__class__.__name__].values[:horizon]
8281

83-
mase_values.append(mase(y=test['y'].values, y_hat=forecast, y_train=df_forecast.iloc[:-horizon]['y'].values, seasonality=seasonality))
82+
nmae_values.append(nmae(y=test['y'].values, y_hat=forecast))
8483

8584
feature_values = np.array(feature_values)
86-
mase_values = np.array(mase_values)
85+
nmae_values = np.array(nmae_values)
8786

8887
num_features = feature_values.shape[1]
8988
x_values = np.arange(len(df.columns))
9089

9190
for i in range(num_features):
9291
plt.figure(figsize=(8, 5))
93-
sc = plt.scatter(x_values, feature_values[:, i], c=mase_values, cmap='viridis', edgecolors='k')
94-
plt.colorbar(sc, label='MASE')
92+
sc = plt.scatter(x_values, feature_values[:, i], c=nmae_values, cmap='viridis', edgecolors='k')
93+
plt.colorbar(sc, label='NMAE')
9594
plt.xlabel('Granularity Level')
9695
plt.ylabel(feature_names[i])
97-
plt.title(f'{feature_names[i]} variation with MASE')
96+
plt.title(f'{feature_names[i]} variation with NMAE')
9897
plt.show()

tsmorph/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import matplotlib.pyplot as plt
2+
import numpy as np
23

34
def plot_gradient_timeseries(df, start_color='#61E6AA', end_color='#5722B1'):
45
# Convert hex to RGB
@@ -36,4 +37,17 @@ def hex_to_rgb(hex_color):
3637
# Adjust layout to prevent label cutoff
3738
plt.tight_layout()
3839
plt.show()
39-
return
40+
return
41+
42+
def nmae(y, y_hat):
43+
"""
44+
Computes the Normalized Mean Absolute Error (NMAE).
45+
46+
Args:
47+
y (np.array): True values.
48+
y_hat (np.array): Predicted values.
49+
50+
Returns:
51+
float: NMAE score.
52+
"""
53+
return np.mean(np.abs(y - y_hat)) / np.mean(np.abs(y))

0 commit comments

Comments
 (0)