def follower_botness(username):
#given a username, it creates the histogram of the botness of the followers
#and saves it in plots (for now) it also returns the probable percentage of follower bots
#(cutoff needs to be defined, for now it is 0.7)"""
cutoff = 0.7
scorelist = []
followers = db.getFollowers(toName=username)
for f in followers:
follower = f['_from'].split('/')[1]
score = db.getUser(follower)['botness']['score']
scorelist.append(score)
if scorelist:
scores = pd.Series(scorelist, name='probability of follower bot')
ax = sns.distplot(scores)
fig = ax.get_figure()
fig.savefig('testfig.png')
botpercent = sum(np.array(scorelist)>cutoff) / len(scorelist)
return botpercent
else:
return None
评论列表
文章目录