谷歌云机器学习引擎(Cloud MLE)实战指南
1. 数据特征与标签生成
在进行机器学习训练或评估时,需要生成特征和标签。以下代码展示了如何使用 TensorFlow 的 Dataset API 来实现这一功能:
import tensorflow as tf
def parse_label_column(features, LABEL_COLUMN):
# 这里假设 parse_label_column 函数用于解析标签列
return features.pop(LABEL_COLUMN)
def input_fn(filenames, num_epochs, batch_size, shuffle=True, skip_header_lines=0, LABEL_COLUMN='label'):
"""Generates features and labels for training or evaluation.
This uses the input pipeline based approach using file name queue
to read data so that entire data is not loaded in memory.
"""
dataset = tf.data.TextLineDataset(filenames).skip(skip_header_lines).map(
_decode_csv)
if shuffle:
dataset = dataset.shuffle(buffer_size=b
超级会员免费看
订阅专栏 解锁全文
15

被折叠的 条评论
为什么被折叠?



