首页 > 代码库 > Python 聚类分析LinkedIn用户人脉网络

Python 聚类分析LinkedIn用户人脉网络

CODE:

#!/usr/bin/python 
# -*- coding: utf-8 -*-

'''
Created on 2014-8-26
@author: guaguastd
@name: linkedin_network_clusters.py
'''

import os
import sys
import json
from urllib2 import HTTPError
from cluster import KMeansClustering, centroid

# A helper function to munge data and build up an XML tree
sys.path.append(os.path.join(os.getcwd(), "e:", "eclipse", "LinkedIn", "dFile"))
from mykml import createKML

K = 3

# get geo code
from geo import geo_from_bing
g = geo_from_bing()

# Load the data
CONNECTIONS_DATA = http://www.mamicode.com/'E:/eclipse/LinkedIn/dfile/linkedin_connections.json'>
RESULT:

[Location(Beijing, Beijing, China 39 54m 0.0s N, 116 23m 0.0s E)]
[Location(Beijing, Beijing, China 39 54m 0.0s N, 116 23m 0.0s E)]
None
[Location(CA, United States 37 43m 0.0s N, 122 15m 0.0s W)]
[Location(Birmingham, England, United Kingdom 52 29m 0.0s N, 1 55m 0.0s W), Location(Birmingham, England, United Kingdom 52 27m 0.0s N, 1 43m 0.0s W), Location(Birmingham Airport, England, United Kingdom 52 27m 0.0s N, 1 44m 0.0s W), Location(Birmingham Business Park, England, United Kingdom 52 28m 0.0s N, 1 43m 0.0s W)]
[Location(Birmingham, England, United Kingdom 52 29m 0.0s N, 1 55m 0.0s W), Location(Birmingham, England, United Kingdom 52 27m 0.0s N, 1 43m 0.0s W), Location(Birmingham Airport, England, United Kingdom 52 27m 0.0s N, 1 44m 0.0s W), Location(Birmingham Business Park, England, United Kingdom 52 28m 0.0s N, 1 43m 0.0s W)]
[Location(China 36 33m 0.0s N, 103 59m 0.0s E)]
[Location(China 36 33m 0.0s N, 103 59m 0.0s E)]
[Location(Chengdu, Sichuan, China 30 40m 0.0s N, 104 5m 0.0s E)]
[Location(Chengdu, Sichuan, China 30 40m 0.0s N, 104 5m 0.0s E)]
[Location(Xingtai, Hebei, China 37 4m 0.0s N, 114 29m 0.0s E)]
[Location(Xingtai, Hebei, China 37 4m 0.0s N, 114 29m 0.0s E)]
[Location(United States 39 27m 0.0s N, 98 57m 0.0s W)]
[Location(United States 39 27m 0.0s N, 98 57m 0.0s W)]
[Location(Foshan, Guangdong, China 23 2m 0.0s N, 113 6m 0.0s E)]
[Location(Foshan, Guangdong, China 23 2m 0.0s N, 113 6m 0.0s E)]
Data written to E:\eclipse\LinkedIn\dfile\linkedin_clusters_kmeans.kml


Python 聚类分析LinkedIn用户人脉网络