Balwant Kumar Singh
Balwant Kumar Singh

Reputation: 1178

PMML document parsing

I'm using jpmml library to parse the PMML document(xml document with root element PMML). I'm able to parse some of the elements but not all. Here, I'm not able to parse CategoricalPredictor attribute inside the RegressionTable element. The code for parsing CategoricalPredictor is :

    RegressionTable regressionTable = new RegressionTable(intercept);
    List<CategoricalPredictor> categoricalPredictor=regressionTable.getCategoricalPredictors();


    /*Categorical predictors*/

    System.out.println("Categorical Predictors:");
    for(CategoricalPredictor c : categoricalPredictor){

        System.out.println("Name :"+c.getName()+",\tValue :"+c.getValue()+
                ",\tCoefficient :"+c.getCoefficient());
        System.out.println();
    }

With this code I'm getting nothing but Categorical Predictors: as output.

What should I do to get it? Your effort will be appreciable. Thanks in advance.

Upvotes: 4

Views: 899

Answers (1)

user1808924
user1808924

Reputation: 4926

You are invoking RegressionTable#getCategoricalPredictors() on a newly constructed RegressionTable instance. The getter returns an empty List, which is the expected behaviour.

If you want to work with an existing RegressionTable instance then you need to load it from PMML file something like that:

PMML pmml = ...
RegressionModelManager regressionManager = new RegressionModelManager(pmml);
RegressionModel model = regressionManager.getModel();
List<RegressionTable> modelTables = model.getRegressionTables();
for(RegressionTable regressionTable : regressionTables){
  ...
}

Upvotes: 1

Related Questions