@@ -202,10 +202,8 @@ RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
202
202
203
203
<div data-lang =" python " >
204
204
205
- Note that the Python API does not yet support model save/load but will in the future.
206
-
207
205
{% highlight python %}
208
- from pyspark.mllib.tree import RandomForest
206
+ from pyspark.mllib.tree import RandomForest, RandomForestModel
209
207
from pyspark.mllib.util import MLUtils
210
208
211
209
# 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
228
226
print('Test Error = ' + str(testErr))
229
227
print('Learned classification forest model:')
230
228
print(model.toDebugString())
229
+
230
+ # Save and load model
231
+ model.save(sc, "myModelPath")
232
+ sameModel = RandomForestModel.load(sc, "myModelPath)
231
233
{% endhighlight %}
232
234
</div >
233
235
@@ -354,10 +356,8 @@ RandomForestModel sameModel = RandomForestModel.load(sc.sc(), "myModelPath");
354
356
355
357
<div data-lang =" python " >
356
358
357
- Note that the Python API does not yet support model save/load but will in the future.
358
-
359
359
{% highlight python %}
360
- from pyspark.mllib.tree import RandomForest
360
+ from pyspark.mllib.tree import RandomForest, RandomForestModel
361
361
from pyspark.mllib.util import MLUtils
362
362
363
363
# 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
380
380
print('Test Mean Squared Error = ' + str(testMSE))
381
381
print('Learned regression forest model:')
382
382
print(model.toDebugString())
383
+
384
+ # Save and load model
385
+ model.save(sc, "myModelPath")
386
+ sameModel = RandomForestModel.load(sc, "myModelPath)
383
387
{% endhighlight %}
384
388
</div >
385
389
@@ -581,10 +585,8 @@ GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "m
581
585
582
586
<div data-lang =" python " >
583
587
584
- Note that the Python API does not yet support model save/load but will in the future.
585
-
586
588
{% highlight python %}
587
- from pyspark.mllib.tree import GradientBoostedTrees
589
+ from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
588
590
from pyspark.mllib.util import MLUtils
589
591
590
592
# Load and parse the data file.
@@ -605,6 +607,10 @@ testErr = labelsAndPredictions.filter(lambda (v, p): v != p).count() / float(tes
605
607
print('Test Error = ' + str(testErr))
606
608
print('Learned classification GBT model:')
607
609
print(model.toDebugString())
610
+
611
+ # Save and load model
612
+ model.save(sc, "myModelPath")
613
+ sameModel = GradientBoostedTreesModel.load(sc, "myModelPath)
608
614
{% endhighlight %}
609
615
</div >
610
616
@@ -732,10 +738,8 @@ GradientBoostedTreesModel sameModel = GradientBoostedTreesModel.load(sc.sc(), "m
732
738
733
739
<div data-lang =" python " >
734
740
735
- Note that the Python API does not yet support model save/load but will in the future.
736
-
737
741
{% highlight python %}
738
- from pyspark.mllib.tree import GradientBoostedTrees
742
+ from pyspark.mllib.tree import GradientBoostedTrees, GradientBoostedTreesModel
739
743
from pyspark.mllib.util import MLUtils
740
744
741
745
# Load and parse the data file.
@@ -756,6 +760,10 @@ testMSE = labelsAndPredictions.map(lambda (v, p): (v - p) * (v - p)).sum() / flo
756
760
print('Test Mean Squared Error = ' + str(testMSE))
757
761
print('Learned regression GBT model:')
758
762
print(model.toDebugString())
763
+
764
+ # Save and load model
765
+ model.save(sc, "myModelPath")
766
+ sameModel = GradientBoostedTreesModel.load(sc, "myModelPath)
759
767
{% endhighlight %}
760
768
</div >
761
769
0 commit comments