pyFTSex/tutorial/darts/anomaly.ipynb
2024-10-01 12:00:12 +04:00

85 lines
2.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Anomaly Detection"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Darts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Загрузите многомерный ряд, обрежьте его, сохраните 2 компонента, разделите поезд и наборы проверки:\n",
"\n",
"from darts.datasets import ETTh2Dataset\n",
"\n",
"series = ETTh2Dataset().load()[:10000][[\"MUFL\", \"LULL\"]]\n",
"train, val = series.split_before(0.6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Создайте систему оценки аномалий k-средних, \n",
"# обучите ее на наборе поездов и используйте в проверочном наборе для получения оценок аномалий:\n",
"\n",
"from darts.ad import KMeansScorer\n",
"\n",
"scorer = KMeansScorer(k=2, window=5)\n",
"scorer.fit(train)\n",
"anom_score = scorer.score(val)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Создайте детектор бинарных аномалий и обучите его на основе оценок поезда, а затем используйте его на результатах проверки, чтобы получить классификацию бинарных аномалий:\n",
"\n",
"from darts.ad import QuantileDetector\n",
"\n",
"detector = QuantileDetector(high_quantile=0.99)\n",
"detector.fit(scorer.score(train))\n",
"binary_anom = detector.detect(anom_score)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}