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).

1  
!752
2  
3  
// java ml and dependencies
4  
lib 1002535
5  
lib 1002536
6  
lib 1002537
7  
lib 1002538
8  
lib 1002539
9  
lib 1002540
10  
11  
import net.sf.javaml.classification.*;
12  
import net.sf.javaml.core.*;
13  
import net.sf.javaml.tools.data.*;
14  
15  
p {
16  
  File irisCSV = loadLibrary("#1002541");
17  
  
18  
  /* Load a data set */
19  
  
20  
  Dataset data = FileHandler.loadDataset(irisCSV, 4, ",");
21  
  
22  
  /* Construct a KNN classifier that uses 5 neighbors to make a
23  
   * decision. */
24  
   
25  
  Classifier knn = new KNearestNeighbors(5);
26  
  knn.buildClassifier(data);
27  
  
28  
  Dataset dataForClassification = FileHandler.loadDataset(irisCSV, 4, ",");
29  
  
30  
  /* Counters for correct and wrong predictions. */
31  
  int correct = 0, wrong = 0;
32  
  /* Classify all instances and check with the correct class values */
33  
  for (Instance inst : dataForClassification) {
34  
      Object predictedClassValue = knn.classify(inst);
35  
      Object realClassValue = inst.classValue();
36  
      if (predictedClassValue.equals(realClassValue))
37  
          correct++;
38  
      else
39  
          wrong++;
40  
  }
41  
  
42  
  print("correct=" + correct + ", wrong=" + wrong);
43  
}

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: 511 / 523
Referenced in: [show references]