Football数据集可视化处理——gephi可视化处理数据

1 football数据集的文件格式

根据如图所示football数据集和的文件格式如下所示:
下图表示football数据集节点部分信息
这里写图片描述
下图表示football数据集边的部分信息
这里写图片描述
根据上述两个图中的格式对football数据集的格式介绍可以介绍为如下所示:

Creator "Mark Newman on Sat Jul 22 05:32:16 2006"
graph
[
  node
  [
    id **
    value **
    label ****
  ]
  ...
  node
  [
    id **
    value **
    label ****
  ]
  edge
  [
    id **
    value **
    label ****
  ]
  ...
  edge
  [
    id ***
    value **
    label ****
  ]
]

2 football数据集文件格式的转化

根据上述的football文件,我们将数据文件转化成两个文件,这两个文件分别用来存储football数据集的边信息和节点信息,对football数据集文件的处理如下。

2.1 football数据集节点信息文件

根据gephi通过csv导入信息的需要,我们将数据信息处理成如下的数据集节点文件格式:

Id Label Value
1  Tom   3
2  Bob   4

在football数据集中将football.gml文件处理得到的结果如下所示:
这里写图片描述
其中:

Id:用于标识唯一的一个点
Label:标识节点的标签或者是名称
Value:标识节点的所属的社区。

2.2 football数据集边信息文件

根据gephi通过csv导入数据的格式,我们分为有向图和无向图两种数据格式,对于有向图的导入数据格式如下所示:

Source Target Weight
1 3 2
2 4 1
根据上述公式:
Source:表示源节点
Target:表示目的结点
Weight:表示对应的边的权重

在无向图的导入中需要加入Type类型得出的数据格式如下所示:

Source Target Weigth Type
1 3 2 Undirected
2 4 1 Undirected

如下图所示为football数据集的数据个格式,football数据集是无权图因此没有有weight。
这里写图片描述

在football数据集的616条边中有三条边是重复出现的分别为

28 18
85 4
100 15

在通过gephi对这些边进行模块化社区划分运算的时候需要将这些边删除,否则无法运行。

2.3 对football.gml处理代码

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main()
{
    FILE* inputfile = NULL;
    FILE* nodefile = NULL;
    FILE* edgefile = NULL;
    inputfile = fopen("football.gml","r");
    nodefile = fopen("nodefile.txt","w");
    edgefile = fopen("edgefile.txt","w");
    fprintf(nodefile, "Id Label Value\n");
    fprintf(edgefile,"Source Target Type\n");
    char strLine[1024];
    int i = 0;
    int node = 0;
    int edge = 0;
    //char nodeinfo[100];
    char edgeinfo[100];
    while(!feof(inputfile))
    {
        fgets(strLine,1024, inputfile);
        if(strncmp(strLine+4,"id",2)==0 )
        {
            char id[5];
            char label[50];
            char value[5];
            memset(label,0,50);
            int idint = 0, valueint = 0;
            int copylen = 0;
            copylen = strlen(strLine) - 8;
            strncpy(id,strLine+7,copylen);
            idint = atoi(id)+1;
            fgets(strLine,1024, inputfile);
            copylen = strlen(strLine) - 13;
            strncpy(label,strLine+11,copylen);
            fgets(strLine,1024, inputfile);
            copylen = strlen(strLine) - 10;
            strncpy(value,strLine+10,copylen);
            valueint = atoi(value)+1;
            //cout << valueint << endl;
            fprintf(nodefile,"%d %s %d\n",idint,label,valueint);
        }
        if(strncmp(strLine+4,"source",6)==0)
        {
            char target[5];
            char source[5];
            int sourceint = 0,targetint = 0;
            memset(target,0,5);
            memset(source,0,5);
            int copylen = 0;
            copylen = strlen(strLine)-12;
            strncpy(source,strLine+11,copylen);
            sourceint = atoi(source)+1;
            fgets(strLine,1024, inputfile);
            copylen = strlen(strLine)-12;
            strncpy(target,strLine+11,copylen);
            targetint = atoi(target)+1;
            fprintf(edgefile,"%d %d undirected\n",sourceint,targetint);
        }
    }
    fclose(nodefile);
    fclose(edgefile);
    return 0;
}

3 gephi点表和边表的导入并生成football图像

(1)点击文件->Import spreadsheet如下图所示:
这里写图片描述

(2)选择需要导入的文件进行数据导入
这里写图片描述
注意选择导入的是边表格还是点表格

(3)点击模块化
这里写图片描述

(4)设置参数为0.4
这里写图片描述

(5)选择节点的渲染方式为Modularity Class
这里写图片描述
(6)得到football的社区划分和真实社区对比

football数据集通过gephi进行社区划分的结果(不带有边的图)
这里写图片描述
football数据集真实社区的结果(不带有边的图)
这里写图片描述
football数据集通过gephi进行社区划分的结果(带有边的图)
这里写图片描述
football数据集真实社区的结果(带有边的图)
这里写图片描述

根据上述的结果我们可以对比得到gephi生成的社区和真实社区的差别,并且最终得到如下所示的两张对比图片。

gephi基于模块度生成社区划分的图片
这里写图片描述
football给出的标签的真实社区图片
这里写图片描述
football数据集以及相关数据集下载地址
CSDN下载链接

发布了15 篇原创文章 · 获赞 7 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/redhatforyou/article/details/76423188