2015-06-16 31 views
0

我试图在只有22MB的示例文档上运行带有Spark的K-means,并且出现Java堆空间错误。有什么想法吗?它在群集行上失败。Spark堆栈空间错误运行K意味着EC2实例

样本数据和代码都在我的github

# run in ipython spark shell, IPYTHON=1 pyspark 

from pyspark import SparkContext 
from pyspark.mllib.feature import HashingTF 
from pyspark.mllib.clustering import KMeans, KMeansModel 
from numpy import array 
from math import sqrt 
import json 
from pyspark.sql import SQLContext, Row 


sqlContext = SQLContext(sc) 
sample = sqlContext.read.json("/home/ubuntu/yelp_project/sample.json") 
sample.registerTempTable("sample") 
reviews = sample.map(lambda x: Row(name= x[1], reviews=' '.join((a[3] for a in  x[0])))) 


hashingTF = HashingTF() 
tf = hashingTF.transform(reviews.map(lambda x: x.reviews)) 
clusters = KMeans.train(tf, 2, maxIterations=10, runs=10, initializationMode="random") 

回答

0

的问题是,我的文件是非常大,特征数量太大,存储在分配给火花进程的内存。为了解决这个问题,我使用最多的功能初始化了我的HashingTF:

hashingTF = HashingTF(5000)