【问题标题】:How do I export the machine learning (Tensorflow) predictions to a csv file?如何将机器学习 (Tensorflow) 预测导出到 csv 文件?
【发布时间】:2018-02-04 05:58:09
【问题描述】:

我已将我的代码 here 包含在 google 文档中。

我无法将作为输出打印的预测值导出到 csv 文件。

for i in range(0, 101):
prediction_run = sess.run(prediction, feed_dict={x: X[i].reshape(1, 60)})
accuracy_run = sess.run(accuracy, feed_dict={x: X[i].reshape(1, 60), y_: Y[i].reshape(1, 2)})
print("Original Class : ", y1[i], " Predicted Values : ", prediction_run[0], " Accuracy : ", accuracy_run)

【问题讨论】:

  • 导出时遇到什么错误?这样问题就更清楚了
  • 我正在使用pandas将其导出为csv,我猜问题是数据类型不匹配。
  • 请不要猜测问题,而是在您的问题中包含相关且完整的错误消息。
  • 我在谷歌文档中包含的代码完全没有错误。我无法将打印到 csv 的结果导出。我正在寻找的是可用于执行此操作的代码段。

标签: python pandas machine-learning tensorflow data-analysis


【解决方案1】:

查看您的代码,您根本没有使用 pandas 将其导出到 csv。你可以这样做:

import pandas as pd

prediction_value = sess.run(prediction, feed_dict={x: x_test}
prediction_df = pd.DataFrame(prediction_value)
prediction_df.to_csv('prediction.csv')

顺便说一句,下次最好将您的代码放在 gist 上,而不是放在 Google 驱动器中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-08
    • 2020-05-06
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多