gpt4 book ai didi

pyspark - 如何修复 : pyspark. sql.utils.IllegalArgumentException : incorrect type for Column features?

转载 作者:行者123 更新时间:2023-12-04 01:45:32 32 4
gpt4 key购买 nike

我是 pyspark 的新手,正在尝试在简单代码下运行。

# create a RDD of LabeledPoint
bcData = MLUtils.loadLibSVMFile(sc, "breast-cancer.txt")

# convert it to DataFrame
bcDataFrame = ss.createDataFrame(bcData)
bcDataFrame.cache()

# split the data
(training_data, testing_data) = bcDataFrame.randomSplit([0.8, 0.2])

# create the model
dt_classifier = DecisionTreeClassifier(impurity="gini", maxDepth=2, labelCol="label", featuresCol="features")
dt_model = dt_classifier.fit(training_data)

运行时,在最后一行出现以下错误。

pyspark.sql.utils.IllegalArgumentException: u'requirement failed: Column features must be of type struct< type:tinyint,size:int,indices:array< int >,values:array< double >> but was actually struct< type:tinyint,size:int,indices:array< int >,values:array< double >>.'

当列“特征”的实际类型与预期完全匹配时,我不确定为什么会收到此错误。

最佳答案

我在以下环境中遇到了同样的问题:数据 block 、Spark 2.4.0、Scala 2.11

在我的例子中,错误是导入了错误的包。当我出错时:

import org.apache.spark.ml.feature.PCA
import org.apache.spark.mllib.linalg.Vectors

错误是第二次导入(使用了错误的 Vectors 类)。解决方案是将第二个导入更改为:

import org.apache.spark.ml.linalg.Vectors

瞧!

希望这能给你一些关于在 python 中修复它的线索。

关于pyspark - 如何修复 : pyspark. sql.utils.IllegalArgumentException : incorrect type for Column features?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55438516/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com