我在x_data中有一个3x2000的numpy数组,在y_data中有一个1x2000的numpy数组,我通过这个函数回归给我一个回归线。它工作正常。问题是我正在尝试做一些回测试,并且测试1000次我不得不倒退1000次,并且需要大约5分钟来运行。Python fmin太慢
我试图标准化变量,它似乎没有让它变得更快。
我还简要地尝试了fmin_powell和fmin_bfgs,它似乎打破了它。
有什么想法?谢谢!
def regress(x_data, y_data, fg_spread, fg_line):
theta = np.matrix(np.ones((1,x_data.shape[0]))*.11)
hyp = lambda theta, x: 1/(1 + np.exp(-(theta*x)))
cost_hyp = lambda theta, x, y: ((np.multiply(-y,np.log10(hyp(theta,x)))) - \
(np.multiply((1-y),(np.log10(1-hyp(theta, x)))))).sum()
theta = scipy.optimize.fmin(cost_hyp, theta, args=(x_data,y_data), xtol=.00001, disp=0)
return hyp(np.matrix(theta),np.matrix([1,fg_spread, fg_line]).reshape(3,1))
注意添加并保存分钟在那一点上? –
五分钟不一定很长;这真的是相对的(只是你需要喝杯咖啡的时间)。另外,您将xtol设置为低10倍;这可能会减慢速度。在这种情况下,“打破它”是什么意思?因为我猜这些可能会稍微快一点。 – Evert
乔兰,你能解释一下你的意思吗?感谢 – appleLover