本文整理汇总了Scala中org.apache.spark.mllib.tree.impurity.Gini类的典型用法代码示例。如果您正苦于以下问题:Scala Gini类的具体用法?Scala Gini怎么用?Scala Gini使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gini类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: DecisionTreeTest
//设置package包名称以及导入依赖的类
package org.apache.spark.examples.mllib
import org.apache.spark.{ SparkConf, SparkContext }
import org.apache.spark.mllib.tree.DecisionTree
import org.apache.spark.mllib.regression.LabeledPoint
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.mllib.tree.configuration.Algo._
import org.apache.spark.mllib.tree.impurity.Gini
object DecisionTreeTest {
def main(args: Array[String]) {
val sparkConf = new SparkConf().setMaster("local[2]").setAppName("KMeansClustering")
val sc = new SparkContext(sparkConf)
val data = sc.textFile("../data/mllib/sample_tree_data.csv")
val parsedData = data.map { line =>
val parts = line.split(',').map(_.toDouble)
//LabeledPoint????????,?????????????,????????????(label)
LabeledPoint(parts(0), Vectors.dense(parts.tail))
}
val maxDepth = 5//??????,???????,?????????
val model = DecisionTree.train(parsedData, Classification, Gini, maxDepth)
val labelAndPreds = parsedData.map { point =>
val prediction = model.predict(point.features)
(point.label, prediction)
}
val trainErr = labelAndPreds.filter(r => r._1 != r._2).count().toDouble / parsedData.count
println("Training Error = " + trainErr)
}
}