无法调用DecisionTreeClassifier.train()

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

错误:(218, 41) 在org.apache.spark.ml.classification.DecisionTreeClassifier类中无法访问train方法,因为封闭对象FeatureSelection在core包中不是classification包中定义目标的DecisionTreeClassifier类的子类,无法访问受保护的方法train val dt = decisionTreeClassifier.train(trainRdd)

报告指出我的对象FeatureSelection不是classification包的子类,因此无法调用该包的受保护方法。但实际上,官方文档中train()是一个公共类型的函数。

环境:Scala 2.10.6 Spark 2.10:1.6.1 jdk 1.8

附上代码如下:

import org.apache.spark.ml.classification.DecisionTreeClassifierobject 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)  }}

希望有人能帮助我解决这个问题。


回答:

您应该使用方法fit

train是一个内部函数,这就是它被保护的原因。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注