對測試資料進行預測
已提供擬合完成的邏輯迴歸模型 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])