0
DNNRegressorをいくつかの単純なデータで実行しようとしているため、正確性をテストできます。モデルは銀行取引を行い、その価格を予測する必要がありますが、私は思ったほど奇妙な結果を得ていますコードに何らかの問題が生じた場合。Tensorflow DNNRegressor predict_score出力
私のコードはここにある:
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import itertools
import pandas as pd
import numpy as np
import tensorflow as 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 the data into a training set and an eval set.
training_data = df[:50]
eval_data = df[50:]
print("Training with this :\n")
print(training_data)
# Separate input features from 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 the column since its a 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 the model
dnnregressor.fit(input_fn=training_input_fn, steps=1)
# Evaluate the 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)
for x in y:
print(str(x)+"\n")
私のデータは、この
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
のように見える私はかなり予測され、次のデータセットで私は0の損失を取得するとの予測がすることを前提としていますポイント上にある。 しかし、まったくそうではなく、まったく同じUberとFoodの予測をいつも得ているし、私が得た結果も理解できない。
コードに何も表示されていませんか?とにかくDNNRegressorがどのように動作すべきか理解できなかったのですか?
ハッシュの問題がありますか?たぶん 'categorical_column_with_vocabulary_list'と' embedding_column'を試してみませんか? –