iit-cs579 / main Goto Github PK
View Code? Open in Web Editor NEWCS579: Online Social Network Analysis at the Illinois Institute of Technology
CS579: Online Social Network Analysis at the Illinois Institute of Technology
Hi,
I am getting a Twitter Request Error : Twitter Request Failed error when giving higher counts like 200. For smaller counts, I am getting the output. Is this because of any connectivity problem to the Twitter or some issue with the code? Is there any way I can get rid of this error?
Thank You
republicans = [c[0] for c in candidates if c[1] == 'R']
democrats = [c[0] for c in candidates if c[1] == 'D']
print('%d republicans, %d democrats' % (len(republicans), len(democrats)))
This doesnt work for me.
c[0] loops through each elem of the string and not each candidate. For example, [c[0] for c in candidates if c[1] == 'R'] processes the elements as follows:
H
I
L
A
R
Y
C
L
I
N
T
O
N
....
I get the correct output for this code after modifying it as follows:
republicans = [c.split(' ')[0] for c in candidates if c.split(' ')[1] == 'R']
democrats = [c.split(' ')[0] for c in candidates if c.split(' ')[1] == 'D']
print('%d republicans, %d democrats' % (len(republicans), len(democrats)))
similarly for the code:
candidate2friends = get_all_friends(c[0] for c in candidates) I had to change it to--
candidate2friends = get_all_friends(c.split(' ')[0] for c in candidates)
Is this fine?
would someone want to compare their output to this call? I would like to compare and see if I am getting the same thing. Its a bit different from the professor's output and I know this is expected because data changes. For this reason, I would like to compare with someone else who has a recent result for the output of this function.
Hi Professor,
Please could you provide us extension of a day or two to submit the code for our project? We shall do the presentation on December 3 as allotted to us.
Thank you.
Is there a good way to see git diffs between commits when using an ipython notebook? It picks up a lot of metadata changes. And there is a lot of json that contains the code. A quick google search revealed a couple tools, but I'm wondering if you have any suggestions? Or if you would be opposed to us writing code in a separate file and placing the proper calls in the notebook?
For assignment 2, there is a question confused me that in the "path_of_length(graph, source, target, length)โ function, we just need to find one path that satisfy this condition or all the paths? Thanks!
Just one path is fine.
-Aron
A student writes:
For every request, you get 20 friends for a given candidate. Since we have fifteen candidates and we're trying to get 200 friends, we're going to have to make 10 requests for each candidate. This amounts to 150 requests, Twitter I thought is going to time us out at 30 requests within a 15 minute window, how are we supposed to get 200 friends?
See the count
parameter of the API request.
I am getting the following error when I try to run ipython:
[W 12:25:40.027 NotebookApp] 400 GET /api/contents/a1.ipynb?type=notebook&_=1441128339659 (127.0.0.1) 3.34ms referer=http://localhost:8888/notebooks/a1.ipynb
Is anybody else getting the same error?
def distance(graph):
""" Return a list containing the average shortest path to all other nodes for each node in the graph. """
None
For example we have senators A,B,C
The shortest distance between A, B and A C is
{A,[{B:2},{C:3}]}
The shortest distance between B, A and B C is
{B,[{A:4},{C:3}]}
The shortest distance between C, A and C B is
{C,[{A:5},{B:6}]}
So the list should be:
{ {A,[{B:2},{C:3}]},{B,[{A:4},{C:3}]},{C,[{A:5},{B:6}]}}
am I right?
Hi,
The twitter api call for friends/list returns result as a class
this class contains attribute text which contains the raw data in unicode format
when i simply print it shows a dict
but not able to access the elements in it
it says " TypeError: string indices must be integers "
so when i look at the type it says unicode
so how to convert to dict or is there any other way to access it
Do we have options for choosing APIs other than social networks?
For example airlines APIs (tourists interests), museum APIs, etc...
Sorry, I am a little confused, are we doing our coding inside the python notebook?
Dear Aron,
I have read the issue related to this in GitHub but my issue seems quite different from that one.
If I hard code my twitter credentials(keys) in twitter_request method. My entire code is working fine.
But if use twitter.cfg file I am facing issue in my get_friends() method like below:
C:\Users\dell\Anaconda\lib\site-packages\TwitterAPI\TwitterAPI.pyc in iter(self)
177 :raises: TwitterConnectionError, TwitterRequestError
178 """
--> 179 return self.get_iterator()
180
181 def get_rest_quota(self):
C:\Users\dell\Anaconda\lib\site-packages\TwitterAPI\TwitterAPI.pyc in get_iterator(self)
164 """
165 if self.response.status_code != 200:
--> 166 raise TwitterRequestError(self.response.status_code)
167
168 if self.stream:
TwitterRequestError: Twitter request failed (401)
When I reviewed this error, it looks like Unauthorized access or Time zone issue.
But if it is Unauthorized access, then it should not work if I hard code my values. My time zone is correct. I have cross verified it.
Please let me know what can be done to resolve this.
Hi Professor,
I am using Ubuntu +pyCharm in my computer.
I have already insall TwitterAPI "pip install networks TwitterAPI".
And I input moudle use the method in "http://stackoverflow.com/questions/19885821/how-do-i-import-modules-in-pycharm"
However, It still has error when I use TwitterAPI
I was stucked by this problem several days.
Do you know what the reason?
Thanks
A student writes:
I have finished the TODO list till graph creation. Do we have to modify the graph to make it resemble like the one displayed in the main repository?
In the main repository, more candidates are near the outer end of the graph. In my case, white nodes are outside of candidates.
The exact layout may be slightly different, but all the nodes and edges should be the same. That is, you don't need to modify the draw_network
method.
A student writes:
"I started working on the first homework and have had a question regarding Twitter application. It looks like that I should have to create an application to go to next step, Generating Tokens.
There are several blanks, Name, Description, and Website, that I have to fill out, but I have no idea what is typed in to 'Website' blank. It will be great if you give me an advice for the 'Description' as well."
As the instruction says, "A function that takes a graph as input and returns a list of values to be plotted."
I want to use a if-elif structure for the plot_property_histogram() ,because there are three different functions.
for example
pseudocode:
if property_fn == degree:
use plot_degree_dist()
elif property_fn == clustering_coef:
use plot_clustering_dist()
elif property_fn == distance:
use plot_shortest_paths_dist(G, title)
So I'm wondering if I make a mistake about the if-elif method?
And how to use variable to represents a function ?
I am trying to get the latest version of my private repository, i.e. a2 files. I used the command:
git pull
and I get Already up-to-date.. However, when I check the a2 folder the only file there is README.md and the other files are not there. I am on the master branch. Also, I tried git fetch
with no luck.
If I check the repository online I am able to see all files and folders e.g. a2.ipynb. I tried pulling the repository using a different machine but I get the same results.
Any suggestions?
I used the function which professor showed in the lecture
nx.random_regular_graph(k,n)
k : degree
n: number of node
but I haven't found a way to control the numerical order of the neighbors of nodes.
Does anyone know how to control? Or give me some tips?
Hi Professor,
Can you upload the lecture 16,18,20.
I can't find it from github. But I think they are very useful for learning social network and prepareing the final.
Thank you
I am getting a slightly different network each time I run the network module. Is it supposed to be like that?
Also in my network the edges aren't seen clearly! like the one in ideal output(rather cannot be seen atall)
PS: the previous output of graph module is- "graph has 129 nodes and 274 edges" is satisfied. But the network still does not show edges.
Did anyone face same problem?
I guess I am doing something wrong but not sure what it is,
I reviewed lecture 04 and when running the code nothing happened (no plot),
Any thoughts?
I've tried to get friend list. I can connect the API. But I found there is an error: {"errors":[{"message":"Could not authenticate you","code":32}]}. At first, I thought is the problem of my consumer_key. I have checked it and even regenerated it. It still had this problem. I even tried the "follower" example from the l02. And it also had error. Does anyone else can help me fix it? Thanks!
I am using logisticRegression model for my project , my code is as folows,i don't know why every time after do it there is an error: "ValueError: setting an array element with a sequence."
I don't know why?
from sklearn.linear_model import LogisticRegression
trainX= [['39', 'State-gov', '77516', 'Bachelors', '13', 'Never-married', 'Adm-clerical', 'Not-in-family', 'White', 'Male', '2174', '0', '40', 'United-States'], ['50', 'Self-emp-not-inc', '83311', 'Bachelors', '13', 'Married-civ-spouse', 'Exec-managerial', 'Husband', 'White', 'Male', '0', '0', '13', 'United-States']]
model = LogisticRegression()
trainY=['<=50K', '<=50K']
model.fit(dataX,dataY)
Dose anybody know what is a negative cross validation accuracy mean in linear regression model? We are fitting our data to sklearn linear regression model and get a negative accuracy which really make me confused.
Hi,
While trying to fetch friends for candidates mentioned in asg1 there are some candidates whose number of friends are not matching with the assignment results. For e.g. "HillaryClinton" has 142 friends as mentioned in asg1, however, on twitter it shows that she has 159 friends (screensot attached) also the twitter API returns 159 results.
The reason for this may be, that, additional friends were added to her list after the results for asg1 were posted.
In such cases, should we filter the results returned from twitter API until the date asg1 was given so should we go ahead and get all the current results till date?
Graph does not open beneath the code. It opens on a new window only if I write plt.show(). Is this fine?
connection has been established. last night i was getting my status code 200 and all queries were working completely fine. Now it is 200. What is the reason for that?
This is a similar questions to #47, regarding the network changing every time you run the code.
I have drawn a graph that seems very close to the example in the sample code. But if I run the code again by creating a new graph and drawing it, the orientation of the nodes and edges changes slightly. I am using a digraph, so the resolution from #47 does not apply to my question.
All of these graphs have the same number of nodes and edges, but as you can see they look different. Is this behavior expected? Or is there a better way to create the graph that will result in it being drawn consistently each time?
I am trying to experiment with the a1.ipynb file in the ipython notebook, but I am having trouble connecting to Twitter. I keep getting a "NoSectionError" when I try to run the get_twitter method, which I assume means it cannot find the twitter.cfg file. (I already edited my twitter.cfg file with the relevant information). Where do I need to put twitter.cfg so it can be found by the notebook (or what else might I be doing wrong)?
Here is a screenshot with the error:
Thanks for any suggestions!
Ryan
for plot_p_effect function .. we also need to call clustering_coef and distance right ? these functions returns a list ... should i take mean of it?
There are some codes in homework 2:
def degree(graph):
""" Return a list containing the degree for each node in the graph. """
return None
def clustering_coef(graph):
""" Return a list containing the clustering coefficient for each node in the graph. """
return None
def distance(graph):
""" Return a list containing the average shortest path to all other nodes for each node in the graph. """
return None
We can get some of them results by using networkx.some_function()
. Can I use these functions or I should follow the definitions and implement them by myself?
It gives me the error: "Go Away!"
Hi,
The output graph given for our reference has changed.
McConnellPress node has no connection before but now there is a edge between
McConnellPress and kaybaileyhutch .
I searched though twitter and the relation do exists between those two nodes.
Any one getting result as me or am i doing something wrong?
I am using to implement this, a function called nx.all_simple_paths()
, however it seems that this function return an infinite number of paths !!
How to avoid that?
import ConfigParser
import sys
import time
import matplotlib.pyplot as plt
import networkx as nx
import json
from networkx.algorithms import bipartite
def create_graph(dots):
G= nx.Graph()
G.add_nodes_from(dots)
return G
dots=["ab","cd","ef"]
graph = create_graph(dots)
nx.draw(graph,with_labels=True)
plt.savefig("p1.png")
graph.clear()
graph = nx.DiGraph()
print graph.nodes()
nx.draw(graph,with_labels=True)
plt.savefig("p2.png")
In my code I try to draw two pictures:p1.png and p2.png. After I draw p1.png , I clear graph. However, p2.png has the same node with p1.png.
I don't know what's wrong with my code . Because I have clear graph, so there should be nothing in p2.png
I google it ,but no answer. What is the problem?
I looked the NetworkX documentation, there is a function used for computing betweenness centrality for nodes in a bipartite network.
betweenness_centrality(G, nodes)
Parameters :
G : graph
A bipartite graph
nodes : list or container
Container with all nodes in one bipartite node set.
Returns :
betweenness : dictionary
Dictionary keyed by node with bipartite betweenness centrality as the value.
I have tried to used it, but it shows a Name Error as follow:
Do I need to import extra library to let it work? Or I just choose an inappropriate function?
A student writes:
You have listed four arguments in the documentation to score_republicans(), but I only see three passed in. That should change to four, correct?
In fact there should only be three parameters. The code is correct, but the documentation is not.
I've updated a1.ipynb to fix this (see commit 6381616 )
Hi, all, I got this error when I was trying to get all the friends for all candidates:
TwitterConnectionError: HTTPSConnectionPool(host='api.twitter.com', port=443): Read timed out.
it's totally fine when I got friends for one candidate.
whenever i am clicking on the ipython notebook launcher , it redirects me to http://localhost:8889/tree , but all the browsers show me the webpage in an improper format . kindly refer the screenshot , what should i do to display the webpage in the proper format.
Did you mean to tell us to name the codecademy screen shot in assignment 1 python.pdf? I tried to save my codecademy screenshot as a PDF, but after I did I couldn't open it because OSX thought it was corrupt. Is it OK to submit a PNG instead? In my experience screenshots aren't usually saved as PDF, but if there's a reason to do it that way, I'd like to know.
Does any group of two still need another member to join their project team? I would like to join one! Thanks!
for this function, are we supposed to return a list with all the user's friend's name or screen name?
In class, I called:
nx.draw(graph)
and this drew the graph with labels. When the students run this code, they don't see any labels.
The real-time plotting (using networkx) doesn't seem to be working.
Here's my code:
def create_graph(senators):
for i in senators:
graph.add_node(i)
return graph
graph = nx.DiGraph()
graph = create_graph(senators)
nx.draw(graph, with_labels = True)
plt.savefig("senators.png")
The output graph that I get is as follows:
However if I replace 'senators' in the for loop with 'len(senators)', then I obtain the proper graph, only not with the desired labels (the senator names):
Any help on why I'm not getting the expected graph in the first instance? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.