Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
med:lab_5 [2018/05/12 23:19]
pszwed [Kod]
med:lab_5 [2018/05/12 23:26]
pszwed [IDE]
Line 24: Line 24:
   * Utwórz projekt   * Utwórz projekt
   * Wybierz: //Project -> Properties -> Java Build Path.// Następnie zakładkę //Libraries// i opcję //Add External JARs//. Dodaj bibliotekę ''weka.jar ''   * Wybierz: //Project -> Properties -> Java Build Path.// Następnie zakładkę //Libraries// i opcję //Add External JARs//. Dodaj bibliotekę ''weka.jar ''
 +
 +
 +Dost
 ===== Kod ===== ===== Kod =====
  
Line 29: Line 32:
  
  
 +5.1.1
 <code java> <code java>
 DataSource source = new DataSource("c-001.arff"); DataSource source = new DataSource("c-001.arff");
Line 41: Line 45:
 Utworznenie i uczenie klasyfikatora Utworznenie i uczenie klasyfikatora
  
 +5.1.3
 <code java> <code java>
 Classifier cls = new NaiveBayes(); Classifier cls = new NaiveBayes();
Line 48: Line 53:
 Instancja do sklasyfikowania  Instancja do sklasyfikowania 
  
 +5.1.4
 <code java> <code java>
 Instance inst = new DenseInstance (3); Instance inst = new DenseInstance (3);
Line 55: Line 61:
 </code> </code>
  
 +5.1.5/6
 <code java> <code java>
 +
 +double y = cls.classifyInstance(inst);
 +
 double[] distrib = cls.distributionForInstance(inst); double[] distrib = cls.distributionForInstance(inst);
 System.out.printf(Locale.US,"%d->%f %d->%f\n",0,distrib[0],1,distrib[1]); System.out.printf(Locale.US,"%d->%f %d->%f\n",0,distrib[0],1,distrib[1]);
Line 62: Line 71:
  
  
 +5.2.2
 <code java> <code java>
 List<Attribute> atts = Arrays.asList( List<Attribute> atts = Arrays.asList(
Line 73: Line 83:
 </code> </code>
  
 +5.2.3
 <code java> <code java>
 for(double x1=-10;x1<=10;x1+=0.1){ for(double x1=-10;x1<=10;x1+=0.1){
Line 88: Line 99:
  
 </code> </code>
 +
 +5.2.4
 +<code java>
 +ArffSaver saver = new ArffSaver();
 +saver.setInstances(result);
 +saver.setFile(new File("c-001-result.arff"));
 +saver.writeBatch();
 +</code>
 +
 +5.4.2
 +<code java>
 +Classifier cls;
 +cls = new NaiveBayes();
 +
 +Evaluation eval = new Evaluation(data);
 +eval.crossValidateModel(cls, data, 10, new Random(1));
 +
 +eval.toSummaryString()
 +eval.confusionMatrix()
 +System.out.printf(Locale.US,
 +"[prec recall fmeasure]:\t%f\t%f\t%f\n",
 +eval.weightedPrecision(),
 +eval.weightedRecall(),
 +eval.weightedFMeasure());
 +
 +</code>
 +
 +
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0