【问题标题】:writing training and testing data sets into separate files将训练和测试数据集写入单独的文件
【发布时间】:2021-05-18 18:09:13
【问题描述】:

我正在为我的工作目的训练一个自动编码器神经网络。但是我正在接受 图像 numpy 数组数据集作为输入(总样本 16110),并希望使用以下 autoencoder.fit 命令将数据集拆分为训练集和测试集。此外,在训练网络时,它就像在 12856 个样本上训练一样,在 3254 个样本上进行验证。

但是,我需要将训练和测试数据保存到单独的文件中。我该怎么做?

es=EarlyStopping(monitor='val_loss',mode='min',verbose=1,patience=5)
mc=ModelCheckpoint('best_model.h5',monitor='val_loss',mode='min',save_best_only=True)

history = autoencoder.fit(dataNoise,dataNoise, epochs=30, batch_size=256, shuffle=256,callbacks=[es,mc], validation_split = 0.2)

【问题讨论】:

    标签: python-3.x tensorflow keras


    【解决方案1】:

    您可以使用 sklearn 中的 train_test_split 函数。见下面的代码

    from sklearn.model_selection import train_test_split
    train_split=.9 # set this  as the % you want for training
    train_noise, valid_noise=train_test_split(dataNoise, train_size=train_split, shuffle=True, 
                                              random_state=123)
    

    现在使用训练噪声作为 x,y 和有效噪声作为 model.fit 中的验证数据

    【讨论】:

    • 但是我需要在 keras 中进行操作...请您建议如何操作
    猜你喜欢
    • 2016-01-25
    • 1970-01-01
    • 2019-05-01
    • 2021-04-28
    • 2019-01-14
    • 2017-02-20
    • 1970-01-01
    • 2015-09-15
    • 2021-12-08
    相关资源
    最近更新 更多