if(overallFCs.getCount(f) < minOccur) be.getFeatures().remove(f);
}
}
ClassificationEvaluator ce = new ClassificationEvaluator();
if(false) {
ce = new ClassificationEvaluator();
DecisionTree dt = new DecisionTree(bagEvents);
dt.printTree();
for(int i=0;i<testBagEvents.size();i++) {
BagEvent be = testBagEvents.get(i);
String result = dt.testBag(be.getFeatures());
ce.logEvent(be.getClassLabel(), result);
}
System.out.println(ce.getAccuracy());
System.out.println(ce.getKappa());
ce.pprintConfusionMatrix();
ce.pprintPrecisionRecallEval();
//return;
}
if(false) {
ce = new ClassificationEvaluator();
DecisionList dl = new DecisionList(bagEvents);
for(int i=0;i<testBagEvents.size();i++) {
BagEvent be = testBagEvents.get(i);
String result = dl.testBag(be.getFeatures());
ce.logEvent(be.getClassLabel(), result);
}
System.out.println(ce.getAccuracy());
System.out.println(ce.getKappa());
ce.pprintConfusionMatrix();
ce.pprintPrecisionRecallEval();
//return;
}
if(true) {
ce = new ClassificationEvaluator();
MultinomialNaiveBayes mnb = new MultinomialNaiveBayes(bagEvents);
Element elem = mnb.toXML();
Document doc = new Document(elem);
Serializer ser = new Serializer(System.out);
//ser.setIndent(2);
ser.write(doc);
mnb = new MultinomialNaiveBayes(elem);
elem = mnb.toXML();
doc = new Document(elem);
ser = new Serializer(System.out);
//ser.setIndent(2);
ser.write(doc);
for(int i=0;i<testBagEvents.size();i++) {
BagEvent be = testBagEvents.get(i);
//Map<String,Double> results = mnb.testBag(be.getClassLabel(), be.getFeatures());
Map<String,Double> results = mnb.testBag(be.getFeatures());
System.out.println(be.getClassLabel() + "\t" + mnb.testBag(be.getFeatures()));
ce.logEvent(be.getClassLabel(), mnb.bestResult(results));
if(!be.getClassLabel().equals(mnb.bestResult(results))) {
System.out.println(be.getFeatures());
System.out.println(bagsToSentences.get(be.getFeatures()));
}
}
System.out.println(ce.getAccuracy());
System.out.println(ce.getKappa());
ce.pprintConfusionMatrix();
ce.pprintPrecisionRecallEval();
}
if(false) {
ce = new ClassificationEvaluator();
List<Event> trainEvents = new ArrayList<Event>();
List<Event> testEvents = new ArrayList<Event>();
for(BagEvent be : bagEvents) {
trainEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
}
for(BagEvent be : testBagEvents) {
testEvents.add(new Event(be.getClassLabel(), be.getFeatures().getSet().toArray(new String[0])));
}
DataIndexer di = new TwoPassDataIndexer(new EventCollectorAsStream(new SimpleEventCollector(trainEvents)), 1);
GISModel gm = GIS.trainModel(100, di);
//ClassificationEvaluator ce = new ClassificationEvaluator();
for(Event event : testEvents) {
double [] results = gm.eval(event.getContext());
String result = results[gm.getIndex("TRUE")] > 0.5 ? "TRUE" : "FALSE";
//String result = gm.getBestOutcome(results);
//System.out.println(event.getOutcome() + "\t" + result + "\t" + results[gm.getIndex(event.getOutcome())] + "\t" + StringTools.arrayToList(event.getContext()));
ce.logEvent(event.getOutcome(), result);
}
System.out.println(ce.getAccuracy());
System.out.println(ce.getKappa());
ce.pprintConfusionMatrix();
ce.pprintPrecisionRecallEval();
}
if(false) {
List<Bag<String>> trueBags = new ArrayList<Bag<String>>();