我目前正在使用 tf 1.4,我需要帮助查看tf.contrib.factorization.KMeansClustering
估算器的预测。我当前的代码段如下所示:
km = KMeansClustering(num_clusters=8,initial_clusters=KMeansClustering.KMEANS_PLUS_PLUS_INIT,model_dir=MODEL,relative_tolerance=0.01)
result = km.train(input_fn=lambda: gen_input(body))
input_fn = tf.estimator.inputs.pandas_input_fn(x={'x':tst}, shuffle=False)
y = result.predict(input_fn)
其中 body 和 tst 是 pandas 数据帧。print(y)
给出:
<generator object Estimator.predict at 0x11ebecba0>
并尝试我搜索过的东西,比如调用print(list(y))
,print(next(y))
或者遍历 y,比如:
for i in y:
...
for i in y.items():
...
for i in enumerate(y):
...
等,给出错误TypeError: data must be either a numpy array or pandas DataFrame if pandas is installed; got dict
。我找不到任何其他方法可以尝试在线打印。谢谢