在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条数据。
再执行上面的代码,没报错。
df=df.select([df[col].cast("double") for col in df.columns])
df=df.dropna()
执行下面代码。出现结果
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.