List of usage examples for weka.classifiers.evaluation EvaluationUtils EvaluationUtils
EvaluationUtils
From source file:machinelearningcw.MachineLearningCw.java
public static void compareAlgorithms(Instances data) throws Exception { System.out.println("Compare Algorithms"); EnhancedLinearPerceptron ep = new EnhancedLinearPerceptron(); ep.onlineoroffline = false;// set to choice offline ep.numberofiterations = 100;//ww w . jav a 2 s. co m ep.setCrossvalidate = false; ep.setStandardiseAttributes = false; int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(ep, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++; } total++; } double acc = ((double) correct / total); System.out.println("Offline Accuracy: " + acc); writer.append(acc + ","); perceptronClassifier p = new perceptronClassifier(); numFolds = 10; eval = new EvaluationUtils(); ArrayList<Prediction> preds2 = eval.getCVPredictions(p, data, numFolds); correct = 0; total = 0; for (Prediction pred : preds2) { if (pred.predicted() == pred.actual()) { correct++; } total++; } acc = ((double) correct / total); System.out.println("Online Accury: " + acc); writer.append(acc + ","); }
From source file:machinelearningcw.MachineLearningCw.java
public static void standardiseData(Instances data) throws Exception { System.out.println("\n" + "Compare Algorithms with standiasation"); EnhancedLinearPerceptron ep = new EnhancedLinearPerceptron(); ep.onlineoroffline = false;// set to choice offline ep.numberofiterations = 100;//from w w w . j a v a 2 s . c om ep.setCrossvalidate = false; ep.setStandardiseAttributes = true;//std attributes //standardise the test instances int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(ep, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++; } total++; } double acc = ((double) correct / total); System.out.println("Offline Accuracy: " + acc); writer.append(acc + ","); ep.onlineoroffline = true; numFolds = 10; eval = new EvaluationUtils(); ArrayList<Prediction> preds2 = eval.getCVPredictions(ep, data, numFolds); correct = 0; total = 0; for (Prediction pred : preds2) { if (pred.predicted() == pred.actual()) { correct++; } total++; } acc = ((double) correct / total); System.out.println("Online Accury: " + acc); writer.append(acc + ","); }
From source file:machinelearningcw.MachineLearningCw.java
public static void crossValidation(Instances data) throws Exception { System.out.println("\n" + "CrossValidation"); EnhancedLinearPerceptron ep = new EnhancedLinearPerceptron(); ep.numberofiterations = 100;//from w ww . ja v a 2 s. c om ep.setCrossvalidate = true; ep.setStandardiseAttributes = false;//std attributes int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(ep, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++; } total++; } double acc = ((double) correct / total); if (ep.onlineoroffline) { System.out.println("picked: online " + "Accuracy " + acc); writer.append(acc + ","); } else { System.out.println("picked: offline " + "Accuracy " + acc); writer.append(acc + ","); } }
From source file:machinelearningcw.MachineLearningCw.java
public static void ensemble(Instances data) throws Exception { System.out.println("====ensemble method====="); RandomLinearPerceptron rlp = new RandomLinearPerceptron(); int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(rlp, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++;/*from w w w . jav a 2 s. c om*/ } total++; } double acc = ((double) correct / total); writer.append(acc + ","); System.out.println("Random Accuracy: " + acc); }
From source file:machinelearningcw.MachineLearningCw.java
public static void perceptron(Instances data) throws Exception { perceptronClassifier p = new perceptronClassifier(); data.setClassIndex(data.numAttributes() - 1); int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(p, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++;//from w w w.j av a 2 s. com } total++; } double acc = ((double) correct / total); System.out.println(acc); }
From source file:machinelearningcw.MachineLearningCw.java
public static void RandomLinearPerceptron(Instances data) throws Exception { System.out.println("\n ========RandomLinearPerceptron=========="); RandomLinearPerceptron rlp = new RandomLinearPerceptron(); int numFolds = 10; EvaluationUtils eval = new EvaluationUtils(); ArrayList<Prediction> preds = eval.getCVPredictions(rlp, data, numFolds); int correct = 0; int total = 0; for (Prediction pred : preds) { if (pred.predicted() == pred.actual()) { correct++;// w w w .ja va2s . c o m } total++; } double acc = ((double) correct / total); System.out.println("Random Accuracy: " + acc); }
From source file:trainableSegmentation.Weka_Segmentation.java
License:GNU General Public License
/** * Display the threshold curve window (for precision/recall, ROC, etc.). * * @param data input instances//from ww w . j a va 2 s. c om * @param classifier classifier to evaluate */ public static void displayGraphs(Instances data, AbstractClassifier classifier) { ThresholdCurve tc = new ThresholdCurve(); FastVector predictions = null; try { final EvaluationUtils eu = new EvaluationUtils(); predictions = eu.getTestPredictions(classifier, data); } catch (Exception e) { IJ.log("Error while evaluating data!"); e.printStackTrace(); return; } Instances result = tc.getCurve(predictions); ThresholdVisualizePanel vmc = new ThresholdVisualizePanel(); vmc.setName(result.relationName() + " (display only)"); PlotData2D tempd = new PlotData2D(result); tempd.setPlotName(result.relationName()); tempd.addInstanceNumberAttribute(); try { vmc.addPlot(tempd); } catch (Exception e) { IJ.log("Error while adding plot to visualization panel!"); e.printStackTrace(); return; } String plotName = vmc.getName(); JFrame jf = new JFrame("Weka Classifier Visualize: " + plotName); jf.setSize(500, 400); jf.getContentPane().setLayout(new BorderLayout()); jf.getContentPane().add(vmc, BorderLayout.CENTER); jf.setVisible(true); }