Skip to content

Instantly share code, notes, and snippets.

@ChristianSch
Created June 9, 2018 15:35
Show Gist options
  • Save ChristianSch/d5ad6883a5e42b34c6267ae308bd18be to your computer and use it in GitHub Desktop.
Save ChristianSch/d5ad6883a5e42b34c6267ae308bd18be to your computer and use it in GitHub Desktop.
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