python - How to write the output of data in tensorflow -


i have been following tutorial understand linear classification model , applications. have taken different example outside census data , can accuracy evaluate.

now interested print out rows of test data predicted column values.

https://www.tensorflow.org/tutorials/wide

import random import pandas import tensorflow tf import tempfile import numpy np  df_train = pandas.read_csv('input/train.csv', usecols=['sex', 'age', 'fare','survived', 'sibsp']) df_test = pandas.read_csv('input/test.csv', usecols=['sex', 'age', 'fare', 'sibsp']) df_test['survived'] = 0 categorical_columns = ['sex'] continuous_columns = ['age', 'fare', 'sibsp'] df_train_nona = df_train.dropna() df_test_nona = df_test.dropna() print(df_test_nona) def input_fn(df):     continuous_cols = {k: tf.constant(df[k].values)                        k in continuous_columns}      categorical_cols = {k: tf.sparsetensor(         indices=[[i,0] in range(df[k].size)],         values=df[k].values,         dense_shape=[df[k].size, 1])         k in categorical_columns     }      feature_cols = dict(list(continuous_cols.items()) + list(categorical_cols.items()))      label = tf.constant(df['survived'].values)      return feature_cols, label  def train_input_fn():     return input_fn(df_train_nona)  def eval_input_fn():     return input_fn(df_test_nona)  gender = tf.contrib.layers.sparse_column_with_keys(     column_name='sex', keys=['female', 'male'] )  pclass = tf.contrib.layers.real_valued_column('pclass')  cabin = tf.contrib.layers.sparse_column_with_hash_bucket("cabin", hash_bucket_size=1000)  age = tf.contrib.layers.real_valued_column('age') fare = tf.contrib.layers.real_valued_column('fare') parch = tf.contrib.layers.real_valued_column('parch') sibsp = tf.contrib.layers.real_valued_column('sibsp')  model_dir = tempfile.mkdtemp()  m = tf.contrib.learn.linearclassifier(feature_columns=[gender, age, fare, sibsp], optimizer=tf.train.ftrloptimizer(       learning_rate=0.1,       l1_regularization_strength=0.001     ),model_dir=model_dir)  m.fit(input_fn = train_input_fn, steps=400) 

the best way take input data , run in through network function. believe should sess.run(output_tensor, feed_dict={x: input_data}).


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -