Skip to main content
 首页 » 编程设计

python之DSX : Consuming prediction results fails due to list() 中的 Tensorflow

2024年10月01日31落叶

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

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 

我该如何解决这个问题?

非常感谢。

约翰内斯

请您参考如下方法:

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