Skip to content

Commit a0e3679

Browse files
committed
export and pmml export traits
kmeans test implementation
1 parent cf1d32e commit a0e3679

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed

mllib/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
<type>test-jar</type>
9999
<scope>test</scope>
100100
</dependency>
101+
<dependency>
102+
<groupId>org.jpmml</groupId>
103+
<artifactId>pmml-model</artifactId>
104+
<version>1.1.7</version>
105+
</dependency>
101106
</dependencies>
102107
<profiles>
103108
<profile>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.export
19+
20+
import java.io.OutputStream
21+
22+
trait ModelExport {
23+
24+
def save(outputStream: OutputStream): Unit
25+
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.export
19+
20+
import org.apache.spark.mllib.clustering.KMeansModel
21+
import org.apache.spark.mllib.export.pmml.KMeansPMMLModelExport
22+
23+
object ModelExportFactory {
24+
25+
//TODO: introduce model export typed
26+
27+
def createModelExport(model: Any): ModelExport = model match {
28+
case kmeans: KMeansModel => new KMeansPMMLModelExport
29+
case _ => throw new IllegalArgumentException("Export not supported for model " + model.getClass)
30+
}
31+
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.export
19+
20+
object ModelExportType extends Enumeration{
21+
22+
type ModelExportType = Value
23+
val PMML = Value
24+
25+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.export.pmml
19+
20+
class KMeansPMMLModelExport extends PMMLModelExport{
21+
22+
populateKMeansPMML();
23+
24+
def populateKMeansPMML(): Unit = {
25+
//TODO: set here header description
26+
pmml.setVersion("testing... kmeans...");
27+
//TODO: generate the model...
28+
}
29+
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark.mllib.export.pmml
19+
20+
import org.apache.spark.mllib.export.ModelExport
21+
import java.io.OutputStream
22+
import org.jpmml.model.JAXBUtil
23+
import org.dmg.pmml.PMML
24+
import javax.xml.transform.stream.StreamResult
25+
import scala.beans.BeanProperty
26+
27+
trait PMMLModelExport extends ModelExport{
28+
29+
@BeanProperty
30+
var pmml: PMML = new PMML();
31+
//TODO: set here header app copyright and timestamp
32+
33+
def save(outputStream: OutputStream): Unit = {
34+
JAXBUtil.marshalPMML(pmml, new StreamResult(outputStream));
35+
}
36+
37+
}

0 commit comments

Comments
 (0)