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 [2017/12/06 17:23]
pszwed [IDE]
med:lab_5 [2018/05/12 23:26]
pszwed [IDE]
Line 22: Line 22:
  
   * W ''usr/local/bin'' jest dostępne Eclipse Neon   * W ''usr/local/bin'' jest dostępne Eclipse Neon
-  * Wybierz: //Project -> Properties -> Jaba Build Path.// Następnie zakładkę //Libraries// i opcję //Add External JARs//. Dodaj bibliotekę ''weka.jar ''+  * Utwórz projekt 
 +  * Wybierz: //Project -> Properties -> Java Build Path.// Następnie zakładkę //Libraries// i opcję //Add External JARs//. Dodaj bibliotekę ''weka.jar '' 
 + 
 + 
 +Dost
 ===== Kod ===== ===== Kod =====
  
Line 28: Line 32:
  
  
 +5.1.1
 <code java> <code java>
 DataSource source = new DataSource("c-001.arff"); DataSource source = new DataSource("c-001.arff");
Line 40: 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 47: 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 54: 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 61: Line 71:
  
  
 +5.2.2
 <code java> <code java>
 List<Attribute> atts = Arrays.asList( List<Attribute> atts = Arrays.asList(
Line 71: Line 82:
  
 </code> </code>
 +
 +5.2.3
 +<code java>
 +for(double x1=-10;x1<=10;x1+=0.1){
 + for(double x2=-10;x2<=10;x2+=0.1){
 +  Instance inst = new DenseInstance(3);
 +  inst.setValue(0, x1);
 +  inst.setValue(1, x2);
 +
 +  inst.setDataset(result);
 +  double y = cls.classifyInstance(inst);
 +  inst.setClassValue(y);
 +  result.add(inst);
 + }
 +}
 +
 +</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