cliffgao的个人博客分享 http://blog.sciencenet.cn/u/cliffgao 兴趣:生物信息学、统计、概率

博文

keras validation n-fold cross validation

已有 3413 次阅读 2019-12-30 16:10 |个人分类:Machine Learning|系统分类:科研笔记

参考:  https://machinelearningmastery.com/evaluate-performance-deep-learning-models-keras/



(1)一种自动划分  训练集、验证集

# Fit the model

model.fit(X, Y, validation_split=0.33, epochs=150, batch_size=10)


(2)还有一种情况,自己手动设置验证集

# Fit the model

model.fit(X_train, y_train, validation_data=(X_test,y_test), epochs=150, batch_size=10)

(3) n-fold cross validation  

原博客提到,一般深度学习模型,不太经常使用 n-fold cross validation。 主要是因为计算量太大。当然,如果数据比较小,可以使用n-fold cv。先计算每个fold的评估值,然后再计算平均值。

### 在分n-fold的时候,可以尝试sklearn自带的一些函数。例如stratifiedKFold  (from sklearn.model_selection import StratifiedKFold)



for train, test in kfold.split(X, Y):

    # create model

    # Compile model

    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

    # Fit the model

    model.fit(X[train], Y[train], epochs=150, batch_size=10, verbose=0)

    # evaluate the model

    scores = model.evaluate(X[test], Y[test], verbose=0)

    print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))

cvscores.append(scores[1] * 100)

print("%.2f%% (+/- %.2f%%)" % (numpy.mean(cvscores), numpy.std(cvscores)))




https://wap.sciencenet.cn/blog-468005-1212059.html

上一篇:Ubuntu 修改python3为默认的python
下一篇:生存分析中 摘记
收藏 IP: 202.113.19.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-30 08:29

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部