[英]Scala Spark load saved MLlib model
我已經在我的S3路徑中保存了一個隨機森林模型,現在我想加載它。 但是,我得到一個錯誤,即該方法不存在。
代碼(保存模型有效):
import org.apache.spark.ml.classification.RandomForestClassifier
val rfClassifier = new RandomForestClassifier()
.setImpurity("gini")
.setMaxDepth(8)
.setNumTrees(200)
.setFeatureSubsetStrategy("auto")
.setSeed(18)
val rfModel = rfClassifier.fit(trainingFeatures)
rfModel
.write
.overwrite()
.save(<MY S3 PATH>)
代碼(加載模型不起作用):
val rfmodel = RandomForestClassifier.load(<MY S3 PATH>)
)
錯誤:
java.lang.NoSuchMethodException: org.apache.spark.ml.classification.RandomForestClassificationModel.<init>(java.lang.String)
不知道為什么存在加載方法時會發生此錯誤
您應該加載RandomForestClassificationModel
而不是RandomForestClassifier
。
用。。。來代替:
val rfmodel = RandomForestClassificationModel.load(<MY S3 PATH>)
更多關於模型持久這里
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.