Created
June 9, 2018 15:35
-
-
Save ChristianSch/d5ad6883a5e42b34c6267ae308bd18be to your computer and use it in GitHub Desktop.
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
package put.mlc.examples.pcc; | |
import mulan.classifier.MultiLabelOutput; | |
import mulan.data.MultiLabelInstances; | |
import put.mlc.classifiers.pcc.PCC; | |
import put.mlc.classifiers.pcc.inference.Inference; | |
import put.mlc.classifiers.pcc.inference.montecarlo.FMeasureMaximizerInference; | |
import put.mlc.classifiers.pcc.inference.ExhaustiveInference; | |
import weka.classifiers.functions.Logistic; | |
import weka.core.Instances; | |
import weka.core.converters.ConverterUtils.DataSource; | |
import weka.core.Utils; | |
public class PCCPredict { | |
public static void main(String[] args) throws Exception { | |
MultiLabelInstances trainSet = new MultiLabelInstances("datasets/scene-train.arff", "datasets/scene.xml"); | |
MultiLabelInstances testSet = new MultiLabelInstances("datasets/scene-test.arff", "datasets/scene.xml"); | |
Instances testData = DataSource.read("datasets/scene-test.arff"); | |
Inference inf = new ExhaustiveInference(); | |
// Inference inf = new FMeasureMaximizerInference(100, 2018); | |
PCC PCCLearner = new PCC(inf); | |
Logistic log = new Logistic(); | |
PCCLearner.setBaseClassifier(log); | |
PCCLearner.build(trainSet); | |
MultiLabelOutput res; | |
res = PCCLearner.makePrediction(testData.get(0)); | |
System.out.println(Utils.arrayToString(res.getConfidences())); | |
for (int i = 0; i < testData.size(); i++) { | |
res = PCCLearner.makePrediction(testData.get(i)); | |
System.out.println(Utils.arrayToString(res.getBipartition())); | |
double[] confidences = res.getConfidences(); | |
System.out.print("[ "); | |
for (int j = 0; j < confidences.length; j++) { | |
System.out.print(String.format("%.2f, ", confidences[j])); | |
} | |
System.out.println("]"); | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment