【问题标题】:how to store spark mllib model into local file system (windows)如何将 spark mllib 模型存储到本地文件系统(Windows)
【发布时间】: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


【解决方案1】:

您使用的模型的绝对路径不正确,而不是使用 file:///E:/​​Work... 前缀。

clusters.save(sc, "file:///E:/Work/Python1/work/spark/anomalydetectionspark/test/spark-warehouse") 

【讨论】:

  • 你能再次分享完整的堆栈跟踪吗?
  • 报错的目录路径,你的机器里有吗?如果没有,则创建它。
【解决方案2】:

部署模式必须是“客户端”才能工作,否则必须在服务器上找到传入的“本地路径”,该服务器不会有看起来像 Windows 路径的路径。如果部署模式是“客户端”,则必须注意保存不会发生在并行代码块中,该代码块将在工作线程上执行并且再次不会有此路径。见:https://spark.apache.org/docs/latest/submitting-applications.html

【讨论】:

    猜你喜欢
    • 2017-03-06
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多