Learn R Programming

nixtlar

Version 0.6.0 of nixtlar is now available! (2024-10-07)

We are excited to announce the release of nixtlar version 0.6.0, which integrates the latest release of the TimeGPT API—v2. This update focuses on what matters most to our users: speed, scalability, and reliability.

Key updates include:

  • Data Structures: nixtlar now extends support to tibbles, in addition to the previously supported data frames and tsibbles. This broadens the range of data structures that can be used in your workflows.

  • Date Formats: For efficiency, nixtlar now strictly requires dates to be in the format YYYY-MM-DD or YYYY-MM-DD hh:mm:ss, either as character strings or date-time objects. For more details, please refer to our Get Started guide and Data Requirements vignette.

  • Default ID Column: In alignment with the Python SDK, nixtlar now defaults the id_col to unique_id. This means you no longer need to specify this column if it is already named unique_id. If your dataset contains only one series, simply set id_col=NULL. The id_col only accepts characters or integers.

These changes leverage the capabilities of TimeGPT’s new API and align nixtlar more closely with the Python SDK, ensuring a better user experience.

TimeGPT-1

The first foundation model for time series forecasting and anomaly detection

TimeGPT is a production-ready, generative pretrained transformer for time series forecasting, developed by Nixtla. It is capable of accurately predicting various domains such as retail, electricity, finance, and IoT, with just a few lines of code. Additionally, it can detect anomalies in time series data.

TimeGPT was initially developed in Python but is now available to R users through the nixtlar package.

Table of Contents

Installation

nixtlar is available on CRAN, so you can install the latest stable version using install.packages.

# Install nixtlar from CRAN
install.packages("nixtlar")

# Then load it 
library(nixtlar)

Alternatively, you can install the development version of nixtlar from GitHub with devtools::install_github.

# install.packages("devtools")
devtools::install_github("Nixtla/nixtlar")

Forecast Using TimeGPT in 3 Easy Steps

library(nixtlar)
  1. Set your API key. Get yours at dashboard.nixtla.io
nixtla_set_api_key(api_key = "Your API key here")
  1. Load sample data
df <- nixtlar::electricity
head(df)
#>   unique_id                  ds     y
#> 1        BE 2016-10-22 00:00:00 70.00
#> 2        BE 2016-10-22 01:00:00 37.10
#> 3        BE 2016-10-22 02:00:00 37.10
#> 4        BE 2016-10-22 03:00:00 44.75
#> 5        BE 2016-10-22 04:00:00 37.10
#> 6        BE 2016-10-22 05:00:00 35.61
  1. Forecast the next 8 steps ahead
nixtla_client_fcst <- nixtla_client_forecast(df, h = 8, level = c(80,95))
#> Frequency chosen: h
head(nixtla_client_fcst)
#>   unique_id                  ds  TimeGPT TimeGPT-lo-95 TimeGPT-lo-80
#> 1        BE 2016-12-31 00:00:00 45.19045      30.49691      35.50842
#> 2        BE 2016-12-31 01:00:00 43.24445      28.96423      35.37463
#> 3        BE 2016-12-31 02:00:00 41.95839      27.06667      35.34079
#> 4        BE 2016-12-31 03:00:00 39.79649      27.96751      32.32625
#> 5        BE 2016-12-31 04:00:00 39.20454      24.66072      30.99895
#> 6        BE 2016-12-31 05:00:00 40.10878      23.05056      32.43504
#>   TimeGPT-hi-80 TimeGPT-hi-95
#> 1      54.87248      59.88399
#> 2      51.11427      57.52467
#> 3      48.57599      56.85011
#> 4      47.26672      51.62546
#> 5      47.41012      53.74836
#> 6      47.78252      57.16700

Optionally, plot the results

nixtla_client_plot(df, nixtla_client_fcst, max_insample_length = 200)

Anomaly Detection Using TimeGPT in 3 Easy Steps

Do anomaly detection with TimeGPT, also in 3 easy steps! Follow steps 1 and 2 from the previous section and then use the nixtla_client_detect_anomalies and the nixtla_client_plot functions.

nixtla_client_anomalies <- nixtlar::nixtla_client_detect_anomalies(df) 
#> Frequency chosen: h
head(nixtla_client_anomalies)
#>   unique_id                  ds     y anomaly  TimeGPT TimeGPT-lo-99
#> 1        BE 2016-10-27 00:00:00 52.58   FALSE 56.07623     -28.58337
#> 2        BE 2016-10-27 01:00:00 44.86   FALSE 52.41973     -32.23986
#> 3        BE 2016-10-27 02:00:00 42.31   FALSE 52.81474     -31.84486
#> 4        BE 2016-10-27 03:00:00 39.66   FALSE 52.59026     -32.06934
#> 5        BE 2016-10-27 04:00:00 38.98   FALSE 52.67297     -31.98662
#> 6        BE 2016-10-27 05:00:00 42.31   FALSE 54.10659     -30.55301
#>   TimeGPT-hi-99
#> 1      140.7358
#> 2      137.0793
#> 3      137.4743
#> 4      137.2499
#> 5      137.3326
#> 6      138.7662
nixtlar::nixtla_client_plot(df, nixtla_client_anomalies, plot_anomalies = TRUE)

Features and Capabilities

nixtlar provides access to TimeGPT’s features and capabilities, such as:

  • Zero-shot Inference: TimeGPT can generate forecasts and detect anomalies straight out of the box, requiring no prior training data. This allows for immediate deployment and quick insights from any time series data.

  • Fine-tuning: Enhance TimeGPT’s capabilities by fine-tuning the model on your specific datasets, enabling the model to adapt to the nuances of your unique time series data and improving performance on tailored tasks.

  • Add Exogenous Variables: Incorporate additional variables that might influence your predictions to enhance forecast accuracy. (E.g. Special Dates, events or prices)

  • Multiple Series Forecasting: Simultaneously forecast multiple time series data, optimizing workflows and resources.

  • Custom Loss Function: Tailor the fine-tuning process with a custom loss function to meet specific performance metrics.

  • Cross Validation: Implement out of the box cross-validation techniques to ensure model robustness and generalizability.

  • Prediction Intervals: Provide intervals in your predictions to quantify uncertainty effectively.

  • Irregular Timestamps: Handle data with irregular timestamps, accommodating non-uniform interval series without preprocessing.

Documentation

For comprehensive documentation, please refer to our vignettes, which cover a wide range of topics to help you effectively use nixtlar. The current documentation includes guides on how to:

The documentation is an ongoing effort, and we are working on expanding its coverage.

API Support

Are you a Python user? If yes, then check out the Python SDK for TimeGPT. You can also refer to our API reference for support in other programming languages.

How to Cite

If you find TimeGPT useful for your research, please consider citing the TimeGPT-1 paper. The associated reference is shown below.

Garza, A., Challu, C., & Mergenthaler-Canseco, M. (2024). TimeGPT-1. arXiv preprint arXiv:2310.03589. Available at https://arxiv.org/abs/2310.03589

License

TimeGPT is closed source. However, this SDK is open source and available under the Apache 2.0 License, so feel free to contribute!

Get in Touch

We welcome your input and contributions to the nixtlar package!

  • Report Issues: If you encounter a bug or have a suggestion to improve the package, please open an issue in GitHub.

  • Contribute: You can contribute by opening a pull request in our repository. Whether it is fixing a bug, adding a new feature, or improving the documentation, we appreciate your help in making nixtlar better.

Copy Link

Version

Install

install.packages('nixtlar')

Monthly Downloads

525

Version

0.6.1

License

Apache License (>= 2.0)

Issues

Pull Requests

Stars

Forks

Maintainer

Mariana Menchero

Last Published

October 10th, 2024

Functions in nixtlar (0.6.1)

.r_frequency

Convert period or offset aliases to a character string recognized by R. This is a private function of 'nixtlar'
nixtla_validate_api_key

Validate 'API' key
nixtla_set_api_key

Set 'API' key in global environment
.level_from_quantiles

Obtain level from quantiles This is a private function of 'nixtlar'
nixtla_client_plot

Plot the output of the following nixtla_client functions: forecast, historic, anomaly_detection, and cross_validation.
nixtlar-package

nixtlar: A Software Development Kit for 'Nixtla''s 'TimeGPT'
infer_frequency

Infer frequency of a data frame.
electricity_exo_vars

Electricity dataset with exogenous variables
nixtla_client_forecast

Sequential version of 'nixtla_client_forecast' This is a private function of 'nixtlar'
nixtla_client_detect_anomalies

Sequential version of 'nixtla_client_detect_anomalies' This is a private function of 'nixtlar'
nixtla_client_cross_validation

Sequential version of 'nixtla_client_cross_validation' This is a private function of 'nixtlar'
nixtla_client_historic

Sequential version of 'nixtla_client_historic' This is a private function of 'nixtlar'
.get_api_key

Get NIXTLA_API_KEY from options or from .Renviron This is a private function of 'nixtlar'
.generate_output_dates

Generate output dates for forecast method. This is a private function of 'nixtlar'
electricity

Electricity dataset
.make_request

Make requests to the 'TimeGPT' API This is a private function of 'nixtlar'
.get_model_params

Retrieve parameters for 'TimeGPT' model This is a private function of 'nixtlar'
.validate_exogenous

Validate future exogenous variables (if applicable) This is a private function of 'nixtlar'
electricity_future_exo_vars

Future values for the electricity dataset with exogenous variables
.transient_errors

A function used by httr2::req_retry() to determine if the response represents a transient error This is a private function of 'nixtlar'