我们如何使用 spark 加载机器学习模型 .sav 文件

how we load machine learning Model .sav file with spark

我想加载已在 spark 中保存为 .sav 文件的机器学习模型 我用过

val loaded_model = Pipeline.load("model_final.sav")    

val loaded_model = PipelineModel.load("model_final.sav")

我遇到异常

Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64)
Caused by: java.lang.NoClassDefFoundError: org/apache/spark/ml/Pipeline$
    at migration2$.main(migration2.scala:61)
    at migration2.main(migration2.scala)
    ... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.spark.ml.Pipeline$
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 7 more

从您的依赖项中删除 provided。所以如下:

libraryDependencies += "org.apache.spark" %% "spark-mllib" % "2.1.0" % "provided"

应改为:

libraryDependencies += "org.apache.spark" %% "spark-mllib" % "2.1.0"