Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/mllib-collaborative-filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ val MSE = ratesAndPreds.map { case ((user, product), (r1, r2)) =>
}.mean()
println("Mean Squared Error = " + MSE)

model.save("myModelPath")
val sameModel = MatrixFactorizationModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = MatrixFactorizationModel.load(sc, "myModelPath")
{% endhighlight %}

If the rating matrix is derived from another source of information (e.g., it is inferred from
Expand Down Expand Up @@ -186,8 +187,9 @@ public class CollaborativeFiltering {
).rdd()).mean();
System.out.println("Mean Squared Error = " + MSE);

model.save("myModelPath");
MatrixFactorizationModel sameModel = MatrixFactorizationModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
MatrixFactorizationModel sameModel = MatrixFactorizationModel.load(sc.sc(), "myModelPath");
}
}
{% endhighlight %}
Expand Down
20 changes: 12 additions & 8 deletions docs/mllib-decision-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
println("Test Error = " + testErr)
println("Learned classification tree model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = DecisionTreeModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = DecisionTreeModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -284,8 +285,9 @@ Double testErr =
System.out.println("Test Error: " + testErr);
System.out.println("Learned classification tree model:\n" + model.toDebugString());

model.save("myModelPath");
DecisionTreeModel sameModel = DecisionTreeModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down Expand Up @@ -362,8 +364,9 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
println("Test Mean Squared Error = " + testMSE)
println("Learned regression tree model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = DecisionTreeModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = DecisionTreeModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -429,8 +432,9 @@ Double testMSE =
System.out.println("Test Mean Squared Error: " + testMSE);
System.out.println("Learned regression tree model:\n" + model.toDebugString());

model.save("myModelPath");
DecisionTreeModel sameModel = DecisionTreeModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down
40 changes: 24 additions & 16 deletions docs/mllib-ensembles.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
println("Test Error = " + testErr)
println("Learned classification forest model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = RandomForestModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = RandomForestModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -193,8 +194,9 @@ Double testErr =
System.out.println("Test Error: " + testErr);
System.out.println("Learned classification forest model:\n" + model.toDebugString());

model.save("myModelPath");
RandomForestModel sameModel = RandomForestModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down Expand Up @@ -276,8 +278,9 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
println("Test Mean Squared Error = " + testMSE)
println("Learned regression forest model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = RandomForestModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = RandomForestModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -343,8 +346,9 @@ Double testMSE =
System.out.println("Test Mean Squared Error: " + testMSE);
System.out.println("Learned regression forest model:\n" + model.toDebugString());

model.save("myModelPath");
RandomForestModel sameModel = RandomForestModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down Expand Up @@ -504,8 +508,9 @@ val testErr = labelAndPreds.filter(r => r._1 != r._2).count.toDouble / testData.
println("Test Error = " + testErr)
println("Learned classification GBT model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = GradientBoostedTreesModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = GradientBoostedTreesModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -568,8 +573,9 @@ Double testErr =
System.out.println("Test Error: " + testErr);
System.out.println("Learned classification GBT model:\n" + model.toDebugString());

model.save("myModelPath");
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down Expand Up @@ -647,8 +653,9 @@ val testMSE = labelsAndPredictions.map{ case(v, p) => math.pow((v - p), 2)}.mean
println("Test Mean Squared Error = " + testMSE)
println("Learned regression GBT model:\n" + model.toDebugString)

model.save("myModelPath")
val sameModel = GradientBoostedTreesModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = GradientBoostedTreesModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -717,8 +724,9 @@ Double testMSE =
System.out.println("Test Mean Squared Error: " + testMSE);
System.out.println("Learned regression GBT model:\n" + model.toDebugString());

model.save("myModelPath");
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down
20 changes: 12 additions & 8 deletions docs/mllib-linear-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ val auROC = metrics.areaUnderROC()

println("Area under ROC = " + auROC)

model.save("myModelPath")
val sameModel = SVMModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = SVMModel.load(sc, "myModelPath")
{% endhighlight %}

The `SVMWithSGD.train()` method by default performs L2 regularization with the
Expand Down Expand Up @@ -308,8 +309,9 @@ public class SVMClassifier {

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

model.save("myModelPath");
SVMModel sameModel = SVMModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
SVMModel sameModel = SVMModel.load(sc.sc(), "myModelPath");
}
}
{% endhighlight %}
Expand Down Expand Up @@ -423,8 +425,9 @@ val valuesAndPreds = parsedData.map { point =>
val MSE = valuesAndPreds.map{case(v, p) => math.pow((v - p), 2)}.mean()
println("training Mean Squared Error = " + MSE)

model.save("myModelPath")
val sameModel = LinearRegressionModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = LinearRegressionModel.load(sc, "myModelPath")
{% endhighlight %}

[`RidgeRegressionWithSGD`](api/scala/index.html#org.apache.spark.mllib.regression.RidgeRegressionWithSGD)
Expand Down Expand Up @@ -496,8 +499,9 @@ public class LinearRegression {
).rdd()).mean();
System.out.println("training Mean Squared Error = " + MSE);

model.save("myModelPath");
LinearRegressionModel sameModel = LinearRegressionModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
LinearRegressionModel sameModel = LinearRegressionModel.load(sc.sc(), "myModelPath");
}
}
{% endhighlight %}
Expand Down
10 changes: 6 additions & 4 deletions docs/mllib-naive-bayes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ val model = NaiveBayes.train(training, lambda = 1.0)
val predictionAndLabel = test.map(p => (model.predict(p.features), p.label))
val accuracy = 1.0 * predictionAndLabel.filter(x => x._1 == x._2).count() / test.count()

model.save("myModelPath")
val sameModel = NaiveBayesModel.load("myModelPath")
// Save and load model
model.save(sc, "myModelPath")
val sameModel = NaiveBayesModel.load(sc, "myModelPath")
{% endhighlight %}
</div>

Expand Down Expand Up @@ -97,8 +98,9 @@ double accuracy = predictionAndLabel.filter(new Function<Tuple2<Double, Double>,
}
}).count() / (double) test.count();

model.save("myModelPath");
NaiveBayesModel sameModel = NaiveBayesModel.load("myModelPath");
// Save and load model
model.save(sc.sc(), "myModelPath");
NaiveBayesModel sameModel = NaiveBayesModel.load(sc.sc(), "myModelPath");
{% endhighlight %}
</div>

Expand Down