首页 > 代码库 > Spark MLLib示例
Spark MLLib示例
import org.apache.spark.mllib.tree.DecisionTree import org.apache.spark.mllib.util.MLUtils val data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_libsvm_data.txt").cache() val numClasses = 2 val categoricalFeaturesInfo = Map[Int, Int]() val impurity = "gini" val maxDepth = 5 val maxBins = 100 val model = DecisionTree.trainClassifier(data, numClasses, categoricalFeaturesInfo, impurity,maxDepth, maxBins) val labelAndPreds = data.map { point => val prediction = model.predict(point.features) (point.label, prediction)} val trainErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / data.count println("Training Error = " + trainErr) println("Learned classification tree model:\n" + model)
Spark MLLib示例
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。