本文整理汇总了Scala中org.apache.spark.mllib.tree.model.DecisionTreeModel类的典型用法代码示例。如果您正苦于以下问题:Scala DecisionTreeModel类的具体用法?Scala DecisionTreeModel怎么用?Scala DecisionTreeModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DecisionTreeModel类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1:
//设置package包名称以及导入依赖的类
package ml
import java.io.{File, PrintWriter}
import org.apache.spark.mllib.tree.model.DecisionTreeModel
import org.apache.spark.{SparkContext, SparkConf}
import org.apache.spark.mllib.util.MLUtils
//val model = DecisionTree.trainClassifier(trainingData, numClasses, categoricalFeaturesInfo,
// impurity, maxDepth, maxBins)
val modelPath = args(2)
val model = DecisionTreeModel.load(sc, modelPath)
// Evaluate model on test instances and compute test error
val labelAndPreds = testData.map { point =>
val prediction = model.predict(point.features)
(point.label, prediction)
};
val pw = new PrintWriter(new File(args(1)));
for( a <- labelAndPreds.collect()) {
pw.write(a._1 + " " + a._2 + "\n")
}
val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.count()
pw.write("Test Error = " + testErr)
//println("Learned classification tree model:\n" + model.toDebugString)
pw.close()
}catch {
case e: Exception => println("ERROR. tool unsuccessful:" + e);
}
}
}