~ubuntu-branches/ubuntu/precise/weka/precise

« back to all changes in this revision

Viewing changes to weka/classifiers/trees/J48graft.java

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2008-02-24 09:18:45 UTC
  • Revision ID: james.westby@ubuntu.com-20080224091845-1l8zy6fm6xipbzsr
Tags: upstream-3.5.7+tut1
ImportĀ upstreamĀ versionĀ 3.5.7+tut1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *    This program is free software; you can redistribute it and/or modify
 
3
 *    it under the terms of the GNU General Public License as published by
 
4
 *    the Free Software Foundation; either version 2 of the License, or
 
5
 *    (at your option) any later version.
 
6
 *
 
7
 *    This program is distributed in the hope that it will be useful,
 
8
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
 *    GNU General Public License for more details.
 
11
 *
 
12
 *    You should have received a copy of the GNU General Public License
 
13
 *    along with this program; if not, write to the Free Software
 
14
 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
15
 */
 
16
 
 
17
/*
 
18
 *    J48graft.java
 
19
 *    Copyright (C) 2007 Geoff Webb & Janice Boughton
 
20
 *    (adapted from code written by Eibe Frank).
 
21
 */
 
22
 
 
23
package weka.classifiers.trees;
 
24
 
 
25
import weka.classifiers.Classifier;
 
26
import weka.classifiers.Sourcable;
 
27
import weka.classifiers.trees.j48.BinC45ModelSelection;
 
28
import weka.classifiers.trees.j48.C45ModelSelection;
 
29
import weka.classifiers.trees.j48.C45PruneableClassifierTreeG;
 
30
import weka.classifiers.trees.j48.ClassifierTree;
 
31
import weka.classifiers.trees.j48.ModelSelection;
 
32
import weka.core.AdditionalMeasureProducer;
 
33
import weka.core.Capabilities;
 
34
import weka.core.Drawable;
 
35
import weka.core.Instance;
 
36
import weka.core.Instances;
 
37
import weka.core.Matchable;
 
38
import weka.core.Option;
 
39
import weka.core.OptionHandler;
 
40
import weka.core.Summarizable;
 
41
import weka.core.TechnicalInformation;
 
42
import weka.core.TechnicalInformationHandler;
 
43
import weka.core.Utils;
 
44
import weka.core.WeightedInstancesHandler;
 
45
import weka.core.TechnicalInformation.Field;
 
46
import weka.core.TechnicalInformation.Type;
 
47
 
 
48
import java.util.Enumeration;
 
49
import java.util.Vector;
 
50
 
 
51
/**
 
52
 <!-- globalinfo-start -->
 
53
 * Class for generating a grafted (pruned or unpruned) C4.5 decision tree. For more information, see:<br/>
 
54
 * <br/>
 
55
 * Geoff Webb (1999). Decision Tree Grafting From the All-Tests-But-One Partition. Morgan Kaufmann, San Francisco, CA.
 
56
 * <br/>
 
57
 *  also:<br/>
 
58
 * Webb, G. I. (1996). Further Experimental Evidence Against The Utility Of Occams Razor. Journal of Artificial Intelligence Research 4. Menlo Park, CA: AAAI Press, pages 397-417.
 
59
 * <p/>
 
60
 <!-- globalinfo-end -->
 
61
 *
 
62
 <!-- technical-bibtex-start -->
 
63
 * BibTeX:
 
64
 * <pre>
 
65
 * &#64;INPROCEEDINGS{Webb99,
 
66
 *   year = {1999},
 
67
 *   title = {Decision Tree Grafting From The All Tests But One Partition},
 
68
 *   booktitle = {Proceedings of the Sixteenth International Joint Conference on Artificial Intelligence (IJCAI 99)},
 
69
 *   publisher = {Morgan Kaufmann},
 
70
 *   editor = {T. Dean},
 
71
 *   address = {San Francisco},
 
72
 *   author = {G. I. Webb},
 
73
 *   location = {Stockholm, Sweden},
 
74
 *   pages = {702-707},
 
75
 * }
 
76
 * &#64:article{Webb96b,
 
77
 *   year = {1996},
 
78
 *   title = {Further Experimental Evidence Against The Utility Of Occams Razor},
 
79
 *   journal = {Journal of Artificial Intelligence Research},
 
80
 *   volume = {4},
 
81
 *   pages = {397-417},
 
82
 *   publisher = {AAAI Press},
 
83
 *   address = {Menlo Park, CA},
 
84
 *   author = {G. I. Webb}
 
85
 * }
 
86
 * </pre>
 
87
 * <p/>
 
88
 <!-- technical-bibtex-end -->
 
89
 *
 
90
 <!-- options-start -->
 
91
 * Valid options are: <p/>
 
92
 *
 
93
 * <pre> -U
 
94
 *  Use unpruned tree.</pre>
 
95
 *
 
96
 * <pre> -C &lt;pruning confidence&gt;
 
97
 *  Set confidence threshold for pruning.
 
98
 *  (default 0.25)</pre>
 
99
 *
 
100
 * <pre> -M &lt;minimum number of instances&gt;
 
101
 *  Set minimum number of instances per leaf.
 
102
 *  (default 2)</pre>
 
103
 *
 
104
 * <pre> -B
 
105
 *  Use binary splits only.</pre>
 
106
 *
 
107
 * <pre> -S
 
108
 *  Don't perform subtree raising.</pre>
 
109
 *
 
110
 * <pre> -L
 
111
 *  Do not clean up after the tree has been built.</pre>
 
112
 *
 
113
 * <pre> -A
 
114
 *  Laplace smoothing for predicted probabilities.
 
115
 *  (note: this option only affects initial tree; grafting process always uses laplace).</pre>
 
116
 *
 
117
 * <pre> -E
 
118
 * Option to allow relabeling during grafting.</pre>
 
119
 *
 
120
 <!-- options-end -->
 
121
 *
 
122
 * @author Janice Boughton (jrbought@csse.monash.edu.au)
 
123
 *  (based on J48.java written by Eibe Frank)
 
124
 * @version $Revision: 1.1 $
 
125
 */
 
126
public class J48graft extends Classifier implements OptionHandler, 
 
127
  Drawable, Matchable, Sourcable, WeightedInstancesHandler, Summarizable,
 
128
  AdditionalMeasureProducer, TechnicalInformationHandler {
 
129
 
 
130
  /** for serialization */
 
131
  static final long serialVersionUID = 8823716098042427799L;
 
132
 
 
133
  /** The decision tree */
 
134
  private ClassifierTree m_root;
 
135
 
 
136
  /** Unpruned tree? */
 
137
  private boolean m_unpruned = false;
 
138
 
 
139
  /** Confidence level */
 
140
  private float m_CF = 0.25f;
 
141
 
 
142
  /** Minimum number of instances */
 
143
  private int m_minNumObj = 2;
 
144
 
 
145
  /** Determines whether probabilities are smoothed using
 
146
      Laplace correction when predictions are generated */
 
147
  private boolean m_useLaplace = false;
 
148
 
 
149
  /** Number of folds for reduced error pruning. */
 
150
  private int m_numFolds = 3;
 
151
 
 
152
  /** Binary splits on nominal attributes? */
 
153
  private boolean m_binarySplits = false;
 
154
 
 
155
  /** Subtree raising to be performed? */
 
156
  private boolean m_subtreeRaising = true;
 
157
 
 
158
  /** Cleanup after the tree has been built. */
 
159
  private boolean m_noCleanup = false;
 
160
 
 
161
  /** relabel instances when grafting */
 
162
  private boolean m_relabel = false;
 
163
 
 
164
  /**
 
165
   * Returns a string describing classifier
 
166
   * @return a description suitable for
 
167
   * displaying in the explorer/experimenter gui
 
168
   */
 
169
  public String globalInfo() {
 
170
    return  "Class for generating a grafted (pruned or unpruned) C4.5 "
 
171
      + "decision tree. For more information, see\n\n"
 
172
      + getTechnicalInformation().toString();
 
173
  }
 
174
 
 
175
  /**
 
176
   * Returns an instance of a TechnicalInformation object, containing
 
177
   * detailed information about the technical background of this class,
 
178
   * e.g., paper reference or book this class is based on.
 
179
   *
 
180
   * @return the technical information about this class
 
181
   */
 
182
  public TechnicalInformation getTechnicalInformation() {
 
183
    TechnicalInformation        result;
 
184
 
 
185
    result = new TechnicalInformation(Type.INPROCEEDINGS);
 
186
    result.setValue(Field.AUTHOR, "Geoff Webb");
 
187
    result.setValue(Field.YEAR, "1999");
 
188
    result.setValue(Field.TITLE, "Decision Tree Grafting From the All-Tests-But-One Partition");
 
189
    result.setValue(Field.PUBLISHER, "Morgan Kaufmann");
 
190
    result.setValue(Field.ADDRESS, "San Francisco, CA");
 
191
 
 
192
    return result;
 
193
  }
 
194
 
 
195
  /**
 
196
   * Returns default capabilities of the classifier.
 
197
   *
 
198
   * @return      the capabilities of this classifier
 
199
   */
 
200
  public Capabilities getCapabilities() {
 
201
    Capabilities      result;
 
202
 
 
203
    try {
 
204
     result = new C45PruneableClassifierTreeG(null, !m_unpruned, m_CF, m_subtreeRaising, m_relabel, !m_noCleanup).getCapabilities();
 
205
    }
 
206
    catch (Exception e) {
 
207
      result = new Capabilities(this);
 
208
    }
 
209
 
 
210
    result.setOwner(this);
 
211
 
 
212
    return result;
 
213
  }
 
214
 
 
215
  /**
 
216
   * Generates the classifier.
 
217
   *
 
218
   * @param instances the data to train the classifier with
 
219
   * @throws Exception if classifier can't be built successfully
 
220
   */
 
221
  public void buildClassifier(Instances instances)
 
222
       throws Exception {
 
223
 
 
224
    ModelSelection modSelection;
 
225
 
 
226
    if (m_binarySplits)
 
227
      modSelection = new BinC45ModelSelection(m_minNumObj, instances);
 
228
    else
 
229
      modSelection = new C45ModelSelection(m_minNumObj, instances);
 
230
      m_root = new C45PruneableClassifierTreeG(modSelection, 
 
231
                              !m_unpruned, m_CF, m_subtreeRaising, 
 
232
                               m_relabel, !m_noCleanup);
 
233
    m_root.buildClassifier(instances);
 
234
 
 
235
    if (m_binarySplits) {
 
236
      ((BinC45ModelSelection)modSelection).cleanup();
 
237
    } else {
 
238
      ((C45ModelSelection)modSelection).cleanup();
 
239
    }
 
240
  }
 
241
 
 
242
  /**
 
243
   * Classifies an instance.
 
244
   *
 
245
   * @param instance the instance to classify
 
246
   * @return the classification for the instance
 
247
   * @throws Exception if instance can't be classified successfully
 
248
   */
 
249
  public double classifyInstance(Instance instance) throws Exception {
 
250
 
 
251
    return m_root.classifyInstance(instance);
 
252
  }
 
253
 
 
254
  /** 
 
255
   * Returns class probabilities for an instance.
 
256
   *
 
257
   * @param instance the instance to calculate the class probabilities for
 
258
   * @return the class probabilities
 
259
   * @throws Exception if distribution can't be computed successfully
 
260
   */
 
261
  public final double [] distributionForInstance(Instance instance) 
 
262
       throws Exception {
 
263
 
 
264
    return m_root.distributionForInstance(instance, m_useLaplace);
 
265
  }
 
266
 
 
267
  /**
 
268
   *  Returns the type of graph this classifier
 
269
   *  represents.
 
270
   *  @return Drawable.TREE
 
271
   */   
 
272
  public int graphType() {
 
273
      return Drawable.TREE;
 
274
  }
 
275
 
 
276
  /**
 
277
   * Returns graph describing the tree.
 
278
   *
 
279
   * @return the graph describing the tree
 
280
   * @throws Exception if graph can't be computed
 
281
   */
 
282
  public String graph() throws Exception {
 
283
 
 
284
    return m_root.graph();
 
285
  }
 
286
 
 
287
  /**
 
288
   * Returns tree in prefix order.
 
289
   *
 
290
   * @return the tree in prefix order
 
291
   * @throws Exception if something goes wrong
 
292
   */
 
293
  public String prefix() throws Exception {
 
294
    
 
295
    return m_root.prefix();
 
296
  }
 
297
 
 
298
 
 
299
  /**
 
300
   * Returns tree as an if-then statement.
 
301
   *
 
302
   * @param className the name of the Java class
 
303
   * @return the tree as a Java if-then type statement
 
304
   * @throws Exception if something goes wrong
 
305
   */
 
306
  public String toSource(String className) throws Exception {
 
307
 
 
308
    StringBuffer [] source = m_root.toSource(className);
 
309
    return 
 
310
    "class " + className + " {\n\n"
 
311
    +"  public static double classify(Object [] i)\n"
 
312
    +"    throws Exception {\n\n"
 
313
    +"    double p = Double.NaN;\n"
 
314
    + source[0]  // Assignment code
 
315
    +"    return p;\n"
 
316
    +"  }\n"
 
317
    + source[1]  // Support code
 
318
    +"}\n";
 
319
  }
 
320
 
 
321
  /**
 
322
   * Returns an enumeration describing the available options.
 
323
   *
 
324
   * Valid options are: <p>
 
325
   *
 
326
   * -U <br>
 
327
   * Use unpruned tree.<p>
 
328
   *
 
329
   * -C confidence <br>
 
330
   * Set confidence threshold for pruning. (Default: 0.25) <p>
 
331
   *
 
332
   * -M number <br>
 
333
   * Set minimum number of instances per leaf. (Default: 2) <p>
 
334
   *
 
335
   * -B <br>
 
336
   * Use binary splits for nominal attributes. <p>
 
337
   *
 
338
   * -S <br>
 
339
   * Don't perform subtree raising. <p>
 
340
   *
 
341
   * -L <br>
 
342
   * Do not clean up after the tree has been built.
 
343
   *
 
344
   * -A <br>
 
345
   * If set, Laplace smoothing is used for predicted probabilites. 
 
346
   *  (note: this option only affects initial tree; grafting process always uses laplace). <p>
 
347
   *
 
348
   * -E <br>
 
349
   * Allow relabelling when grafting. <p>
 
350
   *
 
351
   * @return an enumeration of all the available options.
 
352
   */
 
353
  public Enumeration listOptions() {
 
354
 
 
355
    Vector newVector = new Vector(9);
 
356
 
 
357
    newVector.
 
358
       addElement(new Option("\tUse unpruned tree.",
 
359
                              "U", 0, "-U"));
 
360
    newVector.
 
361
       addElement(new Option("\tSet confidence threshold for pruning.\n" +
 
362
                             "\t(default 0.25)",
 
363
                             "C", 1, "-C <pruning confidence>"));
 
364
    newVector.
 
365
       addElement(new Option("\tSet minimum number of instances per leaf.\n" +
 
366
                              "\t(default 2)",
 
367
                              "M", 1, "-M <minimum number of instances>"));
 
368
    newVector.
 
369
       addElement(new Option("\tUse binary splits only.",
 
370
                              "B", 0, "-B"));
 
371
    newVector.
 
372
       addElement(new Option("\tDon't perform subtree raising.",
 
373
                              "S", 0, "-S"));
 
374
    newVector.
 
375
       addElement(new Option("\tDo not clean up after the tree has been built.",
 
376
                              "L", 0, "-L"));
 
377
    newVector.
 
378
       addElement(new Option("\tLaplace smoothing for predicted probabilities.  (note: this option only affects initial tree; grafting process always uses laplace).",
 
379
 
 
380
                              "A", 0, "-A"));
 
381
    newVector.
 
382
       addElement(new Option("\tRelabel when grafting.",
 
383
                             "E", 0, "-E"));
 
384
    return newVector.elements();
 
385
  }
 
386
 
 
387
  /**
 
388
   * Parses a given list of options.
 
389
   *
 
390
   <!-- options-start -->
 
391
   * Valid options are: <p/>
 
392
   *
 
393
   * <pre> -U
 
394
   *  Use unpruned tree.</pre>
 
395
   *
 
396
   * <pre> -C &lt;pruning confidence&gt;
 
397
   *  Set confidence threshold for pruning.
 
398
   *  (default 0.25)</pre>
 
399
   *
 
400
   * <pre> -M &lt;minimum number of instances&gt;
 
401
   *  Set minimum number of instances per leaf.
 
402
   *  (default 2)</pre>
 
403
   *
 
404
   * <pre> -B
 
405
   *  Use binary splits only.</pre>
 
406
   *
 
407
   * <pre> -S
 
408
   *  Don't perform subtree raising.</pre>
 
409
   *
 
410
   * <pre> -L
 
411
   *  Do not clean up after the tree has been built.</pre>
 
412
   *
 
413
   * <pre> -A
 
414
   *  Laplace smoothing for predicted probabilities.
 
415
   *  (note: this option only affects initial tree; grafting process always uses laplace). </pre>
 
416
   *
 
417
   * <pre> -E
 
418
   * Allow relabelling when performing grafting.</pre>
 
419
   *
 
420
   <!-- options-end -->
 
421
   *
 
422
   * @param options the list of options as an array of strings
 
423
   * @throws Exception if an option is not supported
 
424
   */
 
425
  public void setOptions(String[] options) throws Exception {
 
426
 
 
427
    // Other options
 
428
    String minNumString = Utils.getOption('M', options);
 
429
    if (minNumString.length() != 0) {
 
430
      m_minNumObj = Integer.parseInt(minNumString);
 
431
    } else {
 
432
      m_minNumObj = 2;
 
433
    }
 
434
    m_binarySplits = Utils.getFlag('B', options);
 
435
    m_useLaplace = Utils.getFlag('A', options);
 
436
 
 
437
    // Pruning options
 
438
    m_unpruned = Utils.getFlag('U', options);
 
439
    m_subtreeRaising = !Utils.getFlag('S', options);
 
440
    m_noCleanup = Utils.getFlag('L', options);
 
441
                if ((m_unpruned) && (!m_subtreeRaising)) {
 
442
      throw new Exception("Subtree raising doesn't need to be unset for unpruned tree!");
 
443
    }
 
444
    m_relabel = Utils.getFlag('E', options);
 
445
    String confidenceString = Utils.getOption('C', options);
 
446
    if (confidenceString.length() != 0) {
 
447
      if (m_unpruned) {
 
448
        throw new Exception("Doesn't make sense to change confidence for unpruned "
 
449
                            +"tree!");
 
450
      } else {
 
451
        m_CF = (new Float(confidenceString)).floatValue();
 
452
        if ((m_CF <= 0) || (m_CF >= 1)) {
 
453
          throw new Exception("Confidence has to be greater than zero and smaller " +
 
454
                              "than one!");
 
455
        }
 
456
      }
 
457
    } else {
 
458
      m_CF = 0.25f;
 
459
    }
 
460
  }
 
461
 
 
462
  /**
 
463
   * Gets the current settings of the Classifier.
 
464
   *
 
465
   * @return an array of strings suitable for passing to setOptions
 
466
   */
 
467
  public String [] getOptions() {
 
468
 
 
469
    String [] options = new String [10];
 
470
    int current = 0;
 
471
 
 
472
    if (m_noCleanup) {
 
473
      options[current++] = "-L";
 
474
    }
 
475
    if (m_unpruned) {
 
476
      options[current++] = "-U";
 
477
    } else {
 
478
      if (!m_subtreeRaising) {
 
479
        options[current++] = "-S";
 
480
      }
 
481
      options[current++] = "-C"; options[current++] = "" + m_CF;
 
482
    }
 
483
    if (m_binarySplits) {
 
484
      options[current++] = "-B";
 
485
    }
 
486
    options[current++] = "-M"; options[current++] = "" + m_minNumObj;
 
487
    if (m_useLaplace) {
 
488
      options[current++] = "-A";
 
489
    }
 
490
 
 
491
    if(m_relabel) {
 
492
       options[current++] = "-E";
 
493
    }
 
494
 
 
495
    while (current < options.length) {
 
496
      options[current++] = "";
 
497
    }
 
498
    return options;
 
499
  }
 
500
 
 
501
  /**
 
502
   * Returns the tip text for this property
 
503
   * @return tip text for this property suitable for
 
504
   * displaying in the explorer/experimenter gui
 
505
   */
 
506
  public String useLaplaceTipText() {
 
507
    return "Whether counts at leaves are smoothed based on Laplace.";
 
508
  }
 
509
 
 
510
  /**
 
511
   * Get the value of useLaplace.
 
512
   *
 
513
   * @return Value of useLaplace.
 
514
   */
 
515
  public boolean getUseLaplace() {
 
516
    
 
517
    return m_useLaplace;
 
518
  }
 
519
  
 
520
  /**
 
521
   * Set the value of useLaplace.
 
522
   *
 
523
   * @param newuseLaplace Value to assign to useLaplace.
 
524
   */
 
525
  public void setUseLaplace(boolean newuseLaplace) {
 
526
    
 
527
    m_useLaplace = newuseLaplace;
 
528
  }
 
529
  
 
530
  /**
 
531
   * Returns a description of the classifier.
 
532
   *
 
533
   * @return a description of the classifier
 
534
   */
 
535
  public String toString() {
 
536
 
 
537
    if (m_root == null) {
 
538
      return "No classifier built";
 
539
    }
 
540
    if (m_unpruned)
 
541
      return "J48graft unpruned tree\n------------------\n" + m_root.toString();
 
542
    else
 
543
      return "J48graft pruned tree\n------------------\n" + m_root.toString();
 
544
  }
 
545
 
 
546
  /**
 
547
   * Returns a superconcise version of the model
 
548
   *
 
549
   * @return a summary of the model
 
550
   */
 
551
  public String toSummaryString() {
 
552
 
 
553
    return "Number of leaves: " + m_root.numLeaves() + "\n"
 
554
         + "Size of the tree: " + m_root.numNodes() + "\n";
 
555
  }
 
556
 
 
557
  /**
 
558
   * Returns the size of the tree
 
559
   * @return the size of the tree
 
560
   */
 
561
  public double measureTreeSize() {
 
562
    return m_root.numNodes();
 
563
  }
 
564
 
 
565
  /**
 
566
   * Returns the number of leaves
 
567
   * @return the number of leaves
 
568
   */
 
569
  public double measureNumLeaves() {
 
570
    return m_root.numLeaves();
 
571
  }
 
572
 
 
573
  /**
 
574
   * Returns the number of rules (same as number of leaves)
 
575
   * @return the number of rules
 
576
   */
 
577
  public double measureNumRules() {
 
578
    return m_root.numLeaves();
 
579
  }
 
580
 
 
581
  /**
 
582
   * Returns an enumeration of the additional measure names
 
583
   * @return an enumeration of the measure names
 
584
   */
 
585
  public Enumeration enumerateMeasures() {
 
586
    Vector newVector = new Vector(3);
 
587
    newVector.addElement("measureTreeSize");
 
588
    newVector.addElement("measureNumLeaves");
 
589
    newVector.addElement("measureNumRules");
 
590
    return newVector.elements();
 
591
  }
 
592
 
 
593
  /**
 
594
   * Returns the value of the named measure
 
595
   * @param additionalMeasureName the name of the measure to query for its value
 
596
   * @return the value of the named measure
 
597
   * @throws IllegalArgumentException if the named measure is not supported
 
598
   */
 
599
  public double getMeasure(String additionalMeasureName) {
 
600
    if (additionalMeasureName.compareTo("measureNumRules") == 0) {
 
601
      return measureNumRules();
 
602
    } else if (additionalMeasureName.compareTo("measureTreeSize") == 0) {
 
603
      return measureTreeSize();
 
604
    } else if (additionalMeasureName.compareTo("measureNumLeaves") == 0) {
 
605
      return measureNumLeaves();
 
606
    } else {
 
607
      throw new IllegalArgumentException(additionalMeasureName
 
608
                          + " not supported (j48)");
 
609
    }
 
610
  }
 
611
 
 
612
  /**
 
613
   * Returns the tip text for this property
 
614
   * @return tip text for this property suitable for
 
615
   * displaying in the explorer/experimenter gui
 
616
   */
 
617
  public String unprunedTipText() {
 
618
    return "Whether pruning is performed.";
 
619
  }
 
620
 
 
621
  /**
 
622
   * Get the value of unpruned.
 
623
   *
 
624
   * @return Value of unpruned.
 
625
   */
 
626
  public boolean getUnpruned() {
 
627
 
 
628
    return m_unpruned;
 
629
  }
 
630
 
 
631
  /**
 
632
   * Set the value of unpruned.
 
633
   * @param v  Value to assign to unpruned.
 
634
   */
 
635
  public void setUnpruned(boolean v) {
 
636
 
 
637
    m_unpruned = v;
 
638
  }
 
639
 
 
640
  /**
 
641
   * Returns the tip text for this property
 
642
   * @return tip text for this property suitable for
 
643
   * displaying in the explorer/experimenter gui
 
644
   */
 
645
  public String relabelTipText() {
 
646
    return "Whether relabelling is allowed during grafting.";
 
647
  }
 
648
 
 
649
  /**
 
650
   * Get the value of relabelling
 
651
   *
 
652
   * @return Value of relabelling.
 
653
   */
 
654
  public boolean getRelabel() {
 
655
 
 
656
    return m_relabel;
 
657
  }
 
658
 
 
659
  /**
 
660
   * Set the value of relabelling. 
 
661
   *
 
662
   * @param v  Value to assign to relabelling flag.
 
663
   */
 
664
  public void setRelabel(boolean v) {
 
665
    m_relabel = v;
 
666
  }
 
667
 
 
668
  /**
 
669
   * Returns the tip text for this property
 
670
   * @return tip text for this property suitable for
 
671
   * displaying in the explorer/experimenter gui
 
672
   */
 
673
  public String confidenceFactorTipText() {
 
674
    return "The confidence factor used for pruning (smaller values incur "
 
675
      + "more pruning).";
 
676
  }
 
677
 
 
678
  /**
 
679
   * Get the value of CF.
 
680
   *
 
681
   * @return Value of CF.
 
682
   */
 
683
  public float getConfidenceFactor() {
 
684
    
 
685
    return m_CF;
 
686
  }
 
687
  
 
688
  /**
 
689
   * Set the value of CF.
 
690
   *
 
691
   * @param v  Value to assign to CF.
 
692
   */
 
693
  public void setConfidenceFactor(float v) {
 
694
    
 
695
    m_CF = v;
 
696
  }
 
697
 
 
698
  /**
 
699
   * Returns the tip text for this property
 
700
   * @return tip text for this property suitable for
 
701
   * displaying in the explorer/experimenter gui
 
702
   */
 
703
  public String minNumObjTipText() {
 
704
    return "The minimum number of instances per leaf.";
 
705
  }
 
706
 
 
707
  /**
 
708
   * Get the value of minNumObj.
 
709
   *
 
710
   * @return Value of minNumObj.
 
711
   */
 
712
  public int getMinNumObj() {
 
713
    
 
714
    return m_minNumObj;
 
715
  }
 
716
  
 
717
  /**
 
718
   * Set the value of minNumObj.
 
719
   *
 
720
   * @param v  Value to assign to minNumObj.
 
721
   */
 
722
  public void setMinNumObj(int v) {
 
723
    
 
724
    m_minNumObj = v;
 
725
  }
 
726
 
 
727
  /**
 
728
   * Returns the tip text for this property
 
729
   * @return tip text for this property suitable for
 
730
   * displaying in the explorer/experimenter gui
 
731
   */
 
732
  public String binarySplitsTipText() {
 
733
    return "Whether to use binary splits on nominal attributes when "
 
734
      + "building the trees.";
 
735
  }
 
736
  
 
737
  /**
 
738
   * Get the value of binarySplits.
 
739
   *
 
740
   * @return Value of binarySplits.
 
741
   */
 
742
  public boolean getBinarySplits() {
 
743
 
 
744
    return m_binarySplits;
 
745
  }
 
746
 
 
747
  /**
 
748
   * Set the value of binarySplits.
 
749
   *
 
750
   * @param v  Value to assign to binarySplits.
 
751
   */
 
752
  public void setBinarySplits(boolean v) {
 
753
    
 
754
    m_binarySplits = v;
 
755
  }
 
756
  
 
757
  /**
 
758
   * Returns the tip text for this property
 
759
   * @return tip text for this property suitable for
 
760
   * displaying in the explorer/experimenter gui
 
761
   */
 
762
  public String subtreeRaisingTipText() {
 
763
    return "Whether to consider the subtree raising operation when pruning.";
 
764
  }
 
765
 
 
766
  /**
 
767
   * Get the value of subtreeRaising.
 
768
   *
 
769
   * @return Value of subtreeRaising.
 
770
   */
 
771
  public boolean getSubtreeRaising() {
 
772
    
 
773
    return m_subtreeRaising;
 
774
  }
 
775
  
 
776
  /**
 
777
   * Set the value of subtreeRaising.
 
778
   *
 
779
   * @param v  Value to assign to subtreeRaising.
 
780
   */
 
781
  public void setSubtreeRaising(boolean v) {
 
782
    
 
783
    m_subtreeRaising = v;
 
784
  }
 
785
 
 
786
  /**
 
787
   * Returns the tip text for this property
 
788
   * @return tip text for this property suitable for
 
789
   * displaying in the explorer/experimenter gui
 
790
   */
 
791
  public String saveInstanceDataTipText() {
 
792
    return "Whether to save the training data for visualization.";
 
793
  }
 
794
 
 
795
  /**
 
796
   * Check whether instance data is to be saved.
 
797
   *
 
798
   * @return true if instance data is saved
 
799
   */
 
800
  public boolean getSaveInstanceData() {
 
801
    
 
802
    return m_noCleanup;
 
803
  }
 
804
  
 
805
  /**
 
806
   * Set whether instance data is to be saved.
 
807
   * @param v true if instance data is to be saved
 
808
   */
 
809
  public void setSaveInstanceData(boolean v) {
 
810
 
 
811
    m_noCleanup = v;
 
812
  }
 
813
 
 
814
  /**
 
815
   * Main method for testing this class
 
816
   *
 
817
   * @param argv the commandline options
 
818
   */
 
819
  public static void main(String [] argv){
 
820
    runClassifier(new J48graft(), argv);
 
821
  }
 
822
}