我最近找到了可以找到here的脚本,我已经对其进行了尝试,但是它显示了[TICKER] has not been predicted.
,因此,我深入研究了代码,并找到了一些对我有帮助的代码:
for i in stock_list:
print("Number: " + str(number))
try:
predictData(i, 5)
except:
print("Stock: " + i + " was not predicted")
number += 1
然后我将其注释掉,以查看导致它无法预测的原因。这就是我从中得到的:
Number: 0
AKS
Traceback (most recent call last):
File "finance.py", line 104, in <module>
getStocks(200)
File "finance.py", line 34, in getStocks
predictData(i, 5)
File "finance.py", line 86, in predictData
X, Y, test_size=0.5)
ValueError: too many values to unpack (expected 3)
啊哈!因此,成为b * tch的一小段代码是这样的:
X = np.array(df.drop(['prediction'], 1))
Y = np.array(df['prediction'])
X = preprocessing.scale(X)
X_prediction = X[-forecast_time:]
X_train, Y_train, Y_test = model_selection.train_test_split(
X, Y, test_size=0.5)
我认为这不起作用的原因是
X_train, Y_train, Y_test = model_selection.train_test_split(
X, Y, test_size=0.5)
给出了4个输出,但是只有3个变量。我不知道该怎么办,因为我尝试向其中添加另一个变量,但得到了这个:TypeError: only size-1 arrays can be converted to Python scalars
...
叹气
答案 0 :(得分:1)
model_selection.train_test_split(...)
和cross_validation.train_test_split(...)
返回偶数个数组(实际上,它是原始数组的2 *)。如此说来,您正在输入X和Y数组,因此您应该期望输出包含4个数组。尝试更改您的代码以阅读
X_train, X_test, Y_train, Y_test = model_selection.train_test_split(X, Y, test_size = 0.5)
如果您说在第4个变量中输入错误,我们可以看到回溯吗?我怀疑它不在同一行上,但是我现在无法运行代码,所以我自己不能这样做