Python 如何对单个数据项使用tf.estimator.predict

Python 如何对单个数据项使用tf.estimator.predict,python,tensorflow,prediction,Python,Tensorflow,Prediction,我是tf.estimator的新手,以前使用过旧版本的tensorflow。输入“input_fn”让我有点困惑。我有一个DNNClassifier和一个numpy数组,其中包含一个数据项(x),我想为它预测一个“y”值 这是我目前掌握的代码 dnn_clf = tf.estimator.DNNClassifier(feature_columns=feature_columns, n_classes=14, hidden_units=[60, 100], model_dir="/home/Eho

我是tf.estimator的新手,以前使用过旧版本的tensorflow。输入“input_fn”让我有点困惑。我有一个DNNClassifier和一个numpy数组,其中包含一个数据项(x),我想为它预测一个“y”值

这是我目前掌握的代码

dnn_clf = tf.estimator.DNNClassifier(feature_columns=feature_columns, n_classes=14, hidden_units=[60, 100], model_dir="/home/Ehoward14/mysite/dnn_model")

predict_fn = tf.estimator.inputs.numpy_input_fn(x=scaled_X,
                                                    y=None,
                                                    batch_size=1,
                                                    shuffle=False,
                                                    num_epochs=1)

y_pred = dnn_clf.predict(input_fn=predict_fn)
我想打印单个y值,如下所示:

    //This will only print one value
    for result in y_pred:
            print(result)
scaled_X包含如下内容: [1.42857143 0.0.16.363636 0.1.81818182#012 6.666667 0.2.896 20.0.0.#012 0.20.16.666667 0.]

此代码返回错误:

for result in y_pred:
  File "/usr/lib/python3.6/site- 
packages/tensorflow/python/estimator/estimator.py", line 543, in predict
features, None, model_fn_lib.ModeKeys.PREDICT, self.config)
  File "/usr/lib/python3.6/site- 
packages/tensorflow/python/estimator/estimator.py", line 1133, in _call_model_fn
     model_fn_results = self._model_fn(features=features, **kwargs)
  File "/usr/lib/python3.6/site- 
   packages/tensorflow/python/estimator/canned/dnn.py", line 385, in _model_fn
    batch_norm=batch_norm)
  File "/usr/lib/python3.6/site- 
   packages/tensorflow/python/estimator/canned/dnn.py", line 179, in _dnn_model_fn
    'Given type: {}'.format(type(features)))
    ValueError: features should be a dictionary of `Tensor`s. Given type: <class 'tensorflow.python.framework.ops.Tensor'>
对于y_pred中的结果:
文件“/usr/lib/python3.6/site-
packages/tensorflow/python/estimator/estimator.py”,第543行,预测
功能,无,模型\u fn\u lib.ModeKeys.PREDICT,self.config)
文件“/usr/lib/python3.6/site-
packages/tensorflow/python/estimator/estimator.py”,第1133行,在调用模型fn中
模型\结果=自身。\模型\结果(特征=特征,**kwargs)
文件“/usr/lib/python3.6/site-
packages/tensorflow/python/estimator/canned/dnn.py”,第385行,in_model_fn
批次标准=批次标准)
文件“/usr/lib/python3.6/site-
packages/tensorflow/python/estimator/canted/dnn.py”,第179行,在dnn模型中
'给定类型:{}'。格式(类型(功能)))
ValueError:特征应该是“张量”的字典。给定类型:
事实上,我只需要知道我的方法是否正确,如果不正确,任何改进建议都将不胜感激

提前谢谢