【问题标题】:Illegal Argument Exception using Random Forest in PySpark mllib在 PySpark mllib 中使用随机森林的非法参数异常
【发布时间】:2020-10-18 23:31:07
【问题描述】:

我正在使用 PySpark 在 Spark MLlib 中使用随机森林算法进行分类。我的代码如下:\

model = RandomForest.trainClassifier(trnData, numClasses=3, categoricalFeaturesInfo={}, numTrees=3, featureSubsetStrategy="auto", impurity='gini', maxDepth=4, maxBins=32)

predictions = model.predict(tst_dataRDD.map(lambda x: x.features))

labelsAndPredictions = tst_dataRDD.map(lambda lp: lp.label).zip(predictions)

testErr = labelsAndPredictions.filter(lambda x: x[0] != x[1]).count() / float(tst_dataRDD.count())

我得到 IllegalArgumentException: GiniAggregator given label -0.0625 but requires label to be non-negative.
我怎么解决这个问题?谢谢

【问题讨论】:

  • 完整的堆栈跟踪好吗?

标签: pyspark random-forest apache-spark-mllib illegalargumentexception


【解决方案1】:

【讨论】:

    【解决方案2】:

    似乎Gini 在多类分类过程中的杂质,标签必须为正(> = 0)。请检查是否存在任何负面标签。

    参考-spark repo

    另外,请注意,请使用 ml 包中的算法,而不是旧版 mllib 中的算法

    【讨论】:

      猜你喜欢
      • 2018-05-19
      • 2017-04-14
      • 2015-05-03
      • 2015-05-12
      • 2016-03-06
      • 2016-01-28
      • 2017-03-19
      • 2012-02-01
      • 1970-01-01
      相关资源
      最近更新 更多