python - Having trouble with stock prediction script in Python
问题描述
I recently found this script that you can find here, and I have tried it out, but it says [TICKER] has not been predicted.
So, I dug into the code, and found a little code that helped me:
for i in stock_list:
print("Number: " + str(number))
try:
predictData(i, 5)
except:
print("Stock: " + i + " was not predicted")
number += 1
I then commented that out to see what was causing it to not predict it. This is what I got out of it:
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)
Aha! So, the little piece of code that was being a b*tch was this:
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)
I think the reason that this was not working is because
X_train, Y_train, Y_test = model_selection.train_test_split(
X, Y, test_size=0.5)
was giving 4 outputs, but there were only 3 variables. I don't know what I should do here, because I tried to add another variable to that, but got this: TypeError: only size-1 arrays can be converted to Python scalars
...
sigh
解决方案
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 个变量时出错,我们可以看到回溯吗?我怀疑它不在同一行但我现在无法运行代码所以我不能自己做
推荐阅读
- c# - 将子级添加到列表中的实体框架性能问题
- dynamics-crm - 无法使用 Web API 删除 Dynamics 365 Appointment 的 aboutobjectid 值
- javascript - 使用 customClaims 列出用户的最佳方式
- angular - 如何使用 Angular 材料 7.1.1 在同一页面上实现多个芯片自动完成?
- python-3.x - 对返回语句感到困惑
- batch-file - CLIP 命令无法正常工作
- memory-leaks - 在 Jest 中调试内存泄漏的步骤是什么?
- sql - phpMy Admin 4.8.4 导出表作为 SQL 丢失
- java - Java - Cassandra 在“IN”中有大量参数
- javascript - 从淘汰赛自定义绑定中访问 select2 HTML 选项以禁用它们