【发布时间】:2017-08-07 17:24:06
【问题描述】:
我正在尝试将我的 Kmean 集群模型保存到本地文件系统中。我正在使用 Pyspark mllib 进行 Kmean 聚类。但是我收到以下错误。
format(target_id, ".", name), value)
py4j.protocol.Py4JJavaError: An error occurred while calling o46.save.
: java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: file:E:/Work/Python1/work/spark/anomalydetectionspark/test/spark-warehouse
at org.apache.hadoop.fs.Path.initialize(Path.java:206)
at org.apache.hadoop.fs.Path.<init>(Path.java:172)
at org.apache.hadoop.fs.Path.<init>(Path.java:89)
我的代码:
clusters = KMeans.train(parsedData, 2, maxIterations=10,
runs=10, initializationMode="random")
# Evaluate clustering by computing Within Set Sum of Squared Errors
def error(point):
center = clusters.centers[clusters.predict(point)]
return sqrt(sum([x**2 for x in (point - center)]))
WSSSE = parsedData.map(lambda point: error(point)).reduce(lambda x, y: x + y)
print("Within Set Sum of Squared Error = " + str(WSSSE))
# Save and load model
clusters.save(sc, "file:E:/Work/Python1/work/spark/anomalydetectionspark/test/spark-warehouse")
有人可以帮我找出我收到错误的原因吗?
【问题讨论】:
-
与您提供给
clusters.save的文件路径有关;我对 Windows 上的文件路径不太熟悉,但我怀疑您需要删除file:前缀,所以它只是E:/path/to/file。 -
@Magsol,我也试过了。但还是同样的错误
-
Spark kmeans 大约是你能找到的最慢的。不要使用它。
标签: apache-spark machine-learning cluster-analysis