您的位置:首页 > 其它

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
Matrices
to create local matrices. Remember, local matrices in MLlib are stored in column-major order.
局部矩阵的基类是Matrix,我们提供了两种实现:
DenseMatrix
, and
SparseMatrix
.
我们推荐使用
Matrices 已经实现的工厂方法来创建局部矩阵。

记住,局部矩阵在MLlib中是以列排序存储的。

Refer to the
Matrix
Scala docs
and
Matrices
Scala docs
for details on the API.
更多信息请参见
Matrix
Scala docs
and
Matrices
Scala 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))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: