Tabnine Logo
NaiveBayes
Code IndexAdd Tabnine to your IDE (free)

How to use
NaiveBayes
in
weka.classifiers.bayes

Best Java code snippets using weka.classifiers.bayes.NaiveBayes (Showing top 20 results out of 315)

origin: stackoverflow.com

 Classifier cModel = (Classifier)new NaiveBayes();  
cModel.buildClassifier(isTrainingSet);  

weka.core.SerializationHelper.write("/some/where/nBayes.model", cModel);

Classifier cls = (Classifier) weka.core.SerializationHelper.read("/some/where/nBayes.model");

// Test the model
Evaluation eTest = new Evaluation(isTrainingSet);
eTest.evaluateModel(cls, isTrainingSet);
origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Returns the Capabilities of this filter.
 *
 * @return the capabilities of this object
 * @see Capabilities
 */
@Override
public Capabilities getCapabilities() {
 return new NaiveBayes().getCapabilities();
}
origin: nz.ac.waikato.cms.weka/weka-stable

 /**
  * Main method for testing this class.
  * 
  * @param argv the options
  */
 public static void main(String[] argv) {
  runClassifier(new NaiveBayes(), argv);
 }
}
origin: stackoverflow.com

NaiveBayes nB = new NaiveBayes();
nB.buildClassifier(train);
origin: nz.ac.waikato.cms.weka/weka-stable

@Override
protected Instances process(Instances instances) throws Exception {
 if (m_estimator == null) {
  m_estimator = new NaiveBayes();
   trainingData = Filter.useFilter(instances, m_remove);
  m_estimator.buildClassifier(trainingData);
  Estimator[][] estimators = m_estimator.getConditionalEstimators();
  Instances header = m_estimator.getHeader();
  int index = 0;
  for (int i = 0; i < header.numAttributes(); i++) {
origin: stackoverflow.com

 public class Run {
  public static void main(String[] args) throws Exception {

    ConverterUtils.DataSource source1 = new ConverterUtils.DataSource("./data/train.arff");
    Instances train = source1.getDataSet();
    // setting class attribute if the data format does not provide this information
    // For example, the XRFF format saves the class attribute information as well
    if (train.classIndex() == -1)
      train.setClassIndex(train.numAttributes() - 1);

    ConverterUtils.DataSource source2 = new ConverterUtils.DataSource("./data/test.arff");
    Instances test = source2.getDataSet();
    // setting class attribute if the data format does not provide this information
    // For example, the XRFF format saves the class attribute information as well
    if (test.classIndex() == -1)
      test.setClassIndex(train.numAttributes() - 1);

    // model

    NaiveBayes naiveBayes = new NaiveBayes();
    naiveBayes.buildClassifier(train);

    // this does the trick  
    double label = naiveBayes.classifyInstance(test.instance(0));
    test.instance(0).setClassValue(label);

    System.out.println(test.instance(0).stringValue(4));
  }
}
origin: nz.ac.waikato.cms.weka/weka-stable

getCapabilities().testWithFail(instances);
while (enumInsts.hasMoreElements()) {
 Instance instance = enumInsts.nextElement();
 updateClassifier(instance);
origin: nz.ac.waikato.cms.weka/DTNB

m_NB.updateClassifier(instance);
double[] nbDist = m_NB.distributionForInstance(instance);
instance.setWeight(-instance.weight());
m_NB.updateClassifier(instance);
origin: nz.ac.waikato.cms.weka/DTNB

m_NB = new NaiveBayes();
m_NB.buildClassifier(m_theInstances);
origin: Waikato/weka-trunk

@Override
protected Instances process(Instances instances) throws Exception {
 if (m_estimator == null) {
  m_estimator = new NaiveBayes();
   trainingData = Filter.useFilter(instances, m_remove);
  m_estimator.buildClassifier(trainingData);
  Estimator[][] estimators = m_estimator.getConditionalEstimators();
  Instances header = m_estimator.getHeader();
  int index = 0;
  for (int i = 0; i < header.numAttributes(); i++) {
origin: Waikato/weka-trunk

 /**
  * Main method for testing this class.
  * 
  * @param argv the options
  */
 public static void main(String[] argv) {
  runClassifier(new NaiveBayes(), argv);
 }
}
origin: Waikato/weka-trunk

getCapabilities().testWithFail(instances);
while (enumInsts.hasMoreElements()) {
 Instance instance = enumInsts.nextElement();
 updateClassifier(instance);
origin: nz.ac.waikato.cms.weka/DTNB

  class_distribs[i][(int) inst.classValue()] -= inst.weight();
  inst.setWeight(-inst.weight());
  m_NB.updateClassifier(inst);
  inst.setWeight(-inst.weight());
 } else {
 double[] nbDist = m_NB.distributionForInstance(inst);
 m_NB.updateClassifier(inst);
} else {
 class_distribs[i][0] += (inst.classValue() * inst.weight());
origin: nz.ac.waikato.cms.weka/distributedWekaBase

public AggregateableFilteredClassifier() {
 m_Classifier = new NaiveBayes();
}
origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Test
public void testScoreWithClassifier() throws Exception {
 Instances train = new Instances(new BufferedReader(new StringReader(
  CorrelationMatrixMapTaskTest.IRIS)));
 train.setClassIndex(train.numAttributes() - 1);
 NaiveBayes bayes = new NaiveBayes();
 bayes.buildClassifier(train);
 WekaScoringMapTask task = new WekaScoringMapTask();
 task.setModel(bayes, train, train);
 assertEquals(0, task.getMissingMismatchAttributeInfo().length());
 assertEquals(3, task.getPredictionLabels().size());
 for (int i = 0; i < train.numInstances(); i++) {
  assertEquals(3, task.processInstance(train.instance(i)).length);
 }
}
origin: Waikato/weka-trunk

/**
 * Returns the Capabilities of this filter.
 *
 * @return the capabilities of this object
 * @see Capabilities
 */
@Override
public Capabilities getCapabilities() {
 return new NaiveBayes().getCapabilities();
}
origin: nz.ac.waikato.cms.weka/weka-stable

/** Creates a default NaiveBayes */
public Classifier getClassifier() {
 return new NaiveBayes();
}
origin: nz.ac.waikato.cms.weka/DTNB

m_NB = new NaiveBayes();
m_NB.buildClassifier(m_theInstances);
origin: stackoverflow.com

 Classifier Mode; // a parent class
if(alg.equals("DecisionStump")) {
 Mode = new DecisionStump();
} else if(alg.equals("NaiveBayes")) {
 Mode = new NaiveBayes();
}
origin: nz.ac.waikato.cms.weka/distributedWekaBase

@Test
public void testScoreWithClassifierSomeMissingFields() throws Exception {
 Instances train = new Instances(new BufferedReader(new StringReader(
  CorrelationMatrixMapTaskTest.IRIS)));
 train.setClassIndex(train.numAttributes() - 1);
 NaiveBayes bayes = new NaiveBayes();
 bayes.buildClassifier(train);
 WekaScoringMapTask task = new WekaScoringMapTask();
 Remove r = new Remove();
 r.setAttributeIndices("1");
 r.setInputFormat(train);
 Instances test = Filter.useFilter(train, r);
 task.setModel(bayes, train, test);
 assertTrue(task.getMissingMismatchAttributeInfo().length() > 0);
 assertTrue(task.getMissingMismatchAttributeInfo().equals(
  "sepallength missing from incoming data\n"));
 assertEquals(3, task.getPredictionLabels().size());
 for (int i = 0; i < test.numInstances(); i++) {
  assertEquals(3, task.processInstance(test.instance(i)).length);
 }
}
weka.classifiers.bayesNaiveBayes

Javadoc

Class for a Naive Bayes classifier using estimator classes. Numeric estimator precision values are chosen based on analysis of the training data. For this reason, the classifier is not an UpdateableClassifier (which in typical usage are initialized with zero training instances) -- if you need the UpdateableClassifier functionality, use the NaiveBayesUpdateable classifier. The NaiveBayesUpdateable classifier will use a default precision of 0.1 for numeric attributes when buildClassifier is called with zero training instances.

For more information on Naive Bayes classifiers, see

George H. John, Pat Langley: Estimating Continuous Distributions in Bayesian Classifiers. In: Eleventh Conference on Uncertainty in Artificial Intelligence, San Mateo, 338-345, 1995.

BibTeX:

 
@inproceedings{John1995, 
address = {San Mateo}, 
author = {George H. John and Pat Langley}, 
booktitle = {Eleventh Conference on Uncertainty in Artificial Intelligence}, 
pages = {338-345}, 
publisher = {Morgan Kaufmann}, 
title = {Estimating Continuous Distributions in Bayesian Classifiers}, 
year = {1995} 
} 

Valid options are:

 
-K 
Use kernel density estimator rather than normal 
distribution for numeric attributes 
 
-D 
Use supervised discretization to process numeric attributes 
 
-O 
Display model in old format (good when there are many classes) 

Most used methods

  • <init>
  • buildClassifier
    Generates the classifier.
  • updateClassifier
    Updates the classifier with the given instance.
  • getCapabilities
    Returns default capabilities of the classifier.
  • getConditionalEstimators
    Get all the conditional estimators.
  • getHeader
    Return the header that this classifier was trained with
  • getTechnicalInformation
    Returns an instance of a TechnicalInformation object, containing detailed information about the tech
  • getUseSupervisedDiscretization
    Get whether supervised discretization is to be used.
  • pad
  • runClassifier
  • setDisplayModelInOldFormat
    Set whether to display model output in the old, original format.
  • setUseKernelEstimator
    Sets if kernel estimator is to be used.
  • setDisplayModelInOldFormat,
  • setUseKernelEstimator,
  • setUseSupervisedDiscretization,
  • toStringOriginal,
  • classifyInstance,
  • distributionForInstance,
  • toString

Popular in Java

  • Making http requests using okhttp
  • getApplicationContext (Context)
  • setScale (BigDecimal)
  • setContentView (Activity)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Runner (org.openjdk.jmh.runner)
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now