vincent_nkcs 2019-04-24 22:16
浏览 246

DecisionTreeClassifier.train()调用报错

我在尝试使用DecisionTreeClassifier.train()时一直提示如下错误,说当前对象不是classification包的子类,因此不能调用他的protected属性方法,但是官方文档是public类型的,因此不知道哪里出错了

Error:(218, 41) method train in class DecisionTreeClassifier cannot be accessed in org.apache.spark.ml.classification.DecisionTreeClassifier
 Access to protected method train not permitted because
 enclosing object FeatureSelection in package core is not a subclass of 
 class DecisionTreeClassifier in package classification where target is defined
        val dt = decisionTreeClassifier.train(trainRdd)

环境为scala 2.10.6 spark2.10:1.6.1 jdk1.8,相关代码如下:

import org.apache.spark.ml.classification.DecisionTreeClassifier

object FeatureSelection {
    val selectfeature=ArrayBuffer[String]()
    val tempfeature=selectfeature++ArrayBuffer(line)
    val vectorDF = new VectorAssembler()
                        .setInputCols(tempfeature.toArray)
                        .setOutputCol("features")
                        .transform(tempdf)
                        .select("label", "features")

    val Array(trainRdd, testRdd) =
        vectorDF
            .rdd
            .map(row =>  LabeledPoint(Common.any2Double(row.get(0)).get, row.getAs[Vector](1)))
            .randomSplit(Array(0.5, 0.5), 0L)

    val numClasses = 2
    val categoricalFeaturesInfo = Map[Int, Int]()

     val decisionTreeClassifier = new DecisionTreeClassifier()
          .setMaxBins(maxBins)
          .setImpurity(impurity)
          .setFeaturesCol("features")
          .setLabelCol("label")
          .setMaxDepth(maxDepth)

        val dt = decisionTreeClassifier.train(trainRdd, categoricalFeaturesInfo, numClasses)
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题
    • ¥15 Python时间序列如何拟合疏系数模型