pyspark round函数未按预期工作

y3bcpkx1  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(476)

我用multiclassificationevaluator模块计算了naivebayes模型的精确度,并试图将其四舍五入到小数点后2位。以下是相同的代码:

print("Naive Bayes accuracy is: " + str(round(rf_accuracy,2)))

但我面临以下问题:
typeerror traceback(最近一次调用last)in()--->1 print(“naive bayes accuracity is:”+str(round(rf\u accuracity,2)))
1 frames/usr/local/lib/python3.6/dist-packages/pyspark/sql/column.py在{1}类型的{0}列(col)54“{0}”中55“对于列文字,使用'lit'、'array'、'struct'或'create\u map'”-->56“function.”format(col,type(col)))57返回jcol 58
typeerror:无效参数,不是<class'float'>类型的字符串或列:93.15707620528771。对于列文字,请使用'lit'、'array'、'struct'或'create\ map'函数。
我在google上搜索了很多,浏览了pyspark的函数和示例,但都没有成功。不知道我错过了什么。任何帮助都将不胜感激。

u2nhd7ah

u2nhd7ah1#

如果rfaccurity是Dataframe的列名,那么您必须这样做

import pyspark.sql.functions aa f
df.select(f.round('rfaccuracy')).show()

相关问题