List of usage examples for weka.classifiers.evaluation NominalPrediction NominalPrediction
public NominalPrediction(double actual, double[] distribution)
From source file:meka.core.MLUtils.java
License:Open Source License
/** * Convert to Weka (multi-target) Predictions. * Note: currently only multi-label./*from w w w .j a va 2 s .c o m*/ * */ public static ArrayList<Prediction> toWekaPredictions(int y[], double p[]) { ArrayList<Prediction> predictions = new ArrayList<Prediction>(); for (int i = 0; i < y.length; i++) { predictions.add(new NominalPrediction((double) y[i], new double[] { 1. - p[i], p[i] })); } return predictions; }
From source file:mlflex.WekaInMemoryLearner.java
License:Open Source License
/** This method calculates the area under the curve for a set of predictions and is designed to support classification of more than two classes. This code was derived from Weka's source code. * * @param predictions Predictions that have been made * @return Area under the curve, weighted by the proportion of instances for each class * @throws Exception/*from w w w. ja va 2 s .c o m*/ */ // public static double CalculateWeightedAreaUnderRoc(Predictions predictions) throws Exception { ArrayList<String> uniqueActualClasses = predictions.GetUniqueActualClasses(); if (uniqueActualClasses.size() == 0) return Double.NaN; if (predictions.Size() == 1) { if (predictions.Get(0).WasCorrect()) return 1.0; return 0.5; } if (uniqueActualClasses.size() == 1) return 0.5; ArrayList<String> dependentVariableClasses = Utilities.ProcessorVault.DependentVariableDataProcessor .GetUniqueDependentVariableValues(); FastVector predictionVector = new FastVector(); for (Prediction prediction : predictions) predictionVector.addElement( new NominalPrediction(dependentVariableClasses.indexOf(prediction.DependentVariableValue), Lists.ConvertToDoubleArray(prediction.ClassProbabilities))); double aucTotal = 0; for (int i = 0; i < dependentVariableClasses.size(); i++) { String dependentVariableClass = dependentVariableClasses.get(i); Instances result = new ThresholdCurve().getCurve(predictionVector, i); double auc = ThresholdCurve.getROCArea(result); if (!Instance.isMissingValue(auc)) aucTotal += (auc * new PredictionResults(predictions) .GetNumActualsWithDependentVariableClass(dependentVariableClass)); } return aucTotal / predictions.Size(); }