aboutsummaryrefslogtreecommitdiff
path: root/docs/mllib-feature-extraction.md
diff options
context:
space:
mode:
authorMechCoder <manojkumarsivaraj334@gmail.com>2015-06-17 22:08:38 -0700
committerDavies Liu <davies@databricks.com>2015-06-17 22:08:38 -0700
commit22732e1eca730929345e440ba831386ee7446b74 (patch)
treebdd891792462222c50ebd324efb154980c320d5a /docs/mllib-feature-extraction.md
parent4817ccdf50ef6ee24192800f9924d9ef3bb74e12 (diff)
downloadspark-22732e1eca730929345e440ba831386ee7446b74.tar.gz
spark-22732e1eca730929345e440ba831386ee7446b74.tar.bz2
spark-22732e1eca730929345e440ba831386ee7446b74.zip
[SPARK-7605] [MLLIB] [PYSPARK] Python API for ElementwiseProduct
Python API for org.apache.spark.mllib.feature.ElementwiseProduct Author: MechCoder <manojkumarsivaraj334@gmail.com> Closes #6346 from MechCoder/spark-7605 and squashes the following commits: 79d1ef5 [MechCoder] Consistent and support list / array types 5f81d81 [MechCoder] [SPARK-7605] [MLlib] Python API for ElementwiseProduct
Diffstat (limited to 'docs/mllib-feature-extraction.md')
-rw-r--r--docs/mllib-feature-extraction.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/docs/mllib-feature-extraction.md b/docs/mllib-feature-extraction.md
index 4fe470a8de..1197dbbb8d 100644
--- a/docs/mllib-feature-extraction.md
+++ b/docs/mllib-feature-extraction.md
@@ -560,6 +560,28 @@ JavaRDD<Vector> transformedData2 = data.map(
{% endhighlight %}
</div>
+
+<div data-lang="python">
+{% highlight python %}
+from pyspark import SparkContext
+from pyspark.mllib.linalg import Vectors
+from pyspark.mllib.feature import ElementwiseProduct
+
+# Load and parse the data
+sc = SparkContext()
+data = sc.textFile("data/mllib/kmeans_data.txt")
+parsedData = data.map(lambda x: [float(t) for t in x.split(" ")])
+
+# Create weight vector.
+transformingVector = Vectors.dense([0.0, 1.0, 2.0])
+transformer = ElementwiseProduct(transformingVector)
+
+# Batch transform.
+transformedData = transformer.transform(parsedData)
+transformedData2 = transformer.transform(parsedData.first())
+
+{% endhighlight %}
+</div>
</div>