开始使用免费开始使用

预测测试数据

已提供拟合好的逻辑回归模型 df_fitted。已提供数据框 df_testset,其中包含该模型的测试数据。已提供变量 fields,其内容为列表 ['prediction', 'label', 'endword', 'doc', 'probability'];用于指定要打印的预测字段。

本练习是课程的一部分

Python 中的 Spark SQL 入门

查看课程

练习说明

  • 将模型应用于 df_testset 中的数据。
  • 若预测与标签不一致,则打印 "incorrect"。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Apply the model to the test data
predictions = df_fitted.____(____).select(fields)

# Print incorrect if prediction does not match label
for x in predictions.take(8):
    print()
    if x.label != int(x.____):
        print("INCORRECT ==> ")
    for y in fields:
        print(y,":", x[y])
编辑并运行代码