Alex Rika
Alex Rika

Reputation: 25

How to succesfuly train test split to train a model at keras

Im pretty new to keras so i've been struggling for a while to figure out how I should train - test split my data.

So my plan is to do sentiment analysis and here is my data:

df1
Columns: Sentence , Emotion, BackendSum
         bla1...    0-6      tensor(float32)
         bla2...    0-6      tensor(float32)

Where emotion 0-6 are the emotions (Fear, anger etc.. ) Which I transformed to numbers

And I have another data set which has text and backend sum and I want to classify the emotion of it:

df2
Columns: Sentence, BackendSum
         fla1...   tensor(float32)
         fla2...   tensor(float32)

inputs = keras.Input(shape=(300,))
x = layers.Dense(100, activation="relu", name="dense_1")(inputs)
x = layers.Dense(200, activation="relu", name="dense_2")(x)
outputs = layers.Dense(6, activation="sigmoid", name="predictions")(x)
model = keras.Model(inputs=inputs, outputs=outputs)




model.fit(xtrain, ytrain,
         validation_data=(xtest,ytest),
         epochs = 200,
         batch_size=50)

What is the correct way to fit my model? And to split my data so that I can train on df1 and test on df2

Upvotes: 0

Views: 159

Answers (1)

Aagam Sheth
Aagam Sheth

Reputation: 691

You can use sklearn.

  x_train, x_test, y_train, y_test = sklearn.model_selection.train_test_split(x, y, test_size=0.1)

x are the 2d ndarray of the features, y are the 2d ndarray of the labels and test_size is the size of the data to be split in percentages (0.1 = 10%).

Upvotes: 1

Related Questions