SparkException:Chisquare检验期望因子

2024-09-28 23:43:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个包含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()

Tags: inorgfailureapache选择器特征标签result
1条回答
网友
1楼 · 发布于 2024-09-28 23:43:04

正如您在error msg中看到的,您的features列在vector中包含超过10000个不同的值,看起来它们是连续的而不是分类的,ChiSq只能处理10k个类别,您不能增加这个值。你知道吗

  /**
   * Max number of categories when indexing labels and features
   */
  private[spark] val maxCategories: Int = 10000

在这种情况下,可以使用VectorIndexer.setMaxCategories()参数<;10k来准备数据。您可以尝试其他方法来准备数据,但在向量中不同值的计数大于10k之前,该方法将不起作用

相关问题 更多 >