赞
踩
逻辑回归、支持向量机、朴素贝叶斯和决策树
导入训练数据集,然后在训练集上执行训练算法,最后在所得模型上进行预测并计算训练误差
import org.apache.spark.SparkContext import org.apache.spark.mllib.classification.SVMWithSGD import org.apache.spark.mllib.regression.LabeledPoint // 加载和解析数据文件 val data = sc.textFile("mllib/data/sample_svm_data.txt") val parsedData = data.map { line => val parts = line.split(' ') LabeledPoint(parts(0).toDouble, parts.tail.map(x => x.toDouble).toArray) } // 设置迭代次数并进行进行训练 val numIterations = 20 val model = SVMWithSGD.train(parsedData, numIterations) // 统计分类错误的样本比例 val labelAndPreds = parsedData.map { point => val prediction = model.predict(point.features) (point.label
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。