DSX中的Tensorflow:由于list()导致消费预测结果失败

时间:2017-11-07 13:28:59

标签: python tensorflow data-science-experience

我已经在IBM Data Science Experience中使用Python中的Tensorflow成功构建了一个模型。它用于使用此模型评估测试数据。但是,当我调用它来对记录进行预测时,我无法使用评估返回的结果。我按照https://www.tensorflow.org/get_started/input_fn中的描述并使用list():

predict_input_fn = tf.estimator.inputs.pandas_input_fn(
    x={"x": x_pandas_predict_data},
    num_epochs=1,
    shuffle=False)

y = m.predict(input_fn=predict_input_fn)
predictions = list(p["predictions"] for p in itertools.islice(y, 6))
print("Predictions: {}".format(str(predictions)))

我得到的错误如下:

TypeErrorTraceback (most recent call last)
       <ipython-input-49-49a72bc2fad0> in <module>()
     15 # .predict() returns an iterator of dicts; convert to a list    and print
     16 # predictions
---> 17 predictions = list(p["predictions"] for p in itertools.islice(y, 6))
     18 print("Predictions: {}".format(str(predictions)))

  TypeError: 'list' object is not callable

我该如何解决这个问题?

非常感谢。

约翰

1 个答案:

答案 0 :(得分:2)

看起来你有一个名为list的变量,它隐藏了标准的python类型list