@@ -29,71 +29,85 @@ class GeneralizedLinearPMMLModelExportSuite extends FunSuite{
2929
3030 test(" GeneralizedLinearPMMLModelExport generate PMML format" ) {
3131
32- // arrange models to test
32+ // arrange models to test
3333 val linearInput = LinearDataGenerator .generateLinearInput(
3434 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);
3739 val lassoModel = new LassoModel (linearInput(0 ).features, linearInput(0 ).label);
3840 val svmModel = new SVMModel (linearInput(0 ).features, linearInput(0 ).label);
3941
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
4345 assert(linearModelExport.isInstanceOf [PMMLModelExport ])
4446 var pmml = linearModelExport.asInstanceOf [PMMLModelExport ].getPmml()
4547 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
5055 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)
5258
53- // act
59+ // act
5460 val ridgeModelExport = PMMLModelExportFactory .createPMMLModelExport(ridgeRegressionModel)
55- // assert that the PMML format is as expected
61+ // assert that the PMML format is as expected
5662 assert(ridgeModelExport.isInstanceOf [PMMLModelExport ])
5763 pmml = ridgeModelExport.asInstanceOf [PMMLModelExport ].getPmml()
5864 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
6066 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
6371 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)
6574
66- // act
75+ // act
6776 val lassoModelExport = PMMLModelExportFactory .createPMMLModelExport(lassoModel)
68- // assert that the PMML format is as expected
77+ // assert that the PMML format is as expected
6978 assert(lassoModelExport.isInstanceOf [PMMLModelExport ])
7079 pmml = lassoModelExport.asInstanceOf [PMMLModelExport ].getPmml()
7180 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
7382 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
7687 assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
7788 .getRegressionTables().get(0 ).getNumericPredictors().size() === lassoModel.weights.size)
7889
79- // act
90+ // act
8091 val svmModelExport = PMMLModelExportFactory .createPMMLModelExport(svmModel)
81- // assert that the PMML format is as expected
92+ // assert that the PMML format is as expected
8293 assert(svmModelExport.isInstanceOf [PMMLModelExport ])
8394 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
8698 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
89103 assert(pmml.getModels().get(0 ).asInstanceOf [RegressionModel ]
90104 .getRegressionTables().get(0 ).getNumericPredictors().size() === svmModel.weights.size)
91105
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")
97111
98112 }
99113
0 commit comments