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
5 changes: 5 additions & 0 deletions docs/ml-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,11 @@ for (Row r: predictions.select("id", "text", "probability", "prediction").collec
{% endhighlight %}
</div>

<div data-lang="python">

{% include_example python/ml/cross_validator.py %}
</div>

</div>

## Example: model selection via train validation split
Expand Down
5 changes: 4 additions & 1 deletion examples/src/main/python/ml/cross_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
from __future__ import print_function

from pyspark import SparkContext
# $example on$
from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.evaluation import BinaryClassificationEvaluator
from pyspark.ml.feature import HashingTF, Tokenizer
from pyspark.ml.tuning import CrossValidator, ParamGridBuilder
from pyspark.sql import Row, SQLContext
# $example off$

"""
A simple example demonstrating model selection using CrossValidator.
Expand All @@ -36,7 +38,7 @@
if __name__ == "__main__":
sc = SparkContext(appName="CrossValidatorExample")
sqlContext = SQLContext(sc)

# $example on$
# Prepare training documents, which are labeled.
LabeledDocument = Row("id", "text", "label")
training = sc.parallelize([(0, "a b c d e spark", 1.0),
Expand Down Expand Up @@ -92,5 +94,6 @@
selected = prediction.select("id", "text", "probability", "prediction")
for row in selected.collect():
print(row)
# $example off$

sc.stop()