2
$\begingroup$

I am trying to visualize retweet network in order to find out which users are most likely to have most influence on other users. Here is my code:

    import networkx as nx

    G_retweet = nx.from_pandas_edgelist(translated_iranian_tweets,
                                        source = "userid",
                                        target = "retweet_userid",
                                        create_using = nx.DiGraph())

    print('There are {} Nodes inside Retweet Network'.format(len(G_retweet.nodes())))
    print('There are {} Edges inside Retweet Network'.format(len(G_retweet.edges())))

import matplotlib.pyplot as plt

#Size varies by the number of edges the node has (its degree)
sizes = [x[1] for x in G_retweet.degree()]

    nx.draw_networkx(G_retweet,
                     pos = nx.circular_layout(G_retweet),
                     with_labels = False,
                     node_size = sizes,
                     width = 0.1,
                     alpha = 0.7,
                     arrowsize = 2,
                     linewidths = 0)

    plt.axis('off')
    plt.show()

There are 18631 nodes and 35008 edges inside this network. Visualization is horrible, you cannot see anything. Does anyone have any suggestions what should I do about it? Should I try to extract specific type of users with specific tweets in order to reduce size of my dataset and then try to visualize the network, or something else?

enter image description here

$\endgroup$
1
  • $\begingroup$ Can you tell me which dataset you were working on? $\endgroup$
    – Xovee
    Jan 15, 2019 at 10:14

1 Answer 1

3
$\begingroup$

For answering questions from graph, you should not visualize it. Visualizing graphs is for sake of having an overview on how it looks like in general. There are Graph Visualization techniques that show graph for sake of getting some initial insight (e.g. if there are visually obvious communities or not).

Your question has an analytic answer. After constructing your graph object, you can get the adjacency matrix as a Python array or matrix. This matrix will be asymmetric as outgoing and incoming degrees are different of course. In Networkx you can get in-degree and out-degree information as seen below. Then the main story starts!

The most influential of a social network can be seen as the most central node. Centrality measures capture them for you. The simplest one is degree centrality. It simply says the node with highest degree has most influence in graph. In your case be sure how you model "the guy who is retweeted"as he has the most influence. If being retweeted is in-degree in your modeling then this code get them for you:

import networkx as nx
import operator

g=nx.digraph.DiGraph()
g.add_edges_from([(0,1),(1,2),(2,3),(4,2),(4,3)])
dict_deg = {ii:jj for (ii,jj) in g.in_degree}
print('In-Degree Dictionary\n',dict_deg)

m = max(list(dict_deg.values()))
print('The node(s) number',[i for i, j in enumerate(list(dict_deg.values())) if j == m],'have the most influence!')

Output:

In-Degree Dictionary
 {0: 0, 1: 1, 2: 2, 3: 2, 4: 0}
The node(s) number [2, 3] have the most influence!

And the graph itself:

pos = nx.spring_layout(g)
_=nx.draw(g,label=True,pos=pos)
_=nx.draw_networkx_labels(g,pos=pos)

enter image description here

I hope it answered your question. If not please drop a comment so I can update.

$\endgroup$
2
  • $\begingroup$ This is more then I could have asked for! Thank you so much! Although I have a lot of other questions regarding Social Network Analysis. I am not sure how you feel about sparing some time to chat with me about them? Once again, thank you for your effort! $\endgroup$ Nov 6, 2018 at 23:15
  • 1
    $\begingroup$ I am glad it helped :) sure we can keep in touch in Linkedin. You may just google my name. Cheers, $\endgroup$ Nov 7, 2018 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.