最近在完成毕业设计,daoshi提供了物种故障加正常的数据集,但是数据集只有采样的频率数,
下面的代码是网上找的,但是我的数据集里面什么都没有,source,target都没有,请问应该怎么搞?
# 读取原始数据集
data = pd.read_csv(r"C:\Users\HP\Desktop\mydata\alldataaa\mydataknn1.csv")
# 构建图
G = nx.DiGraph()
for _, row in data.iterrows():
G.add_edge(row['source'], row['target'], attr_dict=row.to_dict())
# 提取节点特征和边属性
x = torch.tensor([G.nodes[node]['feature'] for node in G.nodes()])
edge_attr = torch.tensor([G.edges[edge]['attr'] for edge in G.edges()])
# 构建边索引
edge_index = torch.tensor([[e[0], e[1]] for e in G.edges()]).t().contiguous()
# 提取标签信息
y = torch.tensor(data['label'].values)
# 打印输出
print('x shape:', x.shape)
print('edge_attr shape:', edge_attr.shape)
print('edge_index shape:', edge_index.shape)
print('y shape:', y.shape)
不知道你这个问题是否已经解决, 如果还没有解决的话:属性数据(特征信息)–>特征矩阵X:[num_nodes, num_node_features]
结构数据(邻居/边信息)–>COO格式的边表edge_index:[2, num_edges]
——为后面Aggregate阶段的scatter操作埋下了伏笔!