繁体   English   中英

Spark在K2上运行K表示Spark的Java堆空间错误

[英]Java heap space error with Spark running K means on EC2 instance

我正在尝试在只有22MB的示例文档中使用Spark运行K-means,并且遇到Java堆空间错误。 有什么想法吗? 它在群集行上失败。

示例数据和代码在我的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")

问题是我的文档非常大,要素数量太大,无法存储在为火花过程分配的内存中。 为了解决该问题,我使用最多数量的功能初始化了HashingTF:

hashingTF = HashingTF(5000)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM