let's say you have a model which is of class
"org.apache.spark.mllib.classification.LogisticRegressionModel"
you can save model to disk as following:
/import java.io.FileOutputStream
import java.io.ObjectOutputStream
val fos = new FileOutputStream("e:/model.obj")
val oos = new ObjectOutputStream(fos)
oos.writeObject(model)
oos.close/
and load it in:
/import java.io.FileInputStream
import java.io.ObjectInputStream
val fos = new FileInputStream("e:/model.obj")
val oos = new ObjectInputStream(fos)
val newModel =
oos.readObject().asInstanceOf[org.apache.spark.mllib.classification.LogisticRegressionModel]/
you can check that '/newModel.weights/' gives you the weights, implying that
newModel is loaded successfully.
There remains, however, another problem, which confuses me badly: when i use
the loaded newModel to predict on LabeledPoints, there is always a "Task not
serializable" exception! Detailed logs:
INFO DAGScheduler: Failed to run count at <console>:49
org.apache.spark.SparkException: Job aborted due to stage failure: Task not
serializable: java.io.NotSeri
at
org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndInd
at
org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1017)
at
org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1015)
at
scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
at
scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
at
org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1015)
at
org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$submitMissing
at
org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$submitStage(D
at
org.apache.spark.scheduler.DAGScheduler.handleJobSubmitted(DAGScheduler.scala:697)
at
org.apache.spark.scheduler.DAGSchedulerEventProcessActor$$anonfun$receive$2.applyOrElse(DAGSch
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
at akka.actor.ActorCell.invoke(ActorCell.scala:456)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
at akka.dispatch.Mailbox.run(Mailbox.scala:219) in 2646 ms on
localhost (progress: 345/345)
at
akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at
scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)ed in
528.389 s
at
scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)ed,
from pool
at
scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at
scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Any help here?
PS. any one knows the *constructor function* of the model assuming you have
weights and intercept?
--
View this message in context:
http://apache-spark-user-list.1001560.n3.nabble.com/How-to-save-mllib-model-to-hdfs-and-reload-it-tp11953p12030.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]