文章目录
一、关于 sktime
1、项目概览
sktime 是一个 Python 时间序列分析库,为多种时间序列学习任务提供统一接口。当前支持的功能包括:
- 时间序列预测
- 时间序列分类
- 时间序列聚类
- 异常/变化点检测
- 其他相关任务
该库提供时间序列算法和兼容[scikit-learn]的工具,用于构建、调优和验证时间序列模型。
2、相关链接资源
- Github:https://github.com/sktime/sktime
- 官网:https://www.sktime.net
- 官方文档:https://www.sktime.net/en/stable/users.html
- 教程:https://www.sktime.net/en/stable/examples.html
- Binder Notebooks:https://mybinder.org/v2/gh/sktime/sktime/main?filepath=examples
- YouTube 教程:https://www.youtube.com/playlist?list=PLKs3UgGjlWHqNzu0LEOeLKvnjvvest2d0
- 社区支持:
- License:BSD 3-Clause
- 版本状态:
- 引用:Zenodo
二、功能特性
1、核心模块
模块 | 状态 | 资源链接 |
---|---|---|
预测(Forecasting) | 稳定 | 教程 · API |
时间序列分类 | 稳定 | 教程 · API |
时间序列回归 | 稳定 | API |
时间序列转换 | 稳定 | 教程 · API |
异常检测 | 成熟中 | 模板 |
时间序列聚类 | 成熟中 | API |
2、生态系统集成
与以下库实现互操作:
三、安装配置
1、pip安装
# 基础安装
pip install sktime
# 完整功能安装
pip install sktime[all_extras]
# 按需安装特定模块
pip install sktime[forecasting] # 仅预测相关依赖
pip install sktime[forecasting,transformations] # 预测+转换
2、conda安装
conda install -c conda-forge sktime
# 完整功能安装
conda install -c conda-forge sktime-all-extras
四、快速入门
1、时间序列预测示例
from sktime.datasets import load_airline
from sktime.forecasting.base import ForecastingHorizon
from sktime.forecasting.theta import ThetaForecaster
from sktime.split import temporal_train_test_split
from sktime.performance_metrics.forecasting import mean_absolute_percentage_error
y = load_airline()
y_train, y_test = temporal_train_test_split(y)
fh = ForecastingHorizon(y_test.index, is_relative=False)
forecaster = ThetaForecaster(sp=12) # monthly seasonal periodicity
forecaster.fit(y_train)
y_pred = forecaster.predict(fh)
mean_absolute_percentage_error(y_test, y_pred)
>>> 0.08661467738190656
2、时间序列分类示例
from sktime.classification.interval_based import TimeSeriesForestClassifier
from sktime.datasets import load_arrow_head
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
X, y = load_arrow_head()
X_train, X_test, y_train, y_test = train_test_split(X, y)
classifier = TimeSeriesForestClassifier()
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)
accuracy_score(y_test, y_pred)
>>> 0.8679245283018868
五、社区参与
- 贡献指南:https://www.sktime.net/en/latest/get_involved/contributing.html
- 开发者文档:https://www.sktime.net/en/latest/developer_guide.html
- 社区会议:每周五13:00 UTC(Discord)
- 捐赠支持:https://opencollective.com/sktime
伊织 xAI 2025-05-27(二)