List of usage examples for weka.classifiers CostMatrix setElement
public final void setElement(int rowIndex, int columnIndex, double value)
From source file:etc.aloe.cscw2013.TrainingImpl.java
License:Open Source License
@Override public WekaModel train(ExampleSet examples) { System.out.println("SMO Options: " + SMO_OPTIONS); SMO smo = new SMO(); try {/* w w w .j a v a 2s . c o m*/ smo.setOptions(Utils.splitOptions(SMO_OPTIONS)); } catch (Exception ex) { System.err.println("Unable to configure SMO."); System.err.println("\t" + ex.getMessage()); return null; } //Build logistic models if desired smo.setBuildLogisticModels(isBuildLogisticModel()); Classifier classifier = smo; if (useCostTraining) { CostSensitiveClassifier cost = new CostSensitiveClassifier(); cost.setClassifier(smo); CostMatrix matrix = new CostMatrix(2); matrix.setElement(0, 0, 0); matrix.setElement(0, 1, falsePositiveCost); matrix.setElement(1, 0, falseNegativeCost); matrix.setElement(1, 1, 0); cost.setCostMatrix(matrix); classifier = cost; System.out.print("Wrapping SMO in CostSensitiveClassifier " + matrix.toMatlab()); if (useReweighting) { cost.setMinimizeExpectedCost(false); System.out.println(" using re-weighting."); } else { cost.setMinimizeExpectedCost(true); System.out.println(" using min-cost criterion."); } } try { System.out.print("Training SMO on " + examples.size() + " examples... "); classifier.buildClassifier(examples.getInstances()); System.out.println("done."); WekaModel model = new WekaModel(classifier); return model; } catch (Exception ex) { System.err.println("Unable to train SMO."); System.err.println("\t" + ex.getMessage()); return null; } }
From source file:org.openml.webapplication.algorithm.InstancesHelper.java
License:Open Source License
public static CostMatrix doubleToCostMatrix(double[][] cm) { CostMatrix costmatrix = new CostMatrix(cm.length); for (int i = 0; i < cm.length; ++i) { for (int j = 0; j < cm[i].length; ++j) { costmatrix.setElement(i, j, cm[i][j]); }//from w w w . j a v a 2 s .c om } return costmatrix; }