我有一个包含42个特征和1个标签的数据集。 我想在执行决策树检测异常之前应用spark ML库的选择方法卡方选择器,但是在应用卡方选择器时遇到了这个错误:
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 17.0 failed 1 times, most recent failure: Lost task 0.0 in stage 17.0 (TID 45, localhost, executor driver): org.apache.spark.SparkException: Chi-square test expect factors (categorical values) but found more than 10000 distinct values in column 11.
以下是我的源代码:
from pyspark.ml.feature import ChiSqSelector
selector = ChiSqSelector(numTopFeatures=1, featuresCol="features",outputCol="features2", labelCol="label")
result = selector.fit(dfa1).transform(dfa1)
result.show()
正如您在error msg中看到的,您的
features
列在vector中包含超过10000个不同的值,看起来它们是连续的而不是分类的,ChiSq只能处理10k个类别,您不能增加这个值。你知道吗在这种情况下,可以使用
VectorIndexer
和.setMaxCategories()
参数<;10k来准备数据。您可以尝试其他方法来准备数据,但在向量中不同值的计数大于10k之前,该方法将不起作用相关问题 更多 >
编程相关推荐