-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the lookup of target category values for empty NodeClassificati…
…onMap If the winning Node element does not have any ScoreDistribution child elements, then the method CategoricalResultFeature#getCategoryValues() must return a singleton set that contains the value of the "score" attribute.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
pmml-evaluator/src/test/java/org/jpmml/evaluator/NodeClassificationMapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2015 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-Evaluator | ||
* | ||
* JPMML-Evaluator is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* JPMML-Evaluator is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with JPMML-Evaluator. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.evaluator; | ||
|
||
import com.google.common.collect.Sets; | ||
import org.dmg.pmml.Node; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class NodeClassificationMapTest { | ||
|
||
@Test | ||
public void getProbability(){ | ||
Node node = new Node() | ||
.withScore("ham"); | ||
|
||
NodeClassificationMap classificationMap = new NodeClassificationMap(node); | ||
|
||
assertTrue(classificationMap.isEmpty()); | ||
|
||
assertEquals(Sets.newHashSet("ham"), classificationMap.getCategoryValues()); | ||
|
||
assertEquals((Double)1d, classificationMap.getProbability("ham")); | ||
assertEquals((Double)0d, classificationMap.getProbability("spam")); | ||
|
||
classificationMap.put("ham", 0.75d); | ||
classificationMap.put("spam", 0.25d); | ||
|
||
assertFalse(classificationMap.isEmpty()); | ||
|
||
assertEquals(Sets.newHashSet("ham", "spam"), classificationMap.getCategoryValues()); | ||
|
||
assertEquals((Double)0.75d, classificationMap.getProbability("ham")); | ||
assertEquals((Double)0.25d, classificationMap.getProbability("spam")); | ||
} | ||
} |