Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. Attribute sepallength = new Attribute("sepallength");
  2. Attribute sepalwidth = new Attribute("sepalwidth");
  3. Attribute petallength = new Attribute("petallength");
  4. Attribute petalwidth = new Attribute("petalwidth");
  5. ArrayList<String> cls_atr = new ArrayList<String>();
  6. cls_atr.add("Iris-setosa");
  7. cls_atr.add("Iris-versicolor");
  8. cls_atr.add("Iris-virginica");
  9.  
  10. Attribute cls= new Attribute("class",cls_atr);
  11. ArrayList<Attribute> attributes = new ArrayList<Attribute>();
  12. attributes.add(sepallength);
  13. attributes.add(sepalwidth);
  14. attributes.add(petallength);
  15. attributes.add(petalwidth);
  16. attributes.add(cls);
  17. Instances dataset = new Instances("Test-dataset",attributes,5);
  18.  
  19. double[] val = new double[data.numAttributes()];
  20. String text = null;
  21. BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  22. System.out.println("Podaj sepallength: ");
  23. text = stdin.readLine();
  24. val[0] = Double.parseDouble(text);
  25. text = null;
  26. System.out.println("Podaj sepalwidth: ");
  27. text = stdin.readLine();
  28. val[1] = Double.parseDouble(text);
  29. text = null;
  30.  
  31. System.out.println("Podaj petallength: ");
  32. text = stdin.readLine();
  33. val[2] = Double.parseDouble(text);
  34. text = null;
  35.  
  36. System.out.println("Podaj petalwidth: ");
  37. text = stdin.readLine();
  38. val[3] = Double.parseDouble(text);
  39. val[4]=data.attribute(4).indexOfValue("class");
  40. Instance inst = new DenseInstance(1.0,val);
  41. data.add(inst);
  42.  
  43. double index = j48.classifyInstance(data.instance(data.numInstances()-1));
  44. String className = data.attribute(data.numAttributes() - 1).value((int)index);
  45. System.out.println(className);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement