[英]How do I fit a model in Keras after getting Train and test set from Sklearn
I'm pretty new to machine learning and I am trying to figure out how I would feed in data to a model after I get the train test split from Sklearn.我是机器学习的新手,我想弄清楚在从 Sklearn 进行火车测试拆分后如何将数据输入 model。 Right now this is what I have in the data preparation phase.
现在这就是我在数据准备阶段所拥有的。
x_train, x_test, y_train, y_test =train_test_split(db[predictors], db["default.payment.next.month"], test_size=.2)
x_train= x_train.to_numpy()
x_test = x_test.to_numpy()
y_train = y_train.to_numpy()
y_test = y_test.to_numpy()
I set them all the numpys which I thought was necessary to plug into the model.fit() function. My model.fit() function looks like this:我将它们设置为我认为插入 model.fit() function 所必需的所有 numpy。我的 model.fit() function 看起来像这样:
history = model.fit(x_train,
y_train,
epochs=20,
batch_size=512,
validation_data=(x_val, y_val))
and then I get an error like this:然后我收到这样的错误:
ValueError: Input 0 of layer "sequential_5" is incompatible with the layer: expected shape=(None, 10000), found shape=(None, 5)
Is there something I'm missing or doing wrong?我有什么遗漏或做错了吗?
As error shows, try using input_shape
as below:如错误所示,尝试使用
input_shape
如下:
model.add(layers.Dense(16, activation = 'relu', input_shape=(5,)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.