You are on page 1of 2

wine_data2.

py
import pandas as pd
import tensorflow as tf

def load_data(y_name, data_file_train, data_file_eval):


"""Returns the iris dataset as (train_x, train_y), (test_x, test_y)."""
return (train_x, train_y), (test_x, test_y)

def train_input_fn(features, labels, batch_size):


"""An input function for training"""
# Convert the inputs to a Dataset.
return dataset

def eval_input_fn(features, labels, batch_size):


"""An input function for evaluation or prediction"""
return dataset

def _parse_line(line):
# Decode the line into its fields
return features, label

def csv_input_fn(csv_path, batch_size):


# Create a dataset containing the text lines.
return dataset

create_train_test2.py
import sys
import random

with open('winequality-red_train.data', 'w') as train:


for line in data[:1199]:
train.write(line + '\n')
with open('winequality-red_test.data', 'w') as test:
for line in data[1199:]:
test.write(line + '\n')
custom_estimator2.py
"""An Example of a custom Estimator for the Iris dataset."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import shutil
import sys
import tensorflow as tf
import wine_data2

parser = argparse.ArgumentParser():
'Base directory for the model.',
'Number of training epochs.',
'The number of training epochs to run between evaluations.',
'Number of examples per batch.',
'Path to the training data.',
'Path to the test data.'

def my_model(features, labels, mode, params):


"""DNN with three hidden layers, and dropout of 0.1 probability."""
if mode == tf.estimator.ModeKeys.PREDICT
if mode == tf.estimator.ModeKeys.EVAL
assert mode == tf.estimator.ModeKeys.TRAIN

optimizer = tf.train.AdagradOptimizer(learning_rate=0.01)
train_op = optimizer.minimize(loss, global_step=tf.train.get_global_step())
return tf.estimator.EstimatorSpec(mode, loss=loss, train_op=train_op)

def main(argv):
args = parser.parse_args(argv[1:])
# Fetch the data
(train_x, train_y), (test_x, test_y) = wine_data2.load_data('quality',
FLAGS.train_data, FLAGS.test_data)

classifier = tf.estimator.Estimator
# Train the Model.
# Evaluate the model.
# Generate predictions from the model
confusion_matrix = tf.confusion_matrix(test_y, p_classes)

if __name__ == '__main__':
tf.logging.set_verbosity(tf.logging.INFO)
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)

You might also like