diff options
author | Xiangrui Meng <meng@databricks.com> | 2015-03-17 12:14:40 -0700 |
---|---|---|
committer | Xiangrui Meng <meng@databricks.com> | 2015-03-17 12:14:40 -0700 |
commit | c94d0626471e209ab7ebfc588f9a2992946b7ed5 (patch) | |
tree | b5025c4412aac661e915fe25f3f0a9aaaa371a50 /mllib/src/main | |
parent | d9f3e01688ad0a8d5fc2419a948a682ad7d957c9 (diff) | |
download | spark-c94d0626471e209ab7ebfc588f9a2992946b7ed5.tar.gz spark-c94d0626471e209ab7ebfc588f9a2992946b7ed5.tar.bz2 spark-c94d0626471e209ab7ebfc588f9a2992946b7ed5.zip |
[SPARK-6226][MLLIB] add save/load in PySpark's KMeansModel
Use `_py2java` and `_java2py` to convert Python model to/from Java model. yinxusen
Author: Xiangrui Meng <meng@databricks.com>
Closes #5049 from mengxr/SPARK-6226-mengxr and squashes the following commits:
570ba81 [Xiangrui Meng] fix python style
b10b911 [Xiangrui Meng] add save/load in PySpark's KMeansModel
Diffstat (limited to 'mllib/src/main')
-rw-r--r-- | mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala b/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala index 707da537d2..e4e411a3c8 100644 --- a/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala +++ b/mllib/src/main/scala/org/apache/spark/mllib/clustering/KMeansModel.scala @@ -17,6 +17,8 @@ package org.apache.spark.mllib.clustering +import scala.collection.JavaConverters._ + import org.json4s._ import org.json4s.JsonDSL._ import org.json4s.jackson.JsonMethods._ @@ -34,6 +36,9 @@ import org.apache.spark.sql.Row */ class KMeansModel (val clusterCenters: Array[Vector]) extends Saveable with Serializable { + /** A Java-friendly constructor that takes an Iterable of Vectors. */ + def this(centers: java.lang.Iterable[Vector]) = this(centers.asScala.toArray) + /** Total number of clusters. */ def k: Int = clusterCenters.length |