python - Tensorflow DNNRegressor predict_score output -
i trying run dnnregressor on simple data can test accuracy, model should take bank transaction , try predict price, getting weird results think result of wrong code.
my code here:
from __future__ import print_function __future__ import division __future__ import absolute_import import itertools import pandas pd import numpy np import tensorflow tf print('running version of tensorflow') print(tf.__version__) tf.logging.set_verbosity(tf.logging.debug) names = [ 'trans', 'price', ] predict_names = [ 'trans' ] dtypes = { 'trans': str, 'price': np.float32, } df = pd.read_csv('simple.csv', names=names, dtype=dtypes, na_values='?') # split data training set , eval set. training_data = df[:50] eval_data = df[50:] print("training :\n") print(training_data) # separate input features labels training_label = training_data.pop('price') eval_label = eval_data.pop('price') # feature columns training_input_fn = tf.estimator.inputs.pandas_input_fn(x=training_data, y=training_label, batch_size=1, shuffle=true, num_epochs=none) eval_input_fn = tf.estimator.inputs.pandas_input_fn(x=eval_data, y=eval_label, batch_size=1, shuffle=false, num_epochs=none) #embed column since string transformed_trans = tf.feature_column.categorical_column_with_hash_bucket('trans', 50) print("transformed words **********************") print(transformed_trans) dnn_features = [tf.feature_column.indicator_column(transformed_trans)] # regressor = tf.contrib.learn.linearregressor(feature_columns=[trans]) dnnregressor = tf.contrib.learn.dnnregressor(feature_columns=dnn_features, hidden_units=[50, 30, 10]) #train model dnnregressor.fit(input_fn=training_input_fn, steps=1) # evaluate trianing dnnregressor.evaluate(input_fn=eval_input_fn, steps=1) # predictions predictdf = pd.read_csv('simple_predict.csv', names=names, dtype=dtypes, na_values='?') predict_input_fn = tf.estimator.inputs.pandas_input_fn(x=predictdf,shuffle=false, num_epochs=1) print("predicting scores **********************") y = dnnregressor.predict_scores(input_fn=predict_input_fn) x in y: print(str(x)+"\n")
my data looks
simple.csv: uber,4 food,12 coffee,4 cafe,10 coffee,4 cafe,10 uber,4 food,12 coffee,4 cafe,10 coffee,4 cafe,10 uber,4 food,12 coffee,4 cafe,10 coffee,4 simple_predict.csv: uber food
i assume following data set predictable 0 loss , predictions on point. not case @ all, getting prediction uber , food same , cannot understand results im getting.
am missing in code? or have miss understood how dnnregressor should work anyways?
the problem above code hashing rate low. bumping hashing rate 300 rather 50 work.
transformed_trans = tf.feature_column.categorical_column_with_hash_bucket('trans', 300)
Comments
Post a Comment