切分資料
已提供一個 dataframe df_examples,包含欄位 endword:string、features:vector、outvec:vector,以及 label:int。你將把它切分成訓練集與測試集,並用來訓練與測試分類器。
本練習屬於課程
Python Spark SQL 入門
練習說明
- 以 80/20 的比例將樣本切分為訓練集與測試集。
- 列印訓練樣本的數量。
- 列印測試樣本的數量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Split the examples into train and test, use 80/20 split
df_trainset, df_testset = df_examples.____((____), 42)
# Print the number of training examples
print("Number training: ", ____.____)
# Print the number of test examples
print("Number test: ", ____.____)