tensorflow - Mnist 数据集拆分
问题描述
任何人都可以帮助我按照我们希望的比率将 mnist 数据集拆分为训练、测试和验证。
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
使用 70-20-10 拆分进行培训、验证和测试。
解决方案
这种方法应该可以做到。它基本上迭代地使用train_test_split
来自 tensorflow 的函数将数据集拆分为验证测试训练:
train_ratio = 0.70
validation_ratio = 0.20
test_ratio = 0.10
# train is now 70% of the entire data set
# the _junk suffix means that we drop that variable completely
x_train, x_test, y_train, y_test = train_test_split(dataX, dataY, test_size=1 - train_ratio)
# test is now 10% of the initial data set
# validation is now 20% of the initial data set
x_val, x_test, y_val, y_test = train_test_split(x_test, y_test, test_size=test_ratio/(test_ratio + validation_ratio))
推荐阅读
- javascript - 如何从类外访问类内的方法
- css - Text input to have whatever left as width
- javascript - Java脚本键值对到对象
- reactjs - 如何在 React.js 中访问其中的集合和文档?
- php - 如何在基于 PHP 的 CRUD 应用程序中编辑表单时修复“If(isset($_POST['Id'])) 错误”?
- c# - iOS WebGL 上的 Unity 视频播放器
- algorithm - 在矩形 Young Tableau 中搜索元素的高效算法
- reactjs - 如何在 React 中将数组推送到状态?获取“传播不可迭代实例的无效尝试”
- c# - MongoDB HashTable 平均值
- android - 如何为 WorkManager 和 LocationServices 获得正确的依赖关系?