vincent_nkcs 2019-04-24 22:28
浏览 273

DecisionTreeClassifier.train()无法调用

我在尝试使用DecisionTreeClassifier.train()时出现了以下报错提示:

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)

指出由于我的对象 FeatureSelection不是包classification的子类,因而不能调用它的protected类型方法,但是官方文档上train是public类型的

环境:scala2.10.6 spark2.10:1.6.1 jdk1.8

附上相关代码:

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

object FeatureSelection {
  def selectFeatureGreedyDTNoLimit(){
    val selectfeature=ArrayBuffer[String]()
    val selectsize=selectfeature.size
    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 dt = decisionTreeClassifier.train(trainRdd, categoricalFeaturesInfo, numClasses)
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配