title: MLLIb: Saving and loading a model
body: <p>I'm using <code>LinearRegressionWithSGD</code> and then I save the model weights and intercept. </p>
  
  <p>File that contains weights has this format:</p>
  
  <pre><code>1.20455
  0.1356
  0.000456
  </code></pre>
  
  <p>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</p>
  
  <p>Something along these lines:</p>
  
  <pre><code>// Here is the code the load data and train the model on it.
  val weights = sc.textFile("linear-weights");
  val model = new LinearRegressionWithSGD(weights);
  </code></pre>
  
  <p>then use is as:</p>
  
  <pre><code>// Here is where I want to use the trained model to predict on new data.
  val valuesAndPreds = testData.map { point =&gt;
    // Predicting on new data.
    val prediction = model.predict(point.features)
    (point.label, prediction)
  }
  </code></pre>
  
  <p>Any pointers to how do I do that?</p>