Skip to content

Commit 8841439

Browse files
committed
adjust scala style in order to compile
1 parent 1433b11 commit 8841439

File tree

4 files changed

+45
-29
lines changed

4 files changed

+45
-29
lines changed

mllib/src/main/scala/org/apache/spark/mllib/export/ModelExportFactory.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ object ModelExportFactory {
2525

2626
/**
2727
* Factory object to help creating the necessary ModelExport implementation
28-
* taking as input the ModelExportType (for example PMML) and the machine learning model (for example KMeansModel).
28+
* taking as input the ModelExportType (for example PMML)
29+
* and the machine learning model (for example KMeansModel).
2930
*/
3031
def createModelExport(model: Any, exportType: ModelExportType): ModelExport = {
31-
return exportType match{
32-
case PMML => model match{
33-
case kmeans: KMeansModel => new KMeansPMMLModelExport(kmeans)
34-
case _ => throw new IllegalArgumentException("Export not supported for model: " + model.getClass)
35-
}
36-
case _ => throw new IllegalArgumentException("Export type not supported:" + exportType)
37-
}
32+
return exportType match{
33+
case PMML => model match{
34+
case kmeans: KMeansModel => new KMeansPMMLModelExport(kmeans)
35+
case _ =>
36+
throw new IllegalArgumentException("Export not supported for model: " + model.getClass)
37+
}
38+
case _ => throw new IllegalArgumentException("Export type not supported:" + exportType)
39+
}
3840
}
39-
41+
4042
}

mllib/src/main/scala/org/apache/spark/mllib/export/ModelExportType.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ package org.apache.spark.mllib.export
1919

2020
/**
2121
* Defines export types.
22-
* - PMML exports the machine learning models in an XML-based file format called Predictive Model Markup Language developed by the Data Mining Group (www.dmg.org).
22+
* - PMML exports the machine learning models in an XML-based file format
23+
* called Predictive Model Markup Language developed by the Data Mining Group (www.dmg.org).
2324
*/
2425
object ModelExportType extends Enumeration{
2526

mllib/src/main/scala/org/apache/spark/mllib/export/pmml/KMeansPMMLModelExport.scala

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

mllib/src/main/scala/org/apache/spark/mllib/export/pmml/PMMLModelExport.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ trait PMMLModelExport extends ModelExport{
4141

4242
private def setHeader(pmml : PMML): Unit = {
4343
var version = getClass().getPackage().getImplementationVersion()
44-
var app = new Application().withName("Apache Spark MLlib").withVersion(version)
45-
var timestamp = new Timestamp().withContent(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date()))
46-
var header = new Header()
47-
.withCopyright("www.dmg.org")
44+
var app = new Application().withName("Apache Spark MLlib").withVersion(version)
45+
var timestamp = new Timestamp()
46+
.withContent(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(new Date()))
47+
var header = new Header()
48+
.withCopyright("www.dmg.org")
4849
.withApplication(app)
4950
.withTimestamp(timestamp);
50-
pmml.setHeader(header);
51+
pmml.setHeader(header);
5152
}
5253

5354
/**

0 commit comments

Comments
 (0)