将张量拆分为训练集和测试集 [英] Split tensor into training and test sets

查看:36
本文介绍了将张量拆分为训练集和测试集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我已经使用 TextLineReader 读取了文本文件.有没有办法在 Tensorflow 中将其拆分为训练集和测试集?类似的东西:

Let's say I've read in a textfile using a TextLineReader. Is there some way to split this into train and test sets in Tensorflow? Something like:

def read_my_file_format(filename_queue):
  reader = tf.TextLineReader()
  key, record_string = reader.read(filename_queue)
  raw_features, label = tf.decode_csv(record_string)
  features = some_processing(raw_features)
  features_train, labels_train, features_test, labels_test = tf.train_split(features,
                                                                            labels,
                                                                            frac=.1)
  return features_train, labels_train, features_test, labels_test

推荐答案

类似下面的内容应该可以工作:tf.split_v(tf.random_shuffle(...

Something like the following should work: tf.split_v(tf.random_shuffle(...

对于 tensorflow>0.12 这现在应该被称为 tf.split(tf.random_shuffle(...

For tensorflow>0.12 This should now be called as tf.split(tf.random_shuffle(...

参考

查看tf.splittf.random_shuffle 示例.

这篇关于将张量拆分为训练集和测试集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆