我已经在PySpark 2.4中保存了一个NaiveBayes模型。但是在加载时收到错误。谁能帮忙吗?
我可以看到已创建目录及其中的文件。
nb = NaiveBayes(smoothing=1.0, modelType='multinomial')
predictor = nb.fit(training)
用于保存模型的代码
output_dir = './myNaiveBeyesModel'
predictor.write().overwrite().save(output_dir)
加载代码
# load the model from disk
from pyspark.mllib.classification import NaiveBayesModel
from pyspark.ml.pipeline import PipelineModel
drug_model = PipelineModel.load(output_dir)
尝试过
# load the model from disk
from pyspark.mllib.classification import NaiveBayesModel
from pyspark.ml.pipeline import PipelineModel
drug_model = PipelineModel.load(output_dir)
也
# load the model from disk
from pyspark.mllib.classification import NaiveBayesModel
from pyspark.ml.pipeline import PipelineModel
drug_model = NaiveBayesModel.load(sc,output_dir)
但是两次都出错
Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.classification.NaiveBayesModel.load.
: org.json4s.package$MappingException: Did not find value which can be converted into java.lang.String
at org.json4s.Extraction$.convert(Extraction.scala:603)
at org.json4s.Extraction$.extract(Extraction.scala:350)
at org.json4s.Extraction$.extract(Extraction.scala:42)
at org.json4s.ExtractableJsonAstNode.extract(ExtractableJsonAstNode.scala:21)
at org.apache.spark.mllib.util.Loader$.loadMetadata(modelSaveLoad.scala:131)
at org.apache.spark.mllib.classification.NaiveBayesModel$.load(NaiveBayes.scala:271)
at org.apache.spark.mllib.classification.NaiveBayesModel.load(NaiveBayes.scala)
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 py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.lang.Thread.run(Thread.java:748)