Spark中组件Mllib的学习12之密集向量和稀疏向量的生成
2016-05-23 17:58
363 查看
更多代码请见:https://github.com/xubo245/SparkLearning
Spark中组件Mllib的学习之基础概念篇
1解释
mllib生成Vector
2.代码:
3.结果:
参考
【1】http://spark.apache.org/docs/1.5.2/mllib-guide.html
【2】http://spark.apache.org/docs/1.5.2/programming-guide.html
【3】https://github.com/xubo245/SparkLearning
Spark中组件Mllib的学习之基础概念篇
1解释
mllib生成Vector
2.代码:
/** * @author xubo * ref:Spark MlLib机器学习实战 * more code:https://github.com/xubo245/SparkLearning * more blog:http://blog.csdn.net/xubo245 */ package org.apache.spark.mllib.learning.basic import org.apache.spark.mllib.linalg.Vectors /** * Created by xubo on 2016/5/23. * Vector */ object VectorLearning { def main(args: Array[String]) { val vd = Vectors.dense(2, 0, 6) println(vd(2)) println(vd) //数据个数,序号,value val vs = Vectors.sparse(4, Array(0, 1, 2, 3), Array(9, 5, 2, 7)) println(vs(2)) println(vs) val vs2 = Vectors.sparse(4, Array(0, 2, 1, 3), Array(9, 5, 2, 7)) println(vs2(2)) println(vs2) } }
3.结果:
6.0 [2.0,0.0,6.0] 2.0 (4,[0,1,2,3],[9.0,5.0,2.0,7.0]) 5.0 (4,[0,2,1,3],[9.0,5.0,2.0,7.0])
参考
【1】http://spark.apache.org/docs/1.5.2/mllib-guide.html
【2】http://spark.apache.org/docs/1.5.2/programming-guide.html
【3】https://github.com/xubo245/SparkLearning
相关文章推荐
- Spark RDD API详解(一) Map和Reduce
- 使用spark和spark mllib进行股票预测
- Spark随谈——开发指南(译)
- Spark,一种快速数据分析替代方案
- 用Python从零实现贝叶斯分类器的机器学习的教程
- eclipse 开发 spark Streaming wordCount
- Understanding Spark Caching
- ClassNotFoundException:scala.PreDef$
- Windows 下Spark 快速搭建Spark源码阅读环境
- Spark中将对象序列化存储到hdfs
- 使用java代码提交Spark的hive sql任务,run as java application
- My Machine Learning
- 机器学习---学习首页 3ff0
- Spark机器学习(一) -- Machine Learning Library (MLlib)
- Spark机器学习(二) 局部向量 Local-- Data Types - MLlib
- Spark机器学习(三) Labeled point-- Data Types
- Spark初探
- Spark Streaming初探
- Spark本地开发环境搭建