由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
DataSciences版 - spark 问题
相关主题
questions about SVD and ALSWR for collaborative filteringData Scientist的编程能力
哪里有基于sparks的算法的书?求Google 的 Data Science 有关的位置内推 (转载)
【内部推荐工作】Data scientist / Machine Learning Engineer 相关面试题 (转载)
有尝请教关于spark api java coding求handle missing data的好方法
求问编程语言的选择,学stat的往DS努力刚入行新人的两个问题
不知这样的大数据培训怎样?我想求职Big data Architect......有人考虑过kaggle上这个预测CTR的题目么?
求教! how to run python programs on a hadoop cluster请问哪些算法是可以用python写的,然后输入PMML
现在的大数据技术的价值和功用有些被夸大了我想写个survey报告 关于KNN classification algorithms
相关话题的讨论汇总
话题: vector话题: val话题: spark话题: sparse话题: dense
进入DataSciences版参与讨论
1 (共1页)
s****h
发帖数: 3979
1
新手请教一个scala+spark问题:
数据格式: userid itemid1,itemid2,itemid3,...
sample:
5 7,13,20,27
12 7,10,27,33
需要做的是,每两个userid的item vector算cosine, 每个user, sort其他user by
cosine value.
其实就是一个KNN.
我想得是
a. 一行行读进来,每行一个sparse vector
or
b. 一起读进一个sparse matrix
两种方式都不会.
多谢多谢。
scala+spark经验只限于根据spark summit上的alswr code照猫画虎,处理了一下自己
的数据。
n*****3
发帖数: 1584
2
做过一个小project with spark, 没太多经验。。
你要想好 first 你的data manipulation steps before really starts,
spark tokenlize them differently
BTW spark 最近 搞个 data frame API , 你 可以 试试, should be better

【在 s****h 的大作中提到】
: 新手请教一个scala+spark问题:
: 数据格式: userid itemid1,itemid2,itemid3,...
: sample:
: 5 7,13,20,27
: 12 7,10,27,33
: 需要做的是,每两个userid的item vector算cosine, 每个user, sort其他user by
: cosine value.
: 其实就是一个KNN.
: 我想得是
: a. 一行行读进来,每行一个sparse vector

s****h
发帖数: 3979
3
data frame API 1.3 才有。
弄进一个dense vector很直接:
import org.apache.spark.mllib.linalg.{Vector, Vectors}
val path = "~/test60m.txt"
val minPartitions = 4

val parsed = sc.textFile(path, minPartitions)
.map(_.trim)
.filter(line => !(line.isEmpty || line.startsWith("#")))
val a = parsed.map({ line =>
val fields = line.split(" ")
(fields(0).toInt, fields(1))})
val dataLoad = a.map(x => (x._1, Vectors.dense(x._2.split(',').map(_.
toDouble))))
可是sparse vector就不会了。
不知道怎么结合下面的例子
// Create a dense vector (1.0, 0.0, 3.0).
val dv: Vector = Vectors.dense(1.0, 0.0, 3.0)
// Create a sparse vector (1.0, 0.0, 3.0) by specifying its indices and
values corresponding to nonzero entries.
val sv1: Vector = Vectors.sparse(3, Array(0, 2), Array(1.0, 3.0))
// Create a sparse vector (1.0, 0.0, 3.0) by specifying its nonzero entries.
val sv2: Vector = Vectors.sparse(3, Seq((0, 1.0), (2, 3.0)))
s****h
发帖数: 3979
4
ok
这样就行了
val b = a.map(x => (x._1, Vectors.sparse(30000, x._2.split(',').map(_.toInt)
, (new Array[Double](x._2.split(',').length).map(y=>y+1.0) ))))
下一个问题是:这么搞效率好么?对performance会不会有打的影响呢?
H****E
发帖数: 254
5
https://databricks.com/blog/2014/07/16/new-features-in-mllib-in-spark-1-0.
html
"So storage-wise, the sparse format is better than the dense format when
more than 1/3 of the elements are zero. However, assuming that the data can
be fit into memory in both formats, we usually need sparser data to observe
a speedup, because the sparse format is not as efficient as the dense format
in computation. Our experience suggests a sparsity of around 10%, while the
exact switching point for the running time is indeed problem-dependent."
v*******e
发帖数: 3714
6
你看看 MLlib 上 cosine similarity 的 source code,直接用或者自己改一下应该没
问题吧
https://github.com/apache/spark/blob/master/examples/src/main/scala/org/
apache/spark/examples/mllib/CosineSimilarity.scala
m*********r
发帖数: 119
7
想自学下spark
请问怎么入手好?
youtube 上得视频都不怎么样啊?
h*********d
发帖数: 109
8


【在 s****h 的大作中提到】
: 新手请教一个scala+spark问题:
: 数据格式: userid itemid1,itemid2,itemid3,...
: sample:
: 5 7,13,20,27
: 12 7,10,27,33
: 需要做的是,每两个userid的item vector算cosine, 每个user, sort其他user by
: cosine value.
: 其实就是一个KNN.
: 我想得是
: a. 一行行读进来,每行一个sparse vector

1 (共1页)
进入DataSciences版参与讨论
相关主题
我想写个survey报告 关于KNN classification algorithms求问编程语言的选择,学stat的往DS努力
有关归类不知这样的大数据培训怎样?我想求职Big data Architect......
怎么计算距离比较好?求教! how to run python programs on a hadoop cluster
T家onsite面经现在的大数据技术的价值和功用有些被夸大了
questions about SVD and ALSWR for collaborative filteringData Scientist的编程能力
哪里有基于sparks的算法的书?求Google 的 Data Science 有关的位置内推 (转载)
【内部推荐工作】Data scientist / Machine Learning Engineer 相关面试题 (转载)
有尝请教关于spark api java coding求handle missing data的好方法
相关话题的讨论汇总
话题: vector话题: val话题: spark话题: sparse话题: dense