/** * Construct a new NBNode * * @param header the instances structure of the data we're learning from * @param nbWeightThreshold the weight mass to see before allowing naive Bayes * to predict * @throws Exception if a problem occurs */ public NBNode(Instances header, double nbWeightThreshold) throws Exception { m_nbWeightThreshold = nbWeightThreshold; m_bayes = new NaiveBayesUpdateable(); m_bayes.buildClassifier(header); }
/** * Returns a string describing this classifier * @return a description of the classifier suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "Class for a Naive Bayes classifier using estimator classes. This is the " +"updateable version of NaiveBayes.\n" +"This classifier will use a default precision of 0.1 for numeric attributes " +"when buildClassifier is called with zero training instances.\n\n" +"For more information on Naive Bayes classifiers, see\n\n" + getTechnicalInformation().toString(); }
/** * Main method for testing this class. * * @param argv the options */ public static void main(String [] argv) { runClassifier(new NaiveBayesUpdateable(), argv); } }
public AggregateableFilteredClassifierUpdateable() { m_Classifier = new NaiveBayesUpdateable(); }
/** * Return a textual description of the node * * @return a <code>String</code> value */ public String toString() { return m_nb.toString(); }
@Override public void updateNode(Instance inst) throws Exception { super.updateNode(inst); try { m_bayes.updateClassifier(inst); } catch (Exception e) { e.printStackTrace(); } }
@Override public double[] getDistribution(Instance inst, Attribute classAtt) throws Exception { // totalWeight - m_weightSeenAtLastSplitEval is the weight mass // observed by this node's NB model boolean doNB = m_nbWeightThreshold == 0 ? true : (totalWeight() - m_weightSeenAtLastSplitEval > m_nbWeightThreshold); if (doNB) { return m_bayes.distributionForInstance(inst); } return super.getDistribution(inst, classAtt); }
@Override public void updateNode(Instance inst) throws Exception { String trueClass = inst.classAttribute().value((int) inst.classValue()); int trueClassIndex = (int) inst.classValue(); if (majorityClass().equals(trueClass)) { m_majClassCorrectWeight += inst.weight(); } if (m_bayes.classifyInstance(inst) == trueClassIndex) { m_nbCorrectWeight += inst.weight(); } super.updateNode(inst); }
/** * Default constructor. */ public FilteredClassifierUpdateable() { super(); m_Classifier = new weka.classifiers.bayes.NaiveBayesUpdateable(); m_Filter = new weka.filters.AllFilter(); }
/** * Return a textual description of the node * * @return a <code>String</code> value */ public String toString() { return m_nb.toString(); }
@Override public void updateNode(Instance inst) throws Exception { super.updateNode(inst); try { m_bayes.updateClassifier(inst); } catch (Exception e) { e.printStackTrace(); } }
@Override public double[] getDistribution(Instance inst, Attribute classAtt) throws Exception { // totalWeight - m_weightSeenAtLastSplitEval is the weight mass // observed by this node's NB model boolean doNB = m_nbWeightThreshold == 0 ? true : (totalWeight() - m_weightSeenAtLastSplitEval > m_nbWeightThreshold); if (doNB) { return m_bayes.distributionForInstance(inst); } return super.getDistribution(inst, classAtt); }
@Override public void updateNode(Instance inst) throws Exception { String trueClass = inst.classAttribute().value((int) inst.classValue()); int trueClassIndex = (int) inst.classValue(); if (majorityClass().equals(trueClass)) { m_majClassCorrectWeight += inst.weight(); } if (m_bayes.classifyInstance(inst) == trueClassIndex) { m_nbCorrectWeight += inst.weight(); } super.updateNode(inst); }
/** * Construct a new NBNode * * @param header the instances structure of the data we're learning from * @param nbWeightThreshold the weight mass to see before allowing naive Bayes * to predict * @throws Exception if a problem occurs */ public NBNode(Instances header, double nbWeightThreshold) throws Exception { m_nbWeightThreshold = nbWeightThreshold; m_bayes = new NaiveBayesUpdateable(); m_bayes.buildClassifier(header); }
/** Creates a default NaiveBayesUpdateable */ public Classifier getClassifier() { return new NaiveBayesUpdateable(); }
/** * Main method for testing this class. * * @param argv the options */ public static void main(String [] argv) { runClassifier(new NaiveBayesUpdateable(), argv); } }
@Override protected void printLeafModels(StringBuffer buff) { buff.append("NB adaptive" + m_leafNum).append("\n") .append(m_bayes.toString()); }
((NaiveBayesUpdateable)copies[j]).updateClassifier(test.instance(k));
/** * Return the probability for a class value * * @param classIndex the index of the class value * @param instance the instance to generate a probability for * @param theSubset the subset to consider * @return a probability * @exception Exception if an error occurs */ public double classProb(int classIndex, Instance instance, int theSubset) throws Exception { m_disc.input(instance); Instance temp = m_disc.output(); return m_nb.distributionForInstance(temp)[classIndex]; }
/** * Returns a string describing this classifier * @return a description of the classifier suitable for * displaying in the explorer/experimenter gui */ public String globalInfo() { return "Class for a Naive Bayes classifier using estimator classes. This is the " +"updateable version of NaiveBayes.\n" +"This classifier will use a default precision of 0.1 for numeric attributes " +"when buildClassifier is called with zero training instances.\n\n" +"For more information on Naive Bayes classifiers, see\n\n" + getTechnicalInformation().toString(); }