- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 197字
- 2021-07-09 21:07:49
Matrix in Spark
A local matrix in Spark has integer-typed row and column indices. Values are double-typed. All the values are stored on a single machine. MLlib supports the following matrix types:
- Dense matrices: Matrices where entry values stored are in a single, double array in a column-major order.
- Sparse matrices: Matrices where non-zero entry values are stored in the CSC format in a column-major order. For example, the following dense matrix is stored in a one-dimensional array [2.0, 3.0, 4.0, 1.0, 4.0, 5.0] for the matrix size (3, 2):
2.0 3.0
4.0 1.0
4.0 5.0
This is an example of a dense and sparse matrix:
val dMatrix: Matrix = Matrices.dense(2, 2, Array(1.0, 2.0, 3.0,
4.0))
println("dMatrix: n" + dMatrix)
val sMatrixOne: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3),
Array(0, 2, 1), Array(5, 6, 7))
println("sMatrixOne: n" + sMatrixOne)
val sMatrixTwo: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3),
Array(0, 1, 2), Array(5, 6, 7))
println("sMatrixTwo: n" + sMatrixTwo)
The output of the preceding code is as follows:
[info] Running linalg.matrix.SparkMatrix
dMatrix:
1.0 3.0
2.0 4.0
sMatrixOne:
3 x 2 CSCMatrix
(0,0) 5.0
(2,1) 6.0
(1,1) 7.0
sMatrixTwo:
3 x 2 CSCMatrix
(0,0) 5.0
(1,1) 6.0
(2,1) 7.0
推薦閱讀
- 大學計算機信息技術導論
- Python Artificial Intelligence Projects for Beginners
- Apache Hive Essentials
- 現(xiàn)代機械運動控制技術
- 統(tǒng)計策略搜索強化學習方法及應用
- C語言開發(fā)技術詳解
- 網(wǎng)絡綜合布線設計與施工技術
- 手機游戲程序開發(fā)
- 人工智能技術入門
- C++程序設計基礎(上)
- 智能鼠原理與制作(進階篇)
- Linux系統(tǒng)下C程序開發(fā)詳解
- HBase Essentials
- Cloudera Hadoop大數(shù)據(jù)平臺實戰(zhàn)指南
- 基于Proteus的PIC單片機C語言程序設計與仿真