在Python Tensor Flow中打印生成器

我正在尝试按照这个链接中描述的tensor flow教程进行学习。

我试图按照描述打印预测结果:

print ("Predicted %d, Label: %d" % (classifier.predict(test_data[0]), test_labels[0]))

但是我无法打印结果。我遇到了以下错误:

    print ("Predicted %d, Label: %d" % (classifier.predict(test_data[0]), test_labels[0]))TypeError: %d format: a number is required, not generator

如何在python中打印generator

我尝试编写循环并迭代元素,但没有成功。我也尝试使用next来打印生成器,但这也不起作用。我该如何打印它?


回答:

这是我解决问题的方法

new_samples = np.array([test_data[8]], dtype=float)y = list(classifier.predict(new_samples, as_iterable=True))print('Predictions: {}'.format(str(y)))print ("Predicted %s, Label: %d" % (str(y), test_labels[8]))

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注