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:27]
pszwed [Weka]
Line 18: Line 18:
  
 Brak specjalnych wymagań Brak specjalnych wymagań
 +
 +Biblioteka weka.jar:  ''/opt/weka/weka.jar''
  
 ===== IDE ===== ===== IDE =====
Line 24: Line 26:
   * 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 34:
  
  
 +5.1.1
 <code java> <code java>
 DataSource source = new DataSource("c-001.arff"); DataSource source = new DataSource("c-001.arff");
Line 41: Line 47:
 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 55:
 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 63:
 </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 73:
  
  
 +5.2.2
 <code java> <code java>
 List<Attribute> atts = Arrays.asList( List<Attribute> atts = Arrays.asList(
Line 73: Line 85:
 </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 101:
  
 </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