/**
* 使用决策树算法预测
* def trainRegressor(
* input: RDD[LabeledPoint],
* categoricalFeaturesInfo: Map[Int, Int],
* An entry (n to k)ndicates that feature n is categorical with k categories
* n:表示的是 那个特征值是类别数据,写下标,从0 开始
* k:表示特征性类别个数,星期:7
* impurity: String,
* 计算特征值重要性指标,此处是回归,写死:variance
* maxDepth: Int,
* 最大数的深度
* maxBins: Int
* 树的最大分裂区间数
* ): DecisionTreeModel = {
*/
val dtModel: DecisionTreeModel = DecisionTree.trainRegressor(
traningRDD,
Map[Int, Int](0->7),
"variance",
16,
32
)
//使用模型进行预测--得到预测值和实际值的比较
val actualAndPredictRDD: RDD[(Double, Double)] = testingRDD.map{
case LabeledPoint(label,features)=>{
val predictValue = dtModel.predict(features)
(label,predictValue)
}
}
随机树
/**
* 森林里面有很多棵数,随机森林回归算法

本文探讨了如何利用决策树和随机森林回归算法进行预测,并重点关注了数据预处理中的标准化方法。同时,文章也提到了线性回归在预测中的应用,比较了不同算法在预测效果上的差异。
最低0.47元/天 解锁文章
800

被折叠的 条评论
为什么被折叠?



