Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

43
LINES

< > BotCompany Repo | #1002542 // Java ML Test Program (developing)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 6080K of libraries. Click here for Pure Java version (339L/3K/10K).

!752

// java ml and dependencies
lib 1002535
lib 1002536
lib 1002537
lib 1002538
lib 1002539
lib 1002540

import net.sf.javaml.classification.*;
import net.sf.javaml.core.*;
import net.sf.javaml.tools.data.*;

p {
  File irisCSV = loadLibrary("#1002541");
  
  /* Load a data set */
  
  Dataset data = FileHandler.loadDataset(irisCSV, 4, ",");
  
  /* Construct a KNN classifier that uses 5 neighbors to make a
   * decision. */
   
  Classifier knn = new KNearestNeighbors(5);
  knn.buildClassifier(data);
  
  Dataset dataForClassification = FileHandler.loadDataset(irisCSV, 4, ",");
  
  /* Counters for correct and wrong predictions. */
  int correct = 0, wrong = 0;
  /* Classify all instances and check with the correct class values */
  for (Instance inst : dataForClassification) {
      Object predictedClassValue = knn.classify(inst);
      Object realClassValue = inst.classValue();
      if (predictedClassValue.equals(realClassValue))
          correct++;
      else
          wrong++;
  }
  
  print("correct=" + correct + ", wrong=" + wrong);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002542
Snippet name: Java ML Test Program (developing)
Eternal ID of this version: #1002542/1
Text MD5: c41b10d1922d7cc567c7b63bd9da3573
Transpilation MD5: 4f985273fc2e8a2edbd150e6674d2a64
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-09-11 17:07:12
Source code size: 1103 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 569 / 601
Referenced in: [show references]