[29] | 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 | * NaiveBayesUpdateable.java |
---|
| 19 | * Copyright (C) 1999 University of Waikato, Hamilton, New Zealand |
---|
| 20 | * |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | package weka.classifiers.bayes; |
---|
| 24 | |
---|
| 25 | import weka.classifiers.UpdateableClassifier; |
---|
| 26 | import weka.core.RevisionUtils; |
---|
| 27 | import weka.core.TechnicalInformation; |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | <!-- globalinfo-start --> |
---|
| 31 | * Class for a Naive Bayes classifier using estimator classes. This is the updateable version of NaiveBayes.<br/> |
---|
| 32 | * This classifier will use a default precision of 0.1 for numeric attributes when buildClassifier is called with zero training instances.<br/> |
---|
| 33 | * <br/> |
---|
| 34 | * For more information on Naive Bayes classifiers, see<br/> |
---|
| 35 | * <br/> |
---|
| 36 | * George H. John, Pat Langley: Estimating Continuous Distributions in Bayesian Classifiers. In: Eleventh Conference on Uncertainty in Artificial Intelligence, San Mateo, 338-345, 1995. |
---|
| 37 | * <p/> |
---|
| 38 | <!-- globalinfo-end --> |
---|
| 39 | * |
---|
| 40 | <!-- technical-bibtex-start --> |
---|
| 41 | * BibTeX: |
---|
| 42 | * <pre> |
---|
| 43 | * @inproceedings{John1995, |
---|
| 44 | * address = {San Mateo}, |
---|
| 45 | * author = {George H. John and Pat Langley}, |
---|
| 46 | * booktitle = {Eleventh Conference on Uncertainty in Artificial Intelligence}, |
---|
| 47 | * pages = {338-345}, |
---|
| 48 | * publisher = {Morgan Kaufmann}, |
---|
| 49 | * title = {Estimating Continuous Distributions in Bayesian Classifiers}, |
---|
| 50 | * year = {1995} |
---|
| 51 | * } |
---|
| 52 | * </pre> |
---|
| 53 | * <p/> |
---|
| 54 | <!-- technical-bibtex-end --> |
---|
| 55 | * |
---|
| 56 | <!-- options-start --> |
---|
| 57 | * Valid options are: <p/> |
---|
| 58 | * |
---|
| 59 | * <pre> -K |
---|
| 60 | * Use kernel density estimator rather than normal |
---|
| 61 | * distribution for numeric attributes</pre> |
---|
| 62 | * |
---|
| 63 | * <pre> -D |
---|
| 64 | * Use supervised discretization to process numeric attributes |
---|
| 65 | * </pre> |
---|
| 66 | * |
---|
| 67 | * <pre> -O |
---|
| 68 | * Display model in old format (good when there are many classes) |
---|
| 69 | * </pre> |
---|
| 70 | * |
---|
| 71 | <!-- options-end --> |
---|
| 72 | * |
---|
| 73 | * @author Len Trigg (trigg@cs.waikato.ac.nz) |
---|
| 74 | * @author Eibe Frank (eibe@cs.waikato.ac.nz) |
---|
| 75 | * @version $Revision: 1.11 $ |
---|
| 76 | */ |
---|
| 77 | public class NaiveBayesUpdateable extends NaiveBayes |
---|
| 78 | implements UpdateableClassifier { |
---|
| 79 | |
---|
| 80 | /** for serialization */ |
---|
| 81 | static final long serialVersionUID = -5354015843807192221L; |
---|
| 82 | |
---|
| 83 | /** |
---|
| 84 | * Returns a string describing this classifier |
---|
| 85 | * @return a description of the classifier suitable for |
---|
| 86 | * displaying in the explorer/experimenter gui |
---|
| 87 | */ |
---|
| 88 | public String globalInfo() { |
---|
| 89 | return "Class for a Naive Bayes classifier using estimator classes. This is the " |
---|
| 90 | +"updateable version of NaiveBayes.\n" |
---|
| 91 | +"This classifier will use a default precision of 0.1 for numeric attributes " |
---|
| 92 | +"when buildClassifier is called with zero training instances.\n\n" |
---|
| 93 | +"For more information on Naive Bayes classifiers, see\n\n" |
---|
| 94 | + getTechnicalInformation().toString(); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | * Returns an instance of a TechnicalInformation object, containing |
---|
| 99 | * detailed information about the technical background of this class, |
---|
| 100 | * e.g., paper reference or book this class is based on. |
---|
| 101 | * |
---|
| 102 | * @return the technical information about this class |
---|
| 103 | */ |
---|
| 104 | public TechnicalInformation getTechnicalInformation() { |
---|
| 105 | return super.getTechnicalInformation(); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | /** |
---|
| 109 | * Set whether supervised discretization is to be used. |
---|
| 110 | * |
---|
| 111 | * @param newblah true if supervised discretization is to be used. |
---|
| 112 | */ |
---|
| 113 | public void setUseSupervisedDiscretization(boolean newblah) { |
---|
| 114 | |
---|
| 115 | if (newblah) { |
---|
| 116 | throw new IllegalArgumentException("Can't use discretization " + |
---|
| 117 | "in NaiveBayesUpdateable!"); |
---|
| 118 | } |
---|
| 119 | m_UseDiscretization = false; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | /** |
---|
| 123 | * Returns the revision string. |
---|
| 124 | * |
---|
| 125 | * @return the revision |
---|
| 126 | */ |
---|
| 127 | public String getRevision() { |
---|
| 128 | return RevisionUtils.extract("$Revision: 1.11 $"); |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
| 132 | * Main method for testing this class. |
---|
| 133 | * |
---|
| 134 | * @param argv the options |
---|
| 135 | */ |
---|
| 136 | public static void main(String [] argv) { |
---|
| 137 | runClassifier(new NaiveBayesUpdateable(), argv); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|