17
17
18
18
package org .apache .spark .mllib .api .python
19
19
20
- import java .util .{List => JList }
21
-
22
- import scala .collection .JavaConverters ._
23
- import scala .collection .mutable .ArrayBuffer
20
+ import scala .collection .JavaConverters
24
21
25
22
import org .apache .spark .SparkContext
26
- import org .apache .spark .mllib .linalg .{Vector , Vectors , Matrix }
27
23
import org .apache .spark .mllib .clustering .GaussianMixtureModel
24
+ import org .apache .spark .mllib .linalg .{Vector , Vectors }
28
25
29
26
/**
30
27
* Wrapper around GaussianMixtureModel to provide helper methods in Python
@@ -36,17 +33,11 @@ private[python] class GaussianMixtureModelWrapper(model: GaussianMixtureModel) {
36
33
/**
37
34
* Returns gaussians as a List of Vectors and Matrices corresponding each MultivariateGaussian
38
35
*/
39
- val gaussians : JList [Object ] = {
40
- val modelGaussians = model.gaussians
41
- var i = 0
42
- var mu = ArrayBuffer .empty[Vector ]
43
- var sigma = ArrayBuffer .empty[Matrix ]
44
- while (i < k) {
45
- mu += modelGaussians(i).mu
46
- sigma += modelGaussians(i).sigma
47
- i += 1
36
+ val gaussians : Array [Byte ] = {
37
+ val modelGaussians = model.gaussians.map { gaussian =>
38
+ Array [Any ](gaussian.mu, gaussian.sigma)
48
39
}
49
- List (mu.toArray, sigma.toArray).map(_. asInstanceOf [ Object ] ).asJava
40
+ SerDe .dumps( JavaConverters .seqAsJavaListConverter(modelGaussians ).asJava)
50
41
}
51
42
52
43
def save (sc : SparkContext , path : String ): Unit = model.save(sc, path)
0 commit comments