繁体   English   中英

如何在 keras 成功训练测试拆分以训练 model

[英]How to succesfuly train test split to train a model at keras

我对 keras 很陌生,所以我一直在努力弄清楚我应该如何训练 - 测试拆分我的数据。

所以我的计划是做情绪分析,这是我的数据:

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

其中情绪 0-6 是我将其转换为数字的情绪(恐惧、愤怒等)

我有另一个包含文本和后端总和的数据集,我想对它的情绪进行分类:

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)

安装我的 model 的正确方法是什么? 并拆分我的数据,以便我可以在 df1 上进行训练并在 df2 上进行测试

您可以使用 sklearn。

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

x 是特征的 2d ndarray,y 是标签的 2d ndarray,test_size 是要拆分的数据的大小百分比(0.1 = 10%)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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