python - tensorflow 错误:未能找到可以处理输入的数据适配器:, (包含类型的值
问题描述
我是 NLP 的新手,我正试图通过新闻预测股价上涨。我成功地在 ML 中工作,我正在尝试用 LSTM 做同样的工作。
首先,我更改了 LSTM 的数据类型。(我使用 TfidfVectorizer 制作 x_train)
x_train_3d = x_train.toarray()
x_train_3d = x_train_3d.reshape(len(x_train_3d), 1000, 1)
print(x_train_3d.shape)
>> (39809, 1000, 1)
并编译模型。
model = Sequential()
model.add(LSTM(100, activation='relu', return_sequences=False, input_shape=x_train_3d.shape[1:]))
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='Adam', loss='binary_crossentropy', metrics=['accuracy'])
model.summary()
但是当我尝试拟合模型数据时,它不适用于此错误。
history = model.fit(x_train_3d, y_train, batch_size=100, epochs=100, callbacks=[early_stopping, save_best_model])
Failed to find data adapter that can handle input: <class 'numpy.ndarray'>, (<class 'list'> containing values of types {"<class 'numpy.int64'>"})
有人可以告诉我出了什么问题以及如何解决吗?
解决方案
推荐阅读
- html - 如何更改 HTML 符号的颜色?
- python - 理解 Python 中的 for 循环
- .net - x64 应用程序中的 .Net WPF TaskDialog
- c++ - 无法弄清楚为什么我不断收到“未定义的引用”错误
- android - 未经检查的 Cast 警告和 ClassCastException
- python - 如何在pandas中编辑OneHotEncoder的实现过程?
- json - 如何编写 POJO 以使用 Retrofit2 从 JSON 获取对象内的特定数组?
- c++ - 如果文件在c ++中为空,如何抛出异常?
- gravityforms - 如何将 ACF(高级自定义字段)用户数据显示到重力表单?
- php - 学说生成/迁移命令不生成表格