ValueError: shapes (1,3) and (100,1) not aligned: 3 (dim 1) != 100 (dim 0)
出现这个错误,是你数据的维度不对!这个问题是出现在写logistic Regression 代码时出现的`
#用scipy中truncated newton(TNC)实现寻找最优参数
import scipy.optimize as opt
result = opt.fmin_tnc(func=cost, x0=theta.reshape(-1),fprime=gradient,args=(X,y))
result
紧接着报错
后来在我仔细检查的情况下,发现原先写的损失函数cost()中,参数的位置错了,导致后来程序的错误,在写梯度下降函数时,以及损失函数时,要把theta放到前面
def cost(theta, X, y):
def gradient(theta, X, y):
这样问题就可以解决了!