def get_emotion():
print "Calculating thetas..."
get_theta()
print "Done!"
comments = Comment.query.filter_by(emotion=-1).all()
for comment in comments:
x = [1, float(comment.pos_count), float(comment.neg_count)]
hypothesis = 0
feature_sum = 0
for i in range(3):
feature_sum += theta[i]*x[i]
hypothesis = 1 / (1+math.e**-(feature_sum))
if 0 < hypothesis < 0.4:
comment.analysis_score = 0
elif 0.4 <= hypothesis < 0.6:
comment.analysis_score = 0.5
elif 0.6 <= hypothesis < 1:
comment.analysis_score = 1
评论列表
文章目录