使用字符串替换打印时出现语法错误

时间:2018-03-18 11:16:08

标签: python machine-learning syntax

我使用此代码计算我要打印的准确度分数

accuracy = metrics.accuracy_score(predictions,data[outcome])
print "Accuracy :%s" % "{0:.3%}".format(accuracy)

但是当我运行我的代码时,我得到以下错误。

  File "<ipython-input-53-a86f8606658d>", line 19
    print "Accuracy :%s" % "{0:.3%}".format(accuracy)
                       ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:1)

试试这个:

print("Accuracy :{0:.3%}".format(accuracy))

演示:

accuracy = 0.83456789
print("Accuracy :{0:.3%}".format(accuracy))

打印:

Accuracy :83.457%