Skip to content

Commit 814b3da

Browse files
selvinsourcemengxr
authored andcommitted
[SPARK-7272] [MLLIB] User guide for PMML model export
https://issues.apache.org/jira/browse/SPARK-7272 Author: Vincenzo Selvaggio <[email protected]> Closes apache#6219 from selvinsource/mllib_pmml_model_export_SPARK-7272 and squashes the following commits: c866fb8 [Vincenzo Selvaggio] Update mllib-pmml-model-export.md 1beda98 [Vincenzo Selvaggio] [SPARK-7272] Initial user guide for pmml export d670662 [Vincenzo Selvaggio] Update mllib-pmml-model-export.md 2731375 [Vincenzo Selvaggio] Update mllib-pmml-model-export.md 680dc33 [Vincenzo Selvaggio] Update mllib-pmml-model-export.md 2e298b5 [Vincenzo Selvaggio] Update mllib-pmml-model-export.md a932f51 [Vincenzo Selvaggio] Create mllib-pmml-model-export.md
1 parent 1ecfac6 commit 814b3da

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

docs/mllib-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ filtering, dimensionality reduction, as well as underlying optimization primitiv
3939
* [Optimization (developer)](mllib-optimization.html)
4040
* stochastic gradient descent
4141
* limited-memory BFGS (L-BFGS)
42+
* [PMML model export](mllib-pmml-model-export.html)
4243

4344
MLlib is under active development.
4445
The APIs marked `Experimental`/`DeveloperApi` may change in future releases,

docs/mllib-pmml-model-export.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
layout: global
3+
title: PMML model export - MLlib
4+
displayTitle: <a href="mllib-guide.html">MLlib</a> - PMML model export
5+
---
6+
7+
* Table of contents
8+
{:toc}
9+
10+
## MLlib supported models
11+
12+
MLlib supports model export to Predictive Model Markup Language ([PMML](http://en.wikipedia.org/wiki/Predictive_Model_Markup_Language)).
13+
14+
The table below outlines the MLlib models that can be exported to PMML and their equivalent PMML model.
15+
16+
<table class="table">
17+
<thead>
18+
<tr><th>MLlib model</th><th>PMML model</th></tr>
19+
</thead>
20+
<tbody>
21+
<tr>
22+
<td>KMeansModel</td><td>ClusteringModel</td>
23+
</tr>
24+
<tr>
25+
<td>LinearRegressionModel</td><td>RegressionModel (functionName="regression")</td>
26+
</tr>
27+
<tr>
28+
<td>RidgeRegressionModel</td><td>RegressionModel (functionName="regression")</td>
29+
</tr>
30+
<tr>
31+
<td>LassoModel</td><td>RegressionModel (functionName="regression")</td>
32+
</tr>
33+
<tr>
34+
<td>SVMModel</td><td>RegressionModel (functionName="classification" normalizationMethod="none")</td>
35+
</tr>
36+
<tr>
37+
<td>Binary LogisticRegressionModel</td><td>RegressionModel (functionName="classification" normalizationMethod="logit")</td>
38+
</tr>
39+
</tbody>
40+
</table>
41+
42+
## Examples
43+
<div class="codetabs">
44+
45+
<div data-lang="scala" markdown="1">
46+
To export a supported `model` (see table above) to PMML, simply call `model.toPMML`.
47+
48+
Here a complete example of building a KMeansModel and print it out in PMML format:
49+
{% highlight scala %}
50+
import org.apache.spark.mllib.clustering.KMeans
51+
import org.apache.spark.mllib.linalg.Vectors
52+
53+
// Load and parse the data
54+
val data = sc.textFile("data/mllib/kmeans_data.txt")
55+
val parsedData = data.map(s => Vectors.dense(s.split(' ').map(_.toDouble))).cache()
56+
57+
// Cluster the data into two classes using KMeans
58+
val numClusters = 2
59+
val numIterations = 20
60+
val clusters = KMeans.train(parsedData, numClusters, numIterations)
61+
62+
// Export to PMML
63+
println("PMML Model:\n" + clusters.toPMML)
64+
{% endhighlight %}
65+
66+
As well as exporting the PMML model to a String (`model.toPMML` as in the example above), you can export the PMML model to other formats:
67+
68+
{% highlight scala %}
69+
// Export the model to a String in PMML format
70+
clusters.toPMML
71+
72+
// Export the model to a local file in PMML format
73+
clusters.toPMML("/tmp/kmeans.xml")
74+
75+
// Export the model to a directory on a distributed file system in PMML format
76+
clusters.toPMML(sc,"/tmp/kmeans")
77+
78+
// Export the model to the OutputStream in PMML format
79+
clusters.toPMML(System.out)
80+
{% endhighlight %}
81+
82+
For unsupported models, either you will not find a `.toPMML` method or an `IllegalArgumentException` will be thrown.
83+
84+
</div>
85+
86+
</div>

0 commit comments

Comments
 (0)