使用pyspark计算SVD:
rdd = MLUtils.convertVectorColumnsFromml(df.select("ID","TF_IDF")).rdd
index_mat = IndexedRowMatrix(rdd)
print('index_mat rows = {}'.format(index_mat.numRows()))
print('index_mat columns = {}'.format(index_mat.numCols()))
svd = index_mat.computeSVD(k=100,computeU=True)
输出:
index_mat行= 2000
index_mat列= 6000
spark df
具有100个分区,我正在与20个执行程序一起运行此作业。
这需要一个多小时。在1分钟内运行使用scipy的类似代码。
from scipy.sparse.linalg import svds
u,s,vt = svds(tfidf_sparse,k=100)