本文整理汇总了Scala中org.apache.spark.ml.regression.RandomForestRegressor类的典型用法代码示例。如果您正苦于以下问题:Scala RandomForestRegressor类的具体用法?Scala RandomForestRegressor怎么用?Scala RandomForestRegressor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RandomForestRegressor类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: SitelinkEntry
//设置package包名称以及导入依赖的类
package org.wikimedia.research.recommendation.job.translation
import org.apache.spark.ml.evaluation.RegressionEvaluator
import org.apache.spark.ml.linalg.DenseVector
import org.apache.spark.ml.regression.RandomForestRegressor
import org.apache.spark.sql.{DataFrame, SparkSession}
case class SitelinkEntry(id: String, site: String, title: String)
case class PagecountEntry(site: String, title: String, pageviews: Double)
case class SitelinkPageviewsEntry(id: String, site: String, title: String, pageviews: Double)
case class RankedEntry(id: String, site: String, title: String, pageviews: Double, rank: Double)
object Utils {
val FEATURES = "features"
val LABEL = "label"
val PREDICTION = "prediction"
val EXISTS = 1.0
val NOT_EXISTS = 0.0
val REGRESSOR: RandomForestRegressor = new RandomForestRegressor()
.setLabelCol(LABEL)
.setFeaturesCol(FEATURES)
val EVALUATOR: RegressionEvaluator = new RegressionEvaluator()
.setLabelCol(LABEL)
.setPredictionCol(PREDICTION)
.setMetricName("rmse")
def getWorkData(spark: SparkSession, data: DataFrame, target: String, exists: Boolean = true): DataFrame = {
val workData: DataFrame = data.filter(row =>
row(row.fieldIndex("exists_" + target)) == (if (exists) EXISTS else NOT_EXISTS))
import spark.implicits._
val labeledData = workData.map(row =>
(
row.getString(row.fieldIndex("id")),
row.getDouble(row.fieldIndex("rank_" + target)),
new DenseVector((
(1 until row.fieldIndex("pageviews_" + target)).map(row.getDouble) ++
(row.fieldIndex("exists_" + target) + 1 until row.length).map(row.getDouble)
).toArray)
)
).rdd
spark.createDataFrame(labeledData).toDF("id", LABEL, FEATURES)
}
}
开发者ID:schana,项目名称:recommendation-translation,代码行数:50,代码来源:Utils.scala
注:本文中的org.apache.spark.ml.regression.RandomForestRegressor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论