简体   繁体   中英

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. 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:

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:

model.add(layers.Dense(16, activation = 'relu', input_shape=(5,))) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM