Graph Neural Network-Based Anomaly Detection in Multivariate Time Series 代码配置及解析

可以在GPU上跑通的代码(含数据集),我已经放到了以下链接,
代码:
链接: https://pan.baidu.com/s/1_OKVH_UUwigVWOvdDVC_ig 提取码: 8a2z 复制这段内容后打开百度网盘手机App,操作更方便哦
数据集:
链接: https://pan.baidu.com/s/10ssrweMjrYBtNEIv4guE7A 提取码: 59qp 复制这段内容后打开百度网盘手机App,操作更方便哦
注意:我用的wadi数据集是删掉了几个归一化后列全为0的列,和原文不太一样;SWAT数据集是和原文一致的。

在服务器上跑
先创建一个虚拟环境
conda create -n GDN python==3.7
conda activate GDN

按照read me一步一步安装包。

### Requirements
* Python >= 3.6
* cuda == 10.2
* [Pytorch==1.5.1](https://pytorch.org/)要去这个网站复制下载命令
* [PyG: torch-geometric==1.5.0](https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html)

### Install packages
# run after installing correct Pytorch package
bash install.sh
安装
pip install scikit-learn==1.0.2
              matplotlib == 3.1.1
             numpy == 1.19.4
             pandas == 0.25.1

bash run.sh cpu swat

基于图社区神经网络(Graph Community Neural Network, GCN)和时间序列模糊决策树(Time-Series Fuzzy Decision Tree, TSFDT)的可解释性强的列车延误预测模型是一种结合了深度学习和传统机器学习技术的复杂算法。这类模型通常用于交通领域的应用,如铁路运输系统的实时调度优化。 其核心代码可能会包括以下几个部分: 1. **数据预处理**: ```python import pandas as pd from sklearn.preprocessing import MinMaxScaler # 加载数据 data = pd.read_csv('train_data.csv') scaler = MinMaxScaler() # 归一化时间序列特征 data[['delay', 'weather', ...]] = scaler.fit_transform(data[['delay', 'weather', ...]]) ``` 2. **构建图社区神经网络**: ```python import torch_geometric.nn as pyg_nn import torch_geometric.data def build_gcn_layer(): return pyg_nn.GraphConv(..., add_self_loops=True) model = Sequential( build_gcn_layer(), # GCN层 ReLU(), build_gcn_layer(), # 可能还有其他GCN层 ) ``` 3. **时间序列模糊决策树组件**: ```python from tsfuzzy import FuzzyDecisionTreeRegressor tree = FuzzyDecisionTreeRegressor(...) ``` 4. **集成模型**: ```python class IntegratedModel(nn.Module): def __init__(self): super().__init__() self.gcn = model self.tsft = tree def forward(self, x, graph): gcn_output = self.gcn(x, graph) tsft_input = gcn_output.view(-1, ...) delay_pred = self.tsft(tsft_input) return delay_pred ``` 5. **训练和预测**: ```python optimizer = Adam(model.parameters(), lr=0.01) for epoch in range(num_epochs): train_loss = train_model(model, data_train, optimizer) validate_loss = evaluate_model(model, data_val) # 预测阶段 with torch.no_grad(): test_delay_pred = integrated_model(test_data.x, test_data.edge_index) ```
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值