@@ -22,9 +22,8 @@ import org.json4s.JsonDSL._
2222import org .json4s .jackson .JsonMethods ._
2323
2424import org .apache .spark .api .java .JavaRDD
25- import org .apache .spark .mllib .linalg ._
25+ import org .apache .spark .mllib .linalg .Vector
2626import org .apache .spark .mllib .util .{Loader , Saveable }
27- import org .apache .spark .mllib .util .Loader ._
2827import org .apache .spark .rdd .RDD
2928import org .apache .spark .SparkContext
3029import org .apache .spark .sql .SQLContext
@@ -79,11 +78,11 @@ object KMeansModel extends Loader[KMeansModel] {
7978 KMeansModel .SaveLoadV1_0 .load(sc, path)
8079 }
8180
82- case class IndexedPoint (id : Int , point : Vector )
81+ private case class Cluster (id : Int , point : Vector )
8382
84- object IndexedPoint {
85- def apply (r : Row ): IndexedPoint = {
86- IndexedPoint (r.getInt(0 ), r.getAs[Vector ](1 ))
83+ private object Cluster {
84+ def apply (r : Row ): Cluster = {
85+ Cluster (r.getInt(0 ), r.getAs[Vector ](1 ))
8786 }
8887 }
8988
@@ -102,21 +101,21 @@ object KMeansModel extends Loader[KMeansModel] {
102101 (" class" -> thisClassName) ~ (" version" -> thisFormatVersion) ~ (" k" -> model.k)))
103102 sc.parallelize(Seq (metadata), 1 ).saveAsTextFile(Loader .metadataPath(path))
104103 val dataRDD = sc.parallelize(model.clusterCenters.zipWithIndex).map { case (point, id) =>
105- IndexedPoint (id, point)
104+ Cluster (id, point)
106105 }.toDF()
107106 dataRDD.saveAsParquetFile(Loader .dataPath(path))
108107 }
109108
110109 def load (sc : SparkContext , path : String ): KMeansModel = {
111110 implicit val formats = DefaultFormats
112111 val sqlContext = new SQLContext (sc)
113- val (className, formatVersion, metadata) = loadMetadata(sc, path)
112+ val (className, formatVersion, metadata) = Loader . loadMetadata(sc, path)
114113 assert(className == thisClassName)
115114 assert(formatVersion == thisFormatVersion)
116115 val k = (metadata \ " k" ).extract[Int ]
117- val centriods = sqlContext.parquetFile(dataPath(path))
118- Loader .checkSchema[IndexedPoint ](centriods.schema)
119- val localCentriods = centriods.map(IndexedPoint .apply).collect()
116+ val centriods = sqlContext.parquetFile(Loader . dataPath(path))
117+ Loader .checkSchema[Cluster ](centriods.schema)
118+ val localCentriods = centriods.map(Cluster .apply).collect()
120119 assert(k == localCentriods.size)
121120 new KMeansModel (localCentriods.sortBy(_.id).map(_.point))
122121 }
0 commit comments