本文整理汇总了Scala中org.apache.spark.mllib.stat.MultivariateStatisticalSummary类的典型用法代码示例。如果您正苦于以下问题:Scala MultivariateStatisticalSummary类的具体用法?Scala MultivariateStatisticalSummary怎么用?Scala MultivariateStatisticalSummary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MultivariateStatisticalSummary类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: RandomDistribution
//设置package包名称以及导入依赖的类
package net.akmorrow13.endive.featurizers
import breeze.linalg.DenseVector
import breeze.stats.distributions.{ExponentialFamily, DiscreteDistr, Poisson, Gaussian}
import org.apache.spark.mllib.stat.{MultivariateStatisticalSummary, Statistics}
import org.apache.spark.mllib.linalg.Vectors
import org.apache.spark.rdd.RDD
object RandomDistribution {
def poisson(data: RDD[DenseVector[Double]]): Poisson = {
val summary: MultivariateStatisticalSummary = Statistics.colStats(data.map(r => Vectors.dense(r.toArray)))
val mean = summary.mean.toArray.sum
new Poisson(mean)
}
def gaussian(data: RDD[DenseVector[Double]]): Gaussian = {
val summary: MultivariateStatisticalSummary = Statistics.colStats(data.map(r => Vectors.dense(r.toArray)))
val mean = summary.mean.toArray.sum
val variance = summary.variance.toArray.sum
println(s"mean: ${mean} variance ${variance}")
new Gaussian(mean, variance)
}
}