def hypothesis(self,x,theta):
l_theta = []
for i in range(len(theta)):
thetaX = x.dot(theta[i]) ## wx ##
thetaX_exp = np.exp(thetaX) ## exp(wx)##
if np.isinf(thetaX_exp):
print "overflow"
###prova a mettere una matrice con probabilita tutte uguali in caso di overflow
l_theta.append(thetaX_exp)
l_theta = np.array(l_theta)
thetaX_exp_sum = np.sum(l_theta) ## sum of exp(wx) ##
p = l_theta.T / thetaX_exp_sum ## 5xlen(x) predicted results ##
#print np.sum(p)
'''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
## Calcolo la Derivata della Funzione di Costo ##
LogisticRegression.py 文件源码
python
阅读 40
收藏 0
点赞 0
评论 0
评论列表
文章目录