Spark机器学习(四) Local matrix -- Data Types
2016-04-23 22:45
267 查看
Local matrix
A local matrix has integer-typed row and column indices and double-typed values, stored on a single machine. MLlib supports dense matrices, whose entry values are stored in a single double array in column-major order, and sparse matrices, whose non-zero entry values are stored in the Compressed Sparse Column (CSC) format in column-major order. For example, the following dense matrix局部矩阵由整数型行和列的索引和浮点数类型的值组成,存储在一个单独节点上。MLlib支持密集矩阵,entry值被存储在一个一维浮点数数组,以列为排序主键。而稀疏矩阵,non-zero entry值,以Compressed Sparse Column (CSC) 格式存储,以列主键排序。例如,下面的密集矩阵
|1.0 2.0|
|3.0 4.0|
|5.0 6.0|
is stored in a one-dimensional array
[1.0, 3.0, 5.0, 2.0, 4.0, 6.0]with the matrix size
(3, 2).
被存储在一个一维数组
[1.0, 3.0, 5.0, 2.0, 4.0, 6.0]里,矩阵的size为(3,2)
Scala
The base class of local matrices is
Matrix, and we provide two implementations:
DenseMatrix, and
SparseMatrix. We recommend using the factory methods implemented in
Matricesto create local matrices. Remember, local matrices in MLlib are stored in column-major order.
局部矩阵的基类是Matrix,我们提供了两种实现:
DenseMatrix, and
SparseMatrix.
我们推荐使用
Matrices 已经实现的工厂方法来创建局部矩阵。
记住,局部矩阵在MLlib中是以列排序存储的。
Refer to the
MatrixScala docs and
MatricesScala docs for details on the API.
更多信息请参见
MatrixScala docs and
MatricesScala docs API。
import org.apache.spark.mllib.linalg.{Matrix, Matrices} // Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0)) val dm: Matrix = Matrices.dense(3, 2, Array(1.0, 3.0, 5.0, 2.0, 4.0, 6.0)) // Create a sparse matrix ((9.0, 0.0), (0.0, 8.0), (0.0, 6.0)) val sm: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3), Array(0, 2, 1), Array(9, 6, 8))
相关文章推荐
- C++静态多态性之函数重载
- 【转】单身女孩在魔都 如何活出贵族范
- C++中#error/assert/static_assert的区别及使用
- C++中#error/assert/static_assert的区别及使用
- 中国这100个地方,你去过几个?
- 资深后台研发工程师(转)
- 文章标题
- 数值的整数次方
- 1015 Knight Moves
- jQuery源码学习之对象创建与初始化
- Oracle数据库触发器如何调用Java程序实现Openfire消息推送
- Spring配置文件异常:White spaces are required between publicId and systemId
- import com.sun.image.codec.jpeg.JPEGCodec不通过 Eclipse找不到包
- tty/pts 相关指令
- mysql客户端工具使用
- ZOJ 3933(网络流)
- 优酷 Java笔试题(摘要)
- 排序常用算法总结
- 这是一份沉重回忆的开始
- 搭建简单Samba服务器