Skip to content

Commit 83d369d

Browse files
committed
added comment to save,load parts of ML guide examples
1 parent 2841170 commit 83d369d

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

docs/mllib-collaborative-filtering.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ val MSE = ratesAndPreds.map { case ((user, product), (r1, r2)) =>
9797
}.mean()
9898
println("Mean Squared Error = " + MSE)
9999

100+
// Save and load model
100101
model.save(sc, "myModelPath")
101102
val sameModel = MatrixFactorizationModel.load(sc, "myModelPath")
102103
{% endhighlight %}
@@ -186,6 +187,7 @@ public class CollaborativeFiltering {
186187
).rdd()).mean();
187188
System.out.println("Mean Squared Error = " + MSE);
188189

190+
// Save and load model
189191
model.save(sc.sc(), "myModelPath");
190192
MatrixFactorizationModel sameModel = MatrixFactorizationModel.load(sc.sc(), "myModelPath");
191193
}

docs/mllib-decision-tree.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
223223
println("Test Error = " + testErr)
224224
println("Learned classification tree model:\n" + model.toDebugString)
225225

226+
// Save and load model
226227
model.save(sc, "myModelPath")
227228
val sameModel = DecisionTreeModel.load(sc, "myModelPath")
228229
{% endhighlight %}
@@ -284,6 +285,7 @@ Double testErr =
284285
System.out.println("Test Error: " + testErr);
285286
System.out.println("Learned classification tree model:\n" + model.toDebugString());
286287

288+
// Save and load model
287289
model.save(sc.sc(), "myModelPath");
288290
DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
289291
{% endhighlight %}
@@ -362,6 +364,7 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
362364
println("Test Mean Squared Error = " + testMSE)
363365
println("Learned regression tree model:\n" + model.toDebugString)
364366

367+
// Save and load model
365368
model.save(sc, "myModelPath")
366369
val sameModel = DecisionTreeModel.load(sc, "myModelPath")
367370
{% endhighlight %}
@@ -429,6 +432,7 @@ Double testMSE =
429432
System.out.println("Test Mean Squared Error: " + testMSE);
430433
System.out.println("Learned regression tree model:\n" + model.toDebugString());
431434

435+
// Save and load model
432436
model.save(sc.sc(), "myModelPath");
433437
DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
434438
{% endhighlight %}

docs/mllib-ensembles.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
129129
println("Test Error = " + testErr)
130130
println("Learned classification forest model:\n" + model.toDebugString)
131131

132+
// Save and load model
132133
model.save(sc, "myModelPath")
133134
val sameModel = RandomForestModel.load(sc, "myModelPath")
134135
{% endhighlight %}
@@ -193,6 +194,7 @@ Double testErr =
193194
System.out.println("Test Error: " + testErr);
194195
System.out.println("Learned classification forest model:\n" + model.toDebugString());
195196

197+
// Save and load model
196198
model.save(sc.sc(), "myModelPath");
197199
RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
198200
{% endhighlight %}
@@ -276,6 +278,7 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
276278
println("Test Mean Squared Error = " + testMSE)
277279
println("Learned regression forest model:\n" + model.toDebugString)
278280

281+
// Save and load model
279282
model.save(sc, "myModelPath")
280283
val sameModel = RandomForestModel.load(sc, "myModelPath")
281284
{% endhighlight %}
@@ -343,6 +346,7 @@ Double testMSE =
343346
System.out.println("Test Mean Squared Error: " + testMSE);
344347
System.out.println("Learned regression forest model:\n" + model.toDebugString());
345348

349+
// Save and load model
346350
model.save(sc.sc(), "myModelPath");
347351
RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
348352
{% endhighlight %}
@@ -504,6 +508,7 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
504508
println("Test Error = " + testErr)
505509
println("Learned classification GBT model:\n" + model.toDebugString)
506510

511+
// Save and load model
507512
model.save(sc, "myModelPath")
508513
val sameModel = GradientBoostedTreesModel.load(sc, "myModelPath")
509514
{% endhighlight %}
@@ -568,6 +573,7 @@ Double testErr =
568573
System.out.println("Test Error: " + testErr);
569574
System.out.println("Learned classification GBT model:\n" + model.toDebugString());
570575

576+
// Save and load model
571577
model.save(sc.sc(), "myModelPath");
572578
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "myModelPath");
573579
{% endhighlight %}
@@ -647,6 +653,7 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
647653
println("Test Mean Squared Error = " + testMSE)
648654
println("Learned regression GBT model:\n" + model.toDebugString)
649655

656+
// Save and load model
650657
model.save(sc, "myModelPath")
651658
val sameModel = GradientBoostedTreesModel.load(sc, "myModelPath")
652659
{% endhighlight %}
@@ -717,6 +724,7 @@ Double testMSE =
717724
System.out.println("Test Mean Squared Error: " + testMSE);
718725
System.out.println("Learned regression GBT model:\n" + model.toDebugString());
719726

727+
// Save and load model
720728
model.save(sc.sc(), "myModelPath");
721729
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "myModelPath");
722730
{% endhighlight %}

docs/mllib-linear-methods.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ val auROC = metrics.areaUnderROC()
223223

224224
println("Area under ROC = " + auROC)
225225

226+
// Save and load model
226227
model.save(sc, "myModelPath")
227228
val sameModel = SVMModel.load(sc, "myModelPath")
228229
{% endhighlight %}
@@ -308,6 +309,7 @@ public class SVMClassifier {
308309

309310
System.out.println("Area under ROC = " + auROC);
310311

312+
// Save and load model
311313
model.save(sc.sc(), "myModelPath");
312314
SVMModel sameModel = SVMModel.load(sc.sc(), "myModelPath");
313315
}
@@ -423,6 +425,7 @@ val valuesAndPreds = parsedData.map { point =>
423425
val MSE = valuesAndPreds.map{case(v, p) => math.pow((v - p), 2)}.mean()
424426
println("training Mean Squared Error = " + MSE)
425427

428+
// Save and load model
426429
model.save(sc, "myModelPath")
427430
val sameModel = LinearRegressionModel.load(sc, "myModelPath")
428431
{% endhighlight %}
@@ -496,6 +499,7 @@ public class LinearRegression {
496499
).rdd()).mean();
497500
System.out.println("training Mean Squared Error = " + MSE);
498501

502+
// Save and load model
499503
model.save(sc.sc(), "myModelPath");
500504
LinearRegressionModel sameModel = LinearRegressionModel.load(sc.sc(), "myModelPath");
501505
}

docs/mllib-naive-bayes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ val model = NaiveBayes.train(training, lambda = 1.0)
5656
val predictionAndLabel = test.map(p => (model.predict(p.features), p.label))
5757
val accuracy = 1.0 * predictionAndLabel.filter(x => x._1 == x._2).count() / test.count()
5858

59+
// Save and load model
5960
model.save(sc, "myModelPath")
6061
val sameModel = NaiveBayesModel.load(sc, "myModelPath")
6162
{% endhighlight %}
@@ -97,6 +98,7 @@ double accuracy = predictionAndLabel.filter(new Function<Tuple2<Double, Double>,
9798
}
9899
}).count() / (double) test.count();
99100

101+
// Save and load model
100102
model.save(sc.sc(), "myModelPath");
101103
NaiveBayesModel sameModel = NaiveBayesModel.load(sc.sc(), "myModelPath");
102104
{% endhighlight %}

0 commit comments

Comments
 (0)