def network(dbname, colname, netname): '''Get users' friendship network''' # # ed_usersd = ed_user(dbname, colname) # # pickle.dump(ed_usersd, open('data/ed_users.pick', 'w')) # ed_usersd = pickle.load(open('data/ed_users.pick', 'r')) # # # rec_usersd = rec_user(dbname, colname) # # pickle.dump(rec_usersd, open('data/rec_users.pick', 'w')) # rec_usersd = pickle.load(open('data/rec_users.pick', 'r')) # # # inlist = list(set(ed_usersd).union(set(rec_usersd))) # # print len(inlist) # g = gt.load_network_subset(inlist, dbname, netname) # g.vs['rec'] = 0 # for uid in rec_usersd: # exist = True # try: # v = g.vs.find(name=str(uid)) # except ValueError: # exist = False # if exist: # v['rec'] = 1 # pickle.dump(g, open('data/rec_friendship.pick', 'w')) rg = pickle.load(open('data/rec_friendship.pick', 'r')) # g.write_gml('data/rec_friendship.GML') # g.write_dot('data/rec_friendship.DOT') gc = gt.giant_component(rg, 'WEAK') comm = gt.fast_community(gc, False) fclus = comm.as_clustering(2) communit_topinflu(fclus, None)
def communtiy_feature(dbname, typename): fg = ntt.loadnet(dbname, typename) fcoms = gt.fast_community(fg) pickle.dump(fcoms, open('data/'+dbname+typename+'com.pick', 'w')) fcoms = pickle.load(open('data/'+dbname+typename+'com.pick', 'r')) fclus = fcoms.as_clustering() gt.summary(fclus) """Compare difference of features in cummunities""" features = [ 'liwc_anal.result.i', 'liwc_anal.result.we', 'liwc_anal.result.bio', 'liwc_anal.result.body', 'liwc_anal.result.health', 'liwc_anal.result.posemo', 'liwc_anal.result.negemo', 'liwc_anal.result.ingest', 'liwc_anal.result.anx', 'liwc_anal.result.anger', 'liwc_anal.result.sad' ] therh = 0.1 * fg.vcount() for feature in features: data = [] for clu in fclus: if len(clu) > therh: ulist = set() for v in clu: ulist.add(int(fg.vs[v]['name'])) ulist = list(ulist) clu_values = iot.get_values_one_field(dbname, 'com', feature, {'id': {'$in': ulist}}) data.append(clu_values) plot.plot_config() for i in xrange(len(data)): sns.distplot(data[i], hist=False, label=str(i)+':'+str(len(data[i]))) plt.xlabel(feature) plt.ylabel('PDF') # plt.show() plt.savefig(feature+typename+'_com.pdf') plt.clf()
def communtiy_feature(dbname, typename): fg = ntt.loadnet(dbname, typename) fcoms = gt.fast_community(fg) pickle.dump(fcoms, open('data/' + dbname + typename + 'com.pick', 'w')) fcoms = pickle.load(open('data/' + dbname + typename + 'com.pick', 'r')) fclus = fcoms.as_clustering() gt.summary(fclus) """Compare difference of features in cummunities""" features = [ 'liwc_anal.result.i', 'liwc_anal.result.we', 'liwc_anal.result.bio', 'liwc_anal.result.body', 'liwc_anal.result.health', 'liwc_anal.result.posemo', 'liwc_anal.result.negemo', 'liwc_anal.result.ingest', 'liwc_anal.result.anx', 'liwc_anal.result.anger', 'liwc_anal.result.sad' ] therh = 0.1 * fg.vcount() for feature in features: data = [] for clu in fclus: if len(clu) > therh: ulist = set() for v in clu: ulist.add(int(fg.vs[v]['name'])) ulist = list(ulist) clu_values = iot.get_values_one_field(dbname, 'com', feature, {'id': { '$in': ulist }}) data.append(clu_values) plot.plot_config() for i in xrange(len(data)): sns.distplot(data[i], hist=False, label=str(i) + ':' + str(len(data[i]))) plt.xlabel(feature) plt.ylabel('PDF') # plt.show() plt.savefig(feature + typename + '_com.pdf') plt.clf()
def benetwork(dbname, type, netname): '''Get users' behavior networks''' # ed_usersd = pickle.load(open('data/ed_users.pick', 'r')) # rec_usersd = pickle.load(open('data/rec_users.pick', 'r')) # inlist = list(set(ed_usersd).union(set(rec_usersd))) # g = gt.load_beh_network_subset(inlist, dbname, netname, type) # g.vs['rec'] = 0 # for uid in rec_usersd: # exist = True # try: # v = g.vs.find(name=str(uid)) # except ValueError # exist = False # if exist: # v['rec'] = 1 # pickle.dump(g, open('data/rec_'+type+'.pick', 'w')) rg = pickle.load(open('data/rec_'+type+'.pick', 'r')) # plot_graph(g) gc = gt.giant_component(rg, 'WEAK') comm = gt.fast_community(gc, True) fclus = comm.as_clustering(2) communit_topinflu(fclus, 'weight')
def benetwork(dbname, type, netname): '''Get users' behavior networks''' # ed_usersd = pickle.load(open('data/ed_users.pick', 'r')) # rec_usersd = pickle.load(open('data/rec_users.pick', 'r')) # inlist = list(set(ed_usersd).union(set(rec_usersd))) # g = gt.load_beh_network_subset(inlist, dbname, netname, type) # g.vs['rec'] = 0 # for uid in rec_usersd: # exist = True # try: # v = g.vs.find(name=str(uid)) # except ValueError: # exist = False # if exist: # v['rec'] = 1 # pickle.dump(g, open('data/rec_'+type+'.pick', 'w')) rg = pickle.load(open('data/rec_'+type+'.pick', 'r')) # plot_graph(g) gc = gt.giant_component(rg, 'WEAK') comm = gt.fast_community(gc, True) fclus = comm.as_clustering(2) communit_topinflu(fclus, 'weight')