Skip to content

Commit 201b3b9

Browse files
committed
update user guide
1 parent b5158e2 commit 201b3b9

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

docs/mllib-decision-tree.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,9 @@ DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
293293

294294
<div data-lang="python">
295295

296-
Note that the Python API does not yet support model save/load but will in the future.
297-
298296
{% highlight python %}
299297
from pyspark.mllib.regression import LabeledPoint
300-
from pyspark.mllib.tree import DecisionTree
298+
from pyspark.mllib.tree import DecisionTree, DecisionTreeModel
301299
from pyspark.mllib.util import MLUtils
302300

303301
# Load and parse the data file into an RDD of LabeledPoint.
@@ -317,6 +315,10 @@ testErr = labelsAndPredictions.filter(lambda (v, p): v != p).count() / float(tes
317315
print('Test Error = ' + str(testErr))
318316
print('Learned classification tree model:')
319317
print(model.toDebugString())
318+
319+
# Save and load model
320+
model.save(sc, "myModelPath")
321+
sameModel = DecisionTreeModel.load(sc, "myModelPath)
320322
{% endhighlight %}
321323
</div>
322324

@@ -440,11 +442,9 @@ DecisionTreeModel sameModel = DecisionTreeModel.load(sc.sc(), "myModelPath");
440442

441443
<div data-lang="python">
442444

443-
Note that the Python API does not yet support model save/load but will in the future.
444-
445445
{% highlight python %}
446446
from pyspark.mllib.regression import LabeledPoint
447-
from pyspark.mllib.tree import DecisionTree
447+
from pyspark.mllib.tree import DecisionTree, DecisionTreeModel
448448
from pyspark.mllib.util import MLUtils
449449

450450
# Load and parse the data file into an RDD of LabeledPoint.
@@ -464,6 +464,10 @@ testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() / flo
464464
print('Test Mean Squared Error = ' + str(testMSE))
465465
print('Learned regression tree model:')
466466
print(model.toDebugString())
467+
468+
# Save and load model
469+
model.save(sc, "myModelPath")
470+
sameModel = DecisionTreeModel.load(sc, "myModelPath)
467471
{% endhighlight %}
468472
</div>
469473

docs/mllib-ensembles.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,8 @@ RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
202202

203203
<div data-lang="python">
204204

205-
Note that the Python API does not yet support model save/load but will in the future.
206-
207205
{% highlight python %}
208-
from pyspark.mllib.tree import RandomForest
206+
from pyspark.mllib.tree import RandomForest, RandomForestModel
209207
from pyspark.mllib.util import MLUtils
210208

211209
# Load and parse the data file into an RDD of LabeledPoint.
@@ -228,6 +226,10 @@ testErr = labelsAndPredictions.filter(lambda (v, p): v != p).count() / float(tes
228226
print('Test Error = ' + str(testErr))
229227
print('Learned classification forest model:')
230228
print(model.toDebugString())
229+
230+
# Save and load model
231+
model.save(sc, "myModelPath")
232+
sameModel = RandomForestModel.load(sc, "myModelPath)
231233
{% endhighlight %}
232234
</div>
233235

@@ -354,10 +356,8 @@ RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
354356

355357
<div data-lang="python">
356358

357-
Note that the Python API does not yet support model save/load but will in the future.
358-
359359
{% highlight python %}
360-
from pyspark.mllib.tree import RandomForest
360+
from pyspark.mllib.tree import RandomForest, RandomForestModel
361361
from pyspark.mllib.util import MLUtils
362362

363363
# Load and parse the data file into an RDD of LabeledPoint.
@@ -380,6 +380,10 @@ testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() / flo
380380
print('Test Mean Squared Error = ' + str(testMSE))
381381
print('Learned regression forest model:')
382382
print(model.toDebugString())
383+
384+
# Save and load model
385+
model.save(sc, "myModelPath")
386+
sameModel = RandomForestModel.load(sc, "myModelPath)
383387
{% endhighlight %}
384388
</div>
385389

@@ -581,10 +585,8 @@ GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "m
581585

582586
<div data-lang="python">
583587

584-
Note that the Python API does not yet support model save/load but will in the future.
585-
586588
{% highlight python %}
587-
from pyspark.mllib.tree import GradientBoostedTrees
589+
from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
588590
from pyspark.mllib.util import MLUtils
589591

590592
# Load and parse the data file.
@@ -605,6 +607,10 @@ testErr = labelsAndPredictions.filter(lambda (v, p): v != p).count() / float(tes
605607
print('Test Error = ' + str(testErr))
606608
print('Learned classification GBT model:')
607609
print(model.toDebugString())
610+
611+
# Save and load model
612+
model.save(sc, "myModelPath")
613+
sameModel = GradientBoostedTreesModel.load(sc, "myModelPath)
608614
{% endhighlight %}
609615
</div>
610616

@@ -732,10 +738,8 @@ GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "m
732738

733739
<div data-lang="python">
734740

735-
Note that the Python API does not yet support model save/load but will in the future.
736-
737741
{% highlight python %}
738-
from pyspark.mllib.tree import GradientBoostedTrees
742+
from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
739743
from pyspark.mllib.util import MLUtils
740744

741745
# Load and parse the data file.
@@ -756,6 +760,10 @@ testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() / flo
756760
print('Test Mean Squared Error = ' + str(testMSE))
757761
print('Learned regression GBT model:')
758762
print(model.toDebugString())
763+
764+
# Save and load model
765+
model.save(sc, "myModelPath")
766+
sameModel = GradientBoostedTreesModel.load(sc, "myModelPath)
759767
{% endhighlight %}
760768
</div>
761769

0 commit comments

Comments
 (0)