简体   繁体   English

从 Sklearn 获得训练和测试集后,如何将 model 放入 Keras

[英]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.

相关问题 Keras:使用 model.fit() 混洗数据不会产生变化,但 sklearn.train_test_split() 会产生变化 - Keras: Shuffling data using model.fit() doesn't make a change but sklearn.train_test_split() does Keras - 如何正确使用 fit() 来训练 model? - Keras - How to properly use fit() to train a model? 在 model.fit() 中调用时,如何修改 train_step 以支持验证集? - How do I modify train_step in order to support a validation set when called in model.fit()? 从 Keras ImageDataGenerator 获取训练测试数据 - Getting train test data from Keras ImageDataGenerator 如何让 Keras 在特定 GPU 上训练模型? - How do I get Keras to train a model on a specific GPU? 如何格式化目标以训练Keras CNN模型? - How do I format my targets to train a Keras CNN model? 如何在 keras 成功训练测试拆分以训练 model - How to succesfuly train test split to train a model at keras 如何使用 sklearn 中的 train_test_split 确保用户和项目同时出现在训练和测试数据集中? - How can I ensure that the users and items appear in both train and test data set with train_test_split in sklearn? 我无法导入 sklearn.model_selection.train_test_split - I cannot import sklearn.model_selection.train_test_split 从 sklearn.model_selection 导入 train_test_split 时,为什么我收到错误“AttributeError: module 'attr' has no attribute 's'”? - While importing train_test_split from from sklearn.model_selection, why am I getting the error "AttributeError: module 'attr' has no attribute 's'"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM