aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/python/mllib/isotonic_regression_example.py
diff options
context:
space:
mode:
authorWeichenXu <WeichenXu123@outlook.com>2016-06-16 17:35:40 -0700
committerYanbo Liang <ybliang8@gmail.com>2016-06-16 17:35:40 -0700
commit9040d83bc2cdce06dab0e1bdee4f796da9a9a55c (patch)
tree1d13dfa807220fb5d796d23f3e1d60802f680b2b /examples/src/main/python/mllib/isotonic_regression_example.py
parentd9c6628c47de547dc537310e3c775c7f3e0e4a12 (diff)
downloadspark-9040d83bc2cdce06dab0e1bdee4f796da9a9a55c.tar.gz
spark-9040d83bc2cdce06dab0e1bdee4f796da9a9a55c.tar.bz2
spark-9040d83bc2cdce06dab0e1bdee4f796da9a9a55c.zip
[SPARK-15608][ML][EXAMPLES][DOC] add examples and documents of ml.isotonic regression
## What changes were proposed in this pull request? add ml doc for ml isotonic regression add scala example for ml isotonic regression add java example for ml isotonic regression add python example for ml isotonic regression modify scala example for mllib isotonic regression modify java example for mllib isotonic regression modify python example for mllib isotonic regression add data/mllib/sample_isotonic_regression_libsvm_data.txt delete data/mllib/sample_isotonic_regression_data.txt ## How was this patch tested? N/A Author: WeichenXu <WeichenXu123@outlook.com> Closes #13381 from WeichenXu123/add_isotonic_regression_doc.
Diffstat (limited to 'examples/src/main/python/mllib/isotonic_regression_example.py')
-rw-r--r--examples/src/main/python/mllib/isotonic_regression_example.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/examples/src/main/python/mllib/isotonic_regression_example.py b/examples/src/main/python/mllib/isotonic_regression_example.py
index 89dc9f4b66..33d618ab48 100644
--- a/examples/src/main/python/mllib/isotonic_regression_example.py
+++ b/examples/src/main/python/mllib/isotonic_regression_example.py
@@ -23,7 +23,8 @@ from __future__ import print_function
from pyspark import SparkContext
# $example on$
import math
-from pyspark.mllib.regression import IsotonicRegression, IsotonicRegressionModel
+from pyspark.mllib.regression import LabeledPoint, IsotonicRegression, IsotonicRegressionModel
+from pyspark.mllib.util import MLUtils
# $example off$
if __name__ == "__main__":
@@ -31,10 +32,14 @@ if __name__ == "__main__":
sc = SparkContext(appName="PythonIsotonicRegressionExample")
# $example on$
- data = sc.textFile("data/mllib/sample_isotonic_regression_data.txt")
+ # Load and parse the data
+ def parsePoint(labeledData):
+ return (labeledData.label, labeledData.features[0], 1.0)
+
+ data = MLUtils.loadLibSVMFile(sc, "data/mllib/sample_isotonic_regression_libsvm_data.txt")
# Create label, feature, weight tuples from input data with weight set to default value 1.0.
- parsedData = data.map(lambda line: tuple([float(x) for x in line.split(',')]) + (1.0,))
+ parsedData = data.map(parsePoint)
# Split data into training (60%) and test (40%) sets.
training, test = parsedData.randomSplit([0.6, 0.4], 11)