Search in sources :

Example 1 with BooleanPerceptronClassifier

use of org.apache.lucene.classification.BooleanPerceptronClassifier in project lucene-solr by apache.

the class ConfusionMatrixGeneratorTest method testGetConfusionMatrixWithBP.

@Test
public void testGetConfusionMatrixWithBP() throws Exception {
    LeafReader reader = null;
    try {
        MockAnalyzer analyzer = new MockAnalyzer(random());
        reader = getSampleIndex(analyzer);
        Classifier<Boolean> classifier = new BooleanPerceptronClassifier(reader, analyzer, null, 1, null, booleanFieldName, textFieldName);
        ConfusionMatrixGenerator.ConfusionMatrix confusionMatrix = ConfusionMatrixGenerator.getConfusionMatrix(reader, classifier, booleanFieldName, textFieldName, -1);
        checkCM(confusionMatrix);
        assertTrue(confusionMatrix.getPrecision("true") >= 0d);
        assertTrue(confusionMatrix.getPrecision("true") <= 1d);
        assertTrue(confusionMatrix.getPrecision("false") >= 0d);
        assertTrue(confusionMatrix.getPrecision("false") <= 1d);
        assertTrue(confusionMatrix.getRecall("true") >= 0d);
        assertTrue(confusionMatrix.getRecall("true") <= 1d);
        assertTrue(confusionMatrix.getRecall("false") >= 0d);
        assertTrue(confusionMatrix.getRecall("false") <= 1d);
        assertTrue(confusionMatrix.getF1Measure("true") >= 0d);
        assertTrue(confusionMatrix.getF1Measure("true") <= 1d);
        assertTrue(confusionMatrix.getF1Measure("false") >= 0d);
        assertTrue(confusionMatrix.getF1Measure("false") <= 1d);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
Also used : LeafReader(org.apache.lucene.index.LeafReader) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) BooleanPerceptronClassifier(org.apache.lucene.classification.BooleanPerceptronClassifier) Test(org.junit.Test)

Aggregations

MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 BooleanPerceptronClassifier (org.apache.lucene.classification.BooleanPerceptronClassifier)1 LeafReader (org.apache.lucene.index.LeafReader)1 Test (org.junit.Test)1