Skip to main content

A Wrapper around MLForecast.

Project description

Seánce v0.0.5

A simple wrapper around Nixtla's MLForecast aimed at streamlining plug-and-play forecasting.

A general pattern is to optimize then forecast such as:

from mlforecast.utils import generate_daily_series
series = generate_daily_series(
    n_series=20,
    max_length=100,
    min_length=50,
    with_trend=True
)


from Seance.Optimizer import Optimize
opt = Optimize(series,
            target_column='y',
            date_column='ds',
            id_column='unique_id',
            freq='D',
            seasonal_period=7,
            test_size=10,
            # ar_lags=[list(range(1, 8))], #by default this will be done based on seasonal period
            metric='smape',
            n_trials=100)
#returns an optuna study obj
best_params, study = opt.fit(seed=1)

optuna plotting

import optuna
optuna.visualization.matplotlib.plot_param_importances(study)

alt text Here we can see the most important parameter is (unsurprisingly) the number of lags. Followd by decay which controls the 'forgetfulness' of the basis functions.

optuna.visualization.matplotlib.plot_optimization_history(study)

alt text

passing off best params for forecasts

from Seance.Forecaster import Forecaster
seance = Forecaster()
output = seance.fit(series,
                    target_column='y',
                    date_column='ds',
                    id_column='unique_id',
                    freq='D',
                    **best_params)
predicted = seance.predict(24)

quick plot of the forecasts

import matplotlib.pyplot as plt
plot_ser = np.append(series[series['unique_id'] == 'id_00']['y'].values,
                     predicted[predicted['unique_id'] == 'id_00']['LGBMRegressor'].values)
plt.plot(plot_ser)
plt.vlines(x=len(plot_ser) - 24, ymin=0, ymax=max(plot_ser), linestyle='dashed', color='red')
plt.show()

alt text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

Seance-0.0.9-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file Seance-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: Seance-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.15

File hashes

Hashes for Seance-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 894d0765c75ca6feadfdc87a6d8371d31233a7bcafbbcfa395fa3a72152bc760
MD5 679c9d9e8866682455ed89e47e03518a
BLAKE2b-256 550f45e52faf3b277c1b01ee6497e1302b8fa1dc983ab7163aedbfbcdd310ab1

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page