testMovies.py 文件源码

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

项目:software-suite-movie-market-analysis 作者: 93lorenzo 项目源码 文件源码
def hypothesis(self,x,theta):
        l_theta = []
        for i in range(len(theta)):
            #print theta[i]
            thetaX = x.dot(theta[i])#  wx
            thetaX_exp = np.exp(thetaX)  # exp(wx)
            l_theta.append(thetaX_exp)
        l_theta = np.array(l_theta)
        #print np.shape(l_theta)
        thetaX_exp_sum = np.sum(l_theta)  # sum of exp(wx)
        #print thetaX_exp_sum
        p = l_theta.T / thetaX_exp_sum  # 5xlen(x) predicted results
        if np.isinf(p).any():  # deal with overflow in results.
            inf_idx = np.isinf(p)  # idx where overflow occurs
            val = np.sum(p, 0) / np.sum(inf_idx, 0) * inf_idx  # values to be used to substitution
            p[inf_idx] = val[inf_idx]  # substitute values
        return p.T




#### predict the labels for a set of observations ####
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号