@@ -62,30 +62,42 @@ class KMeansPMMLModelExport(model : KMeansModel) extends PMMLModelExport{
6262 var miningSchema = new MiningSchema ()
6363
6464 for ( i <- 0 to (clusterCenter.size - 1 )) {
65- fields(i) = FieldName .create(" field_" + i)
66- dataDictionary.withDataFields(new DataField (fields(i), OpType .CONTINUOUS , DataType .DOUBLE ))
67- miningSchema.withMiningFields(new MiningField (fields(i)).withUsageType(FieldUsageType .ACTIVE ))
68- }
65+ fields(i) = FieldName .create(" field_" + i)
66+ dataDictionary
67+ .withDataFields(new DataField (fields(i), OpType .CONTINUOUS , DataType .DOUBLE ))
68+ miningSchema
69+ .withMiningFields(new MiningField (fields(i))
70+ .withUsageType(FieldUsageType .ACTIVE ))
71+ }
6972
7073 var comparisonMeasure = new ComparisonMeasure ()
71- .withKind(Kind .DISTANCE )
72- .withMeasure(new SquaredEuclidean ()
74+ .withKind(Kind .DISTANCE )
75+ .withMeasure(new SquaredEuclidean ()
7376 );
7477
7578 dataDictionary.withNumberOfFields((dataDictionary.getDataFields()).size());
76-
79+
7780 pmml.setDataDictionary(dataDictionary);
7881
79- var clusteringModel = new ClusteringModel (miningSchema, comparisonMeasure, MiningFunctionType .CLUSTERING , ModelClass .CENTER_BASED , model.clusterCenters.length)
80- .withModelName(" k-means" );
82+ var clusteringModel = new ClusteringModel (miningSchema, comparisonMeasure,
83+ MiningFunctionType .CLUSTERING , ModelClass .CENTER_BASED , model.clusterCenters.length)
84+ .withModelName(" k-means" );
8185
8286 for ( i <- 0 to (clusterCenter.size - 1 )) {
83- clusteringModel.withClusteringFields(new ClusteringField (fields(i)).withCompareFunction(CompareFunctionType .ABS_DIFF ))
84- var cluster = new Cluster ().withName(" cluster_" + i).withArray(new org.dmg.pmml.Array ().withType(Type .REAL ).withN(clusterCenter.size).withValue(model.clusterCenters(i).toArray.mkString(" " )))
85- // cluster.withSize(value) //we don't have the size of the single cluster but only the centroids (withValue)
86- clusteringModel.withClusters(cluster)
87+ clusteringModel.withClusteringFields(
88+ new ClusteringField (fields(i)).withCompareFunction(CompareFunctionType .ABS_DIFF )
89+ )
90+ var cluster = new Cluster ()
91+ .withName(" cluster_" + i)
92+ .withArray(new org.dmg.pmml.Array ()
93+ .withType(Type .REAL )
94+ .withN(clusterCenter.size)
95+ .withValue(model.clusterCenters(i).toArray.mkString(" " )))
96+ // we don't have the size of the single cluster but only the centroids (withValue)
97+ // .withSize(value)
98+ clusteringModel.withClusters(cluster)
8799 }
88-
100+
89101 pmml.withModels(clusteringModel);
90102
91103 }
0 commit comments