def get_theta():
import math
theta = [0.0, 0.0, 0.0]
step = 0.01
comments = Comment.query.all()[:100]
print "Comments gotten! Training..."
for m in range(1000):
for comment in comments:
if comment.emotion != -1:
x = [1, float(comment.pos_count), float(comment.neg_count)]
feature_sum = 0
for i in range(3):
feature_sum += theta[i]*x[i]
h = 1 / (1+math.e**-(feature_sum))
for i in range(3):
theta[i] = theta[i] + step*(comment.emotion-h)*x[i]
print "Theta Gotten: ", theta
评论列表
文章目录