我想找到最小的函数值scipy.optimize.minimize_scalar
功能:
def error(w0, w1):
dataset = data
total_error = 0
for i in range(1, 25000):
meta = dataset['Height'][i] - ((w0 + w1 * dataset['Weight'][i]))**2
total_error = total_error + meta
return total_error
我想要w0 = 50
并且w1 = [-5,5]
当我试图将函数置于 scipy 方法下时,我看到了不同的错误:
res = minimize_scalar(error)
TypeError: error() missing 1 required positional argument: 'w1'
w0 = 50
w1 = 0
res = minimize_scalar(error (w0, w1))
'numpy.float64' object is not callable
w0 = 50
w1 = range(-5,5)
res = minimize_scalar(error, w0, w1)
TypeError: object of type 'int' has no len()