首页 > 其他分享 >图级别数据读取函数示例

图级别数据读取函数示例

时间:2023-06-26 12:13:28浏览次数:31  
标签:node index 读取 示例 df graph labels filename 级别

def _load_graph_kernel_dataset(dataset):

    dataset.download()

    def _load_from_txt_file(filename, names=None, dtype=None, index_increment=None):
        df = pd.read_csv(
            dataset._resolve_path(filename=f"{dataset.name}_{filename}.txt"),
            header=None,
            index_col=False,
            dtype=dtype,
            names=names,
        )
        # We optional increment the index by 1 because indexing, e.g. node IDs, for this dataset starts
        # at 1 whereas the Pandas DataFrame implicit index starts at 0 potentially causing confusion selecting
        # rows later on.
        if index_increment:
            df.index = df.index + index_increment
        return df

    # edge information:
    df_graph = _load_from_txt_file(filename="A", names=["source", "target"])

    if dataset._edge_labels_as_weights:
        # there's some edge labels, that can be used as edge weights
        df_edge_labels = _load_from_txt_file(
            filename="edge_labels", names=["weight"], dtype=int
        )
        df_graph = pd.concat([df_graph, df_edge_labels], axis=1)

    # node information:
    df_graph_ids = _load_from_txt_file(
        filename="graph_indicator", names=["graph_id"], index_increment=1
    )

    df_node_labels = _load_from_txt_file(
        filename="node_labels", dtype="category", index_increment=1
    )
    # One-hot encode the node labels because these are used as node features in graph classification
    # tasks.
    df_node_features = pd.get_dummies(df_node_labels)

    if dataset._node_attributes:
        # there's some actual node attributes
        df_node_attributes = _load_from_txt_file(
            filename="node_attributes", dtype=np.float32, index_increment=1
        )

        df_node_features = pd.concat([df_node_features, df_node_attributes], axis=1)

    # graph information:
    df_graph_labels = _load_from_txt_file(
        filename="graph_labels", dtype="category", names=["label"], index_increment=1
    )

    # split the data into each of the graphs, based on the nodes in each one
    def graph_for_nodes(nodes):
        # each graph is disconnected, so the source is enough to identify the graph for an edge
        edges = df_graph[df_graph["source"].isin(nodes.index)]
        return StellarGraph(nodes, edges)

    groups = df_node_features.groupby(df_graph_ids["graph_id"])
    graphs = [graph_for_nodes(nodes) for _, nodes in groups]

    return graphs, df_graph_labels["label"]

标签:node,index,读取,示例,df,graph,labels,filename,级别
From: https://www.cnblogs.com/ZZXJJ/p/17505296.html

相关文章

  • 配置文件 proxy_set_header -发往后端服务器的请求头---- nginx日志设置级别调试技巧
    http{includemime.types;default_typeapplication/octet-stream;sendfileon;#tcp_nopushon;#keepalive_timeout0;keepalive_timeout65;server_tokensoff;log_formatmain'$remote_addr-$remote_user[$time_local]......
  • C/C++按位读取
    RinpoStk按位读取在C中无法直接按位读取,常见的方法是通过位运算获取每一位的数据。//获取B5第4位//(B5&(1<<5))>>5 10110101& 00010000;= 00010000//得到1采取共用体(联合)可以得到一个既可以按位读取,也可以按字节读取的数据类型union{struct{un......
  • 评估级别-评估分类
    评估级别-评估分类 ......
  • 图文示例二叉树的编码实现过程
    前言在上一篇文章中,带大家一起学习认识了树型数据结构的定义和特点,并特别介绍了二叉树的遍历操作,分别有:前序遍历、中序遍历、后序遍历。前中后的核心区别是根据根节点在遍历过程中的位置决定的,即:根节点在最前面的称之为中序遍历,根节点在中间的称之为中序遍历,根节点在最后的称之为......
  • prometheus 使用 ipmi exporter 增加硬件级别监控
    prometheus监控硬件安装ipmitool并加载相应模块yuminstallipmitoolfreeipmi-ymodprobeipmi_msghandlermodprobeipmi_devintfmodprobeipmi_poweroffmodprobeipmi_simodprobeipmi_watchdog下载ipmi_exporter源码包wgethttps://github.com/soundcloud/ipmi_......
  • 【拼多多商品详情数据】API接口获得宝贝详情数据、商品标题数据等Java调用示例
    ​拼多多商品详情API接口的作用是获取拼多多平台上某个商品的详细信息,包括商品标题、价格、图片、规格、参数、店铺信息等。开发者可以通过该接口获取到商品的原始数据,方便进行数据分析、价格比较、爬取等操作。通过该接口获取到的商品详情数据可以结合其他数据进行深度挖掘,例如......
  • 【淘宝商品详情数据】api接口获得宝贝详情数据、优惠价格数据Java调用示例
    淘宝详情API接口的作用是获取淘宝平台上某个商品的详细信息,包括商品标题、价格、图片、规格、参数、店铺信息等。开发者可以通过该接口获取到商品的原始数据,方便进行数据分析、价格比较、爬取等操作。通过该接口获取到的商品详情数据可以结合其他数据进行深度挖掘,例如可以将商品数......
  • Linux从文件中逐行读取文件名并将匹配的文件复制到指定目录
    问题应该算挺常见的但是一句话还挺难说清楚,所以百度特别难搜。场景就是,有一堆以员工名称命名的文件(名称可能还有字母数字等前后缀),现在给定一个员工清单,需要从这些文件中筛选出员工清单上列出的员工的文件,并复制到另外一个目录中。输入:1.许多文件名包含员工名称的文件2.一个清......
  • 179_自动生成 千万级 Power BI 示例数据
    179_自动生成千万级PowerBI示例数据在早一些是时候,我曾写过一个示例数据《赠送300家门店260亿销售额的零售企业PowerBI实战示例数据》,本次我们对该示例数据做了一些调整。一、更新内容针对有一些朋友不会使用vba模块,我们增加了UI操作。填写几个简单的参数即可生成......
  • WPF入门教程系列二十九 ——DataGrid使用示例MVVM模式(7)
    WPF入门教程系列目录WPF入门教程系列二——Application介绍WPF入门教程系列三——Application介绍(续)WPF入门教程系列四——Dispatcher介绍WPF入门教程系列五——Window介绍WPF入门教程系列十一——依赖属性(一)WPF入门教程系列十五——WPF中的数据绑定(一) 接上文WPF......