1. 程式人生 > >pyspark 用fit訓練資料集的時候出現"Params must be either a param map or a list/tuple of param maps, "

pyspark 用fit訓練資料集的時候出現"Params must be either a param map or a list/tuple of param maps, "

在anaconda用決策樹訓練資料,

from pyspark.ml.classification import DecisionTreeClassifier
dt=DecisionTreeClassifier(labelCol="label",featuresCol="features")
dt_model=dt.fit(dfff)

出現錯誤 在這裡插入圖片描述

沒辦法,最後通過谷歌搜尋,最後猜測可能是當我用cast轉換資料型別時,導致某些資料不能轉換從而變成null。 然後再轉換型別之後,用dff.dropna()。用dfff.count()檢視資料行數,果然比之前少了10條資料。 再執行上面的程式碼,沒報錯。

執行下面程式碼。出現結果

print(dt_model)

DecisionTreeClassificationModel (uid=DecisionTreeClassifier_49c7b461375198d98f68) of depth 5 with 59 nodes

檢視下面的錯誤訊息,會發現有這麼一句話: Caused by: org.apache.spark.SparkException: Values to assemble cannot be null.