@@ -29,71 +29,85 @@ class GeneralizedLinearPMMLModelExportSuite extends FunSuite{
29
29
30
30
test(" GeneralizedLinearPMMLModelExport generate PMML format" ) {
31
31
32
- // arrange models to test
32
+ // arrange models to test
33
33
val linearInput = LinearDataGenerator .generateLinearInput(
34
34
3.0 , Array (10.0 , 10.0 ), 1 , 17 )
35
- val linearRegressionModel = new LinearRegressionModel (linearInput(0 ).features, linearInput(0 ).label);
36
- val ridgeRegressionModel = new RidgeRegressionModel (linearInput(0 ).features, linearInput(0 ).label);
35
+ val linearRegressionModel = new LinearRegressionModel (
36
+ linearInput(0 ).features, linearInput(0 ).label);
37
+ val ridgeRegressionModel = new RidgeRegressionModel (
38
+ linearInput(0 ).features, linearInput(0 ).label);
37
39
val lassoModel = new LassoModel (linearInput(0 ).features, linearInput(0 ).label);
38
40
val svmModel = new SVMModel (linearInput(0 ).features, linearInput(0 ).label);
39
41
40
- // act by exporting the model to the PMML format
41
- val linearModelExport = PMMLModelExportFactory .createPMMLModelExport(linearRegressionModel)
42
- // assert that the PMML format is as expected
42
+ // act by exporting the model to the PMML format
43
+ val linearModelExport = PMMLModelExportFactory .createPMMLModelExport(linearRegressionModel)
44
+ // assert that the PMML format is as expected
43
45
assert(linearModelExport.isInstanceOf [PMMLModelExport ])
44
46
var pmml = linearModelExport.asInstanceOf [PMMLModelExport ].getPmml()
45
47
assert(pmml.getHeader().getDescription() === " linear regression" )
46
- // check that the number of fields match the weights size
47
- assert(pmml.getDataDictionary().getNumberOfFields() === linearRegressionModel.weights.size + 1 )
48
- // this verify that there is a model attached to the pmml object and the model is a regression one
49
- // it also verifies that the pmml model has a regression table with the same number of predictors of the model weights
48
+ // check that the number of fields match the weights size
49
+ assert(pmml.getDataDictionary().getNumberOfFields()
50
+ === linearRegressionModel.weights.size + 1 )
51
+ // this verify that there is a model attached to the pmml object
52
+ // and the model is a regression one
53
+ // it also verifies that the pmml model has a regression table
54
+ // with the same number of predictors of the model weights
50
55
assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
51
- .getRegressionTables().get(0 ).getNumericPredictors().size() === linearRegressionModel.weights.size)
56
+ .getRegressionTables().get(0 ).getNumericPredictors().size()
57
+ === linearRegressionModel.weights.size)
52
58
53
- // act
59
+ // act
54
60
val ridgeModelExport = PMMLModelExportFactory .createPMMLModelExport(ridgeRegressionModel)
55
- // assert that the PMML format is as expected
61
+ // assert that the PMML format is as expected
56
62
assert(ridgeModelExport.isInstanceOf [PMMLModelExport ])
57
63
pmml = ridgeModelExport.asInstanceOf [PMMLModelExport ].getPmml()
58
64
assert(pmml.getHeader().getDescription() === " ridge regression" )
59
- // check that the number of fields match the weights size
65
+ // check that the number of fields match the weights size
60
66
assert(pmml.getDataDictionary().getNumberOfFields() === ridgeRegressionModel.weights.size + 1 )
61
- // this verify that there is a model attached to the pmml object and the model is a regression one
62
- // it also verifies that the pmml model has a regression table with the same number of predictors of the model weights
67
+ // this verify that there is a model attached to the pmml object
68
+ // and the model is a regression one
69
+ // it also verifies that the pmml model has a regression table
70
+ // with the same number of predictors of the model weights
63
71
assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
64
- .getRegressionTables().get(0 ).getNumericPredictors().size() === ridgeRegressionModel.weights.size)
72
+ .getRegressionTables().get(0 ).getNumericPredictors().size()
73
+ === ridgeRegressionModel.weights.size)
65
74
66
- // act
75
+ // act
67
76
val lassoModelExport = PMMLModelExportFactory .createPMMLModelExport(lassoModel)
68
- // assert that the PMML format is as expected
77
+ // assert that the PMML format is as expected
69
78
assert(lassoModelExport.isInstanceOf [PMMLModelExport ])
70
79
pmml = lassoModelExport.asInstanceOf [PMMLModelExport ].getPmml()
71
80
assert(pmml.getHeader().getDescription() === " lasso regression" )
72
- // check that the number of fields match the weights size
81
+ // check that the number of fields match the weights size
73
82
assert(pmml.getDataDictionary().getNumberOfFields() === lassoModel.weights.size + 1 )
74
- // this verify that there is a model attached to the pmml object and the model is a regression one
75
- // it also verifies that the pmml model has a regression table with the same number of predictors of the model weights
83
+ // this verify that there is a model attached to the pmml object
84
+ // and the model is a regression one
85
+ // it also verifies that the pmml model has a regression table
86
+ // with the same number of predictors of the model weights
76
87
assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
77
88
.getRegressionTables().get(0 ).getNumericPredictors().size() === lassoModel.weights.size)
78
89
79
- // act
90
+ // act
80
91
val svmModelExport = PMMLModelExportFactory .createPMMLModelExport(svmModel)
81
- // assert that the PMML format is as expected
92
+ // assert that the PMML format is as expected
82
93
assert(svmModelExport.isInstanceOf [PMMLModelExport ])
83
94
pmml = svmModelExport.asInstanceOf [PMMLModelExport ].getPmml()
84
- assert(pmml.getHeader().getDescription() === " linear SVM: if predicted value > 0, the outcome is positive, or negative otherwise" )
85
- // check that the number of fields match the weights size
95
+ assert(pmml.getHeader().getDescription()
96
+ === " linear SVM: if predicted value > 0, the outcome is positive, or negative otherwise" )
97
+ // check that the number of fields match the weights size
86
98
assert(pmml.getDataDictionary().getNumberOfFields() === svmModel.weights.size + 1 )
87
- // this verify that there is a model attached to the pmml object and the model is a regression one
88
- // it also verifies that the pmml model has a regression table with the same number of predictors of the model weights
99
+ // this verify that there is a model attached to the pmml object
100
+ // and the model is a regression one
101
+ // it also verifies that the pmml model has a regression table
102
+ // with the same number of predictors of the model weights
89
103
assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
90
104
.getRegressionTables().get(0 ).getNumericPredictors().size() === svmModel.weights.size)
91
105
92
- // manual checking
93
- // linearRegressionModel.toPMML("/tmp/linearregression.xml")
94
- // ridgeRegressionModel.toPMML("/tmp/ridgeregression.xml")
95
- // lassoModel.toPMML("/tmp/lassoregression.xml")
96
- // svmModel.toPMML("/tmp/linearsvm.xml")
106
+ // manual checking
107
+ // linearRegressionModel.toPMML("/tmp/linearregression.xml")
108
+ // ridgeRegressionModel.toPMML("/tmp/ridgeregression.xml")
109
+ // lassoModel.toPMML("/tmp/lassoregression.xml")
110
+ // svmModel.toPMML("/tmp/linearsvm.xml")
97
111
98
112
}
99
113
0 commit comments