You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Sameer Tilak <ss...@live.com> on 2014/12/03 19:12:25 UTC

MLLib: loading saved model

Hi All,I am using LinearRegressionWithSGD and then I save the model weights and intercept. File that contains weights have this format:
1.204550.13560.000456......
Intercept is 0 since I am using train not setting the intercept so it can be ignored for the moment. I would now like to initialize a new model object and using these saved weights from the above file. We are using CDH 5.1
Something along these lines:
val weights = sc.textFile("linear-weights");val model = new LinearRegressionWithSGD(weights);
then use is as:
val valuesAndPreds = testData.map { point =>  val prediction = model.predict(point.features)  (point.label, prediction)}

Any pointers to how do I do that?

 		 	   		  

Re: MLLib: loading saved model

Posted by manish_k <ma...@sigmoidanalytics.com>.
Hi Sameer,

Your model recreation should be:

val model = new LinearRegressionModel(weights, intercept)

As you have already got weights for linear regression model using stochastic
gradient descent, you just have to use LinearRegressionModel to construct
new model. Other points to notice is that weights should be in vector format
so you have to convert weights to vector after reading from file and your
intercept will be 0.0 as you mentioned.

Regards,
Manish



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/MLLib-loading-saved-model-tp20281p20354.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org