テストデータを予測する
学習済みのロジスティック回帰モデル 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])