manage.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:sentiment-analysis 作者: kasheemlew 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号