weka.classifiers.evaluation.Prediction Java Examples
The following examples show how to use
weka.classifiers.evaluation.Prediction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestWekaBayes.java From Java-Data-Analysis with MIT License | 8 votes |
public static void main(String[] args) throws Exception { // ConverterUtils.DataSource source = new ConverterUtils.DataSource("data/AnonFruit.arff"); DataSource source = new DataSource("data/AnonFruit.arff"); Instances train = source.getDataSet(); train.setClassIndex(3); // target attribute: (Sweet) //build model NaiveBayes model=new NaiveBayes(); model.buildClassifier(train); //use Instances test = train; Evaluation eval = new Evaluation(test); eval.evaluateModel(model,test); List <Prediction> predictions = eval.predictions(); int k = 0; for (Instance instance : test) { double actual = instance.classValue(); double prediction = eval.evaluateModelOnce(model, instance); System.out.printf("%2d.%4.0f%4.0f", ++k, actual, prediction); System.out.println(prediction != actual? " *": ""); } }
Example #2
Source File: MLUtils.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Convert to Weka (multi-target) Predictions. * Note: currently only multi-label. * */ 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; }