, (包含类型的值,python,tensorflow,keras,nlp,lstm"/>

首页 > 解决方案 > 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'>"})

有人可以告诉我出了什么问题以及如何解决吗?

标签: pythontensorflowkerasnlplstm

解决方案


推荐阅读