Mastering AutoTS: Your Guide to Time Series Forecasting in Python

Jan 10, 2021 | Data Science

Welcome to the world of AutoTS, a powerful time series forecasting package for Python that has taken the analytics community by storm. This tool allows you to swiftly deploy accurate forecasts and it was even victorious in the M6 forecasting competition of 2023. Whether you’re dealing with stock market predictions or other time series data, AutoTS has got your back!

Table of Contents

Installation

To get started with AutoTS, first, you need to install it. Run the following command in your terminal:

pip install autots

This will install AutoTS along with the necessary dependencies for basic models. Just a quick note: if you want to use certain models and functionalities, additional packages might be required which you can find detailed in the documentation.

Basic Use

AutoTS expects to receive your data in either a long or a wide format:

  • Wide Format: A pandas.DataFrame with a pandas.DatetimeIndex where each column represents a distinct series.
  • Long Format: This format includes three columns:
    • Date (in a pandas-recognized datetime format)
    • Series ID (use None for a single series)
    • Value

When using long data, simply specify the column names when calling .fit(). For wide data, no extra parameters are needed.

Here’s an analogy to make it easier to grasp: Think of your data as if you were preparing a salad. In the wide format, all ingredients (data series) are laid out in separate bowls (columns) on the table. In the long format, you put all your ingredients (data) into a single bowl where you have them organized with labels (columns) so you can easily access each one as you prepare your salad. This structure aids AutoTS in mixing and matching the right components (models) for your predictions!

Here’s a quick example of using AutoTS:

from autots import AutoTS, load_daily

df = load_daily(long=False)
model = AutoTS(
    forecast_length=21,
    frequency='infer',
    prediction_interval=0.9,
    ensemble='auto',
    model_list='fast',
    drop_most_recent=1,
    max_generations=4,
    num_validations=2,
    validation_method='backwards'
)

model = model.fit(
    df,
    date_col=None,
    value_col='value'
)

prediction = model.predict()
prediction.plot(model.df_wide_numeric, series=model.df_wide_numeric.columns[0], start_date='2019-01-01')
print(model)
forecasts_df = prediction.forecast
forecasts_up, forecasts_low = prediction.upper_forecast, prediction.lower_forecast
model_results = model.results()
validation_results = model.results(validation='True')

Tips for Speed and Large Data

  • Utilize predefined model lists like superfast for naive models or fast for more complex models optimized for larger datasets.
  • If working with many similar series, consider using the subset parameter to prevent overload. For example, subset=100 would be a handy choice!
  • If your memory is constrained, running multiple instances of AutoTS on batches of data could help.
  • Set model_interrupt=True to skip the current model during training if you press Ctrl+C.
  • Pre-fill any NaN values in your dataset to speed up processing.

Troubleshooting

If things go awry, here are a few hints to guide you:

  • If you encounter crashes, it may be due to memory shortages. Tackle this by testing with a smaller dataset or trying a different model list.
  • For speed concerns, ensure you’re using an optimal model_list.
  • Check the documentation for any specific issues related to certain model parameters.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Conclusion

The AutoTS package is not just a tool; it’s an invaluable asset for anyone looking to make sense of time series data efficiently and effectively. With its flexible models, insightful metrics, and seamless integration, you have the power to tackle forecasting challenges head-on!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox