mat 和asmatrix的区别_Apache Spark中RowMatrix和Matrix之间的区别?(Difference between RowMatrix and Matrix in Apac...

Apache Spark中RowMatrix和Matrix之间的区别?(Difference between RowMatrix and Matrix in Apache Spark?)

我想知道Apache Spark中可用的RowMatrix和Matrix类之间的基本区别。

I want to know the basic difference between RowMatrix and Matrix class available in Apache Spark.

原文:https://stackoverflow.com/questions/35497736

更新时间:2020-07-26 13:07

最满意答案

这里有一个更精确的问题是mllib.linalg.Matrix和mllib.linalg.distributed.DistributedMatrix之间有什么区别。

Matrix是一种特征,表示驻留在单个机器的内存中的本地矩阵 。 目前有两种基本实现: DenseMatrix和SparseMatrix 。

DistributedMatrix是一种特征,表示构建在RDD之上的分布式矩阵 。 RowMatrix是DistributedMatrix的子类,它以行方式存储数据,而没有有意义的行排序。 DistributedMatrix还有其他实现(如IndexedRowMatrix , CoordinateMatrix和BlockMatrix ),每个实现都有自己的存储策略和特定的方法集。 请参阅Apache Spark中的Matrix Multiplication

A little bit more precise question here would be what is a difference between mllib.linalg.Matrix and mllib.linalg.distributed.DistributedMatrix.

Matrix is a trait which represents local matrices which reside in a memory of a single machine. For now there are two basic implementations: DenseMatrix and SparseMatrix.

DistributedMatrix is a trait which represents distributed matrices build on top of RDD. RowMatrix is a subclass of a DistributedMatrix which stores data in a row-wise manner without meaningful row ordering. There are other implementations of DistributedMatrix (like IndexedRowMatrix, CoordinateMatrix and BlockMatrix) each with its own storage strategy and specific set of methods. See for example Matrix Multiplication in Apache Spark

2017-05-23

相关问答

上面的代码正常工作。 我得到这个错误的原因是我用RDD [Vector]制作了RowMatrix。 现在,在火花中,事物按列排序以形成一个矩阵,而在numpy的情况下,数组被转换为一个矩阵 Array(1,2,3,4,5,6,7,8,9)

在Spark 1 4 7

2 5 8

3 6 9

在Python中,它被解释为 1 2 3

4 5 6

7 8 9

所以,测试用例失败:| The above code works properly. The reason I was getting th

...

只需为RDD提供显式类型注释 val dataRows: org.apache.spark.rdd.RDD[Vector] = ???

或匿名函数的结果: ...

.map(line => Vectors.dense(line.split(" ").map(_.toDouble)).toSparse: Vector)

Just provide explicit type annotation either for a RDD val dataRows: org.apache.spark.r

...

只有支持矩阵 - 矩阵乘法的分布式矩阵才是BlockMatrices 。 你必须相应地转换你的数据 - 人工指数足够好: new IndexedRowMatrix(

rowMatrix.rows.zipWithIndex.map(x => IndexedRow(x._2, x._1))

).toBlockMatrix match { case m => m.multiply(m.transpose) }

Only distributed matrices which support mat

...

使用: row_mat.rows.map(lambda x: (x, )).toDF()

Use: row_mat.rows.map(lambda x: (x, )).toDF()

啊这确实是由依赖性冲突引起的。 显然,新的Spark使用了我所引入的版本中没有的新Breeze方法。从我的Play中移除Breeze! 构建文件我能够运行上面的函数就好了。 对于那些感兴趣的人,这是输出: -0.23490049167080018 0.4371989078912155 0.5344916752692394 ... (6 total)

-0.43624389448418854 0.531880914138611 0.1854269324452522 ..

...

经过多次尝试,这是一个解决方案: val rdd = df.rdd.map(

row => Vectors.dense(row.getAs[Seq[Double]](1).toArray)//get the second column value as Seq[Double], then as Array, then cast to Vector

)

val row = new RowMatrix(rdd)

After numerous tries, h

...

这是一个基本的操作,考虑到U是一个RowMatrix,你需要做的就是: val U = svd.U

rows()是一种RowMatrix方法,允许您逐行从RowMatrix获取RDD。 您只需要在RowMatrix上应用行并映射RDD [Vector]以创建一个阵列,您可以将其连接成一个创建RDD [String]的字符串。 val rdd = U.rows.map( x => x.toArray.mkString(","))

现在你需要做的就是保存RDD了: rdd.saveAsTextFi

...

从映射稍微不同的byUserHour开始现在是RDD[(String, (String, Int))] . 因为RowMatrix不保留row_id上的行groupByKey的顺序。 也许将来我会弄清楚如何用稀疏矩阵做到这一点。 val byUser = byUserHour.groupByKey // RDD[(String, Iterable[(String, Int)])]

val times = countHour.map(x => x._1.split("\\+")(1)).distin

...

RowMatrix是一种分布式数据结构,可靠地输出其内容的唯一方法是将数据提取到驱动程序并在本地打印。 通常它是您想要避免的操作,但一般方法如下 val mat: RowMatrix = ???

mat

.rows // Extract RDD[org.apache.spark.mllib.linalg.Vector]

.collect // you can use toLocalIterator to limit memory usage

.foreach(println) // I

...

这里有一个更精确的问题是mllib.linalg.Matrix和mllib.linalg.distributed.DistributedMatrix之间有什么区别。 Matrix是一种特征,表示驻留在单个机器的内存中的本地矩阵 。 目前有两种基本实现: DenseMatrix和SparseMatrix 。 DistributedMatrix是一种特征,表示构建在RDD之上的分布式矩阵 。 RowMatrix是DistributedMatrix的子类,它以行方式存储数据,而没有有意义的行排序。 Di

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值