【问题标题】:WARN TaskSetManager: Lost Task xxx: java.lang.ArrayIndexOutOfBoundsException: 1 - ScalaWARN TaskSetManager: Lost Task xxx: java.lang.ArrayIndexOutOfBoundsException: 1 - Scala
【发布时间】:2019-07-07 01:43:53
【问题描述】:

我正在尝试使用 GridCV 在 scala 中进行超参数调整。但是,我创建了我的管道和所有内容,我将我的数据集与管道相匹配,它非常适合。

然后我添加一些paramGrid 并在 4 个阶段后进行交叉验证,它给了我错误:

scala> val cvModel = cv.fit(df)
Tracker started, with env={DMLC_NUM_SERVER=0, DMLC_TRACKER_URI=10.xx.xx.xxx, DMLC_TRACKER_PORT=9091, DMLC_NUM_WORKER=1}
Tracker started, with env={DMLC_NUM_SERVER=0, DMLC_TRACKER_URI=10.xx.xx.xxx, DMLC_TRACKER_PORT=9091, DMLC_NUM_WORKER=1}
Tracker started, with env={DMLC_NUM_SERVER=0, DMLC_TRACKER_URI=10.xx.xx.xxx, DMLC_TRACKER_PORT=9091, DMLC_NUM_WORKER=1}
Tracker started, with env={DMLC_NUM_SERVER=0, DMLC_TRACKER_URI=10.xx.xx.xxx, DMLC_TRACKER_PORT=9091, DMLC_NUM_WORKER=1}
19/02/13 09:16:33 WARN TaskSetManager: Lost task 2.0 in stage 152.0 (TID 916, ip-10.xx.xx.xxx.ec2.internal, executor 7): java.lang.ArrayIndexOutOfBoundsException: 1
        at org.apache.spark.ml.linalg.DenseVector.apply(Vectors.scala:448)
        at org.apache.spark.ml.evaluation.BinaryClassificationEvaluator$$anonfun$1.apply(BinaryClassificationEvaluator.scala:82)
        at org.apache.spark.ml.evaluation.BinaryClassificationEvaluator$$anonfun$1.apply(BinaryClassificationEvaluator.scala:81)
        at scala.collection.Iterator$$anon$11.next(Iterator.scala:409)
        at org.apache.spark.util.collection.ExternalSorter.insertAll(ExternalSorter..

然后实际上是两三段错误。我无法弄清楚为什么会发生这种情况,因为我是第一次在 scala 中编码。但是根据我的概念和示例中给出的代码,它似乎没有锻炼。

这是我的代码:

import java.util.Calendar
import org.apache.log4j.{Level, Logger}
import org.apache.spark.ml.feature._
import org.apache.spark.sql._
import org.apache.spark.sql.functions.lit
import java.io.PrintWriter
import java.io.File
import org.apache.spark.ml.feature.StringIndexer
import org.apache.spark.ml.tuning._
import org.apache.spark.ml.evaluation.BinaryClassificationEvaluator
import ml.dmlc.xgboost4j.scala.spark.XGBoostClassifier
import ml.dmlc.xgboost4j.scala.spark.XGBoostClassificationModel
import org.apache.spark.ml.{Pipeline, PipelineModel}

val spark = SparkSession.builder().getOrCreate()
val dataset = spark.sql("select * from userdb.xgb_train_data")
val df = dataset.na.fill(0)




val header = df.columns.filter(_ != "id").filter(_ != "y_val")
val assembler = new VectorAssembler().setInputCols(header).setOutputCol("features")

val booster= new XGBoostClassifier().setLabelCol("y_val")
val pipeline = new Pipeline().setStages(Array(assembler,booster))
val model = pipeline.fit(df)

val evaluator = new BinaryClassificationEvaluator().setLabelCol("y_val")

val paramGrid = new ParamGridBuilder().
    addGrid(booster.maxDepth, Array(3, 8)).
    addGrid(booster.eta, Array(0.2, 0.6)).
    build()


val cv = new CrossValidator().
    setEstimator(pipeline).
    setEvaluator(evaluator).
    setEstimatorParamMaps(paramGrid).
    setNumFolds(10)
val cvModel = cv.fit(df)

val bestModel = cvModel.bestModel.asInstanceOf[PipelineModel].stages()
    .asInstanceOf[XGBoostClassificationModel]
bestModel.extractParamMap()

或者有没有其他方法可以对交叉验证进行超参数调优和测试?我在执行setEvaluator 代码时遇到了这个问题。我的理解是我的特征形状和 y 预测形状不匹配。但是我如何确保他们这样做呢?

附:我在 EMR 集群上运行它。我也尝试了同样的事情,只是将算法更改为逻辑回归,它工作得很好。我使用的是 xgboost v0.8 而 spark 是 v2.2

【问题讨论】:

    标签: java python scala apache-spark xgboost


    【解决方案1】:

    解决这个问题的诀窍是使用multiclassclassification评估器而不是Binaryclassificationevaluator

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 2013-11-19
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      相关资源
      最近更新 更多