sktime: Unified Framework for Time Series Machine Learning

0.40.1 · active · verified Sat Apr 11

sktime is a Python library for machine learning with time series. It provides a unified interface for various time series tasks, including forecasting, classification, regression, and transformation. It integrates seamlessly with `scikit-learn` and offers a modular architecture for building complex time series pipelines. The project is actively maintained with frequent minor and patch releases, typically every few weeks.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic time series forecasting workflow using `sktime`. It covers data preparation, model initialization, fitting, and prediction with the `ThetaForecaster`. Note that plotting requires the `matplotlib` library, which is an optional dependency.

import pandas as pd
from sktime.forecasting.model_selection import temporal_train_test_split
from sktime.forecasting.theta import ThetaForecaster
from sktime.utils.plotting import plot_series # requires 'matplotlib' optional dependency

# 1. Data loading and splitting
y = pd.Series([10, 12, 13, 15, 18, 20, 22, 25, 28, 30])
y.index = pd.to_datetime(pd.date_range("2020-01-01", periods=10, freq="M"))
y_train, y_test = temporal_train_test_split(y, test_size=3)

# 2. Model selection and fitting
forecaster = ThetaForecaster(sp=1)
forecaster.fit(y_train)

# 3. Prediction
fh = [1, 2, 3]  # forecast horizon for next 3 periods
y_pred = forecaster.predict(fh=fh)

print("Training data:\n", y_train)
print("Test data:\n", y_test)
print("Predictions:\n", y_pred)

# To plot, ensure matplotlib is installed (pip install matplotlib)
# plot_series(y_train, y_test, y_pred, labels=["y_train", "y_test", "y_pred"])

view raw JSON →