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下載鏈接

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章