当前位置: 首页>>代码示例>>Java>>正文


Java NaiveBayesUpdateable类代码示例

本文整理汇总了Java中weka.classifiers.bayes.NaiveBayesUpdateable的典型用法代码示例。如果您正苦于以下问题:Java NaiveBayesUpdateable类的具体用法?Java NaiveBayesUpdateable怎么用?Java NaiveBayesUpdateable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NaiveBayesUpdateable类属于weka.classifiers.bayes包,在下文中一共展示了NaiveBayesUpdateable类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getClassifierClassName

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
 * Get classifier's class name by a short name
 * */
public static String getClassifierClassName(String classifierName) {
	String className = "";
	switch (classifierName) {
	case "SGD":
		className = SGD.class.toString();
		break;
	case "SGDText":
		className = SGDText.class.toString();
		break;
	case "J48":
		className = J48.class.toString();
		break;
	case "PART":
		className = PART.class.toString();
		break;
	case "NaiveBayes":
		className = NaiveBayes.class.toString();
		break;
	case "NBUpdateable":
		className = NaiveBayesUpdateable.class.toString();
		break;
	case "AdaBoostM1":
		className = AdaBoostM1.class.toString();
		break;
	case "LogitBoost":
		className = LogitBoost.class.toString();
		break;
	case "Bagging":
		className = Bagging.class.toString();
		break;
	case "Stacking":
		className = Stacking.class.toString();
		break;
	case "AdditiveRegression":
		className = AdditiveRegression.class.toString();
		break;
	case "Apriori":
		className = Apriori.class.toString();
		break;
	default:
		className = SGD.class.toString();
	}
	className = className.substring(6);
	return className;
}
 
开发者ID:Eyasics,项目名称:recon,代码行数:49,代码来源:Util.java

示例2: crossValidate

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
  * Utility method for fast 5-fold cross validation of a naive bayes
  * model
  *
  * @param fullModel a <code>NaiveBayesUpdateable</code> value
  * @param trainingSet an <code>Instances</code> value
  * @param r a <code>Random</code> value
  * @return a <code>double</code> value
  * @exception Exception if an error occurs
  */
 public static double crossValidate(NaiveBayesUpdateable fullModel,
		       Instances trainingSet,
		       Random r) throws Exception {
   // make some copies for fast evaluation of 5-fold xval
   Classifier [] copies = AbstractClassifier.makeCopies(fullModel, 5);
   Evaluation eval = new Evaluation(trainingSet);
   // make some splits
   for (int j = 0; j < 5; j++) {
     Instances test = trainingSet.testCV(5, j);
     // unlearn these test instances
     for (int k = 0; k < test.numInstances(); k++) {
test.instance(k).setWeight(-test.instance(k).weight());
((NaiveBayesUpdateable)copies[j]).updateClassifier(test.instance(k));
// reset the weight back to its original value
test.instance(k).setWeight(-test.instance(k).weight());
     }
     eval.evaluateModel(copies[j], test);
   }
   return eval.incorrect();
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:31,代码来源:NBTreeNoSplit.java

示例3: crossValidate

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
  * Utility method for fast 5-fold cross validation of a naive bayes
  * model
  *
  * @param fullModel a <code>NaiveBayesUpdateable</code> value
  * @param trainingSet an <code>Instances</code> value
  * @param r a <code>Random</code> value
  * @return a <code>double</code> value
  * @exception Exception if an error occurs
  */
 public static double crossValidate(NaiveBayesUpdateable fullModel,
		       Instances trainingSet,
		       Random r) throws Exception {
   // make some copies for fast evaluation of 5-fold xval
   Classifier [] copies = Classifier.makeCopies(fullModel, 5);
   Evaluation eval = new Evaluation(trainingSet);
   // make some splits
   for (int j = 0; j < 5; j++) {
     Instances test = trainingSet.testCV(5, j);
     // unlearn these test instances
     for (int k = 0; k < test.numInstances(); k++) {
test.instance(k).setWeight(-test.instance(k).weight());
((NaiveBayesUpdateable)copies[j]).updateClassifier(test.instance(k));
// reset the weight back to its original value
test.instance(k).setWeight(-test.instance(k).weight());
     }
     eval.evaluateModel(copies[j], test);
   }
   return eval.incorrect();
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:31,代码来源:NBTreeNoSplit.java

示例4: makeOnlineClassifier

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
public static Classifier makeOnlineClassifier(String wekaClassifier, String[] options) throws Exception {
    switch (WekaOnlineClassificationAlgorithms.valueOf(wekaClassifier)) {
        case naiveBayes:
            NaiveBayesUpdateable naiveBayesUpdateable = new NaiveBayesUpdateable();
            setOptionsForWekaPredictor(options, naiveBayesUpdateable);
            return naiveBayesUpdateable;
        case locallyWeightedLearner:
            LWL lwl = new LWL();
            setOptionsForWekaPredictor(options, lwl);
            return lwl;
        case nearestNeighbors:
            IBk ibk = new IBk();
            setOptionsForWekaPredictor(options, ibk);
            return ibk;
        case onlineDecisionTree:
            HoeffdingTree tree = new HoeffdingTree();
            setOptionsForWekaPredictor(options, tree);
            return tree;
        case stochasticGradientDescent:
            SGD sgd = new SGD();
            setOptionsForWekaPredictor(options, sgd);
            return sgd;
        default:
            return new NaiveBayesUpdateable();
    }
}
 
开发者ID:LakkiB,项目名称:mlstorm,代码行数:27,代码来源:WekaUtils.java

示例5: buildClassifier

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
 * Build the no-split node
 *
 * @param instances an <code>Instances</code> value
 * @exception Exception if an error occurs
 */
public final void buildClassifier(Instances instances) throws Exception {
  m_nb = new NaiveBayesUpdateable();
  m_disc = new Discretize();
  m_disc.setInputFormat(instances);
  Instances temp = Filter.useFilter(instances, m_disc);
  m_nb.buildClassifier(temp);
  if (temp.numInstances() >= 5) {
    m_errors = crossValidate(m_nb, temp, new Random(1));
  }
  m_numSubsets = 1;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:18,代码来源:NBTreeNoSplit.java

示例6: AggregateableFilteredClassifierUpdateable

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
public AggregateableFilteredClassifierUpdateable() {
  m_Classifier = new NaiveBayesUpdateable();
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:4,代码来源:AggregateableFilteredClassifierUpdateable.java

示例7: handleNumericAttribute

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
 * Creates split on numeric attribute.
 * 
 * @exception Exception if something goes wrong
 */
private void handleNumericAttribute(Instances trainInstances)
  throws Exception {

  m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights, true);
  m_c45S.buildClassifier(trainInstances);
  if (m_c45S.numSubsets() == 0) {
    return;
  }
  m_errors = 0;

  Instances[] trainingSets = new Instances[m_complexityIndex];
  trainingSets[0] = new Instances(trainInstances, 0);
  trainingSets[1] = new Instances(trainInstances, 0);
  int subset = -1;

  // populate the subsets
  for (int i = 0; i < trainInstances.numInstances(); i++) {
    Instance instance = trainInstances.instance(i);
    subset = m_c45S.whichSubset(instance);
    if (subset != -1) {
      trainingSets[subset].add((Instance) instance.copy());
    } else {
      double[] weights = m_c45S.weights(instance);
      for (int j = 0; j < m_complexityIndex; j++) {
        Instance temp = (Instance) instance.copy();
        if (weights.length == m_complexityIndex) {
          temp.setWeight(temp.weight() * weights[j]);
        } else {
          temp.setWeight(temp.weight() / m_complexityIndex);
        }
        trainingSets[j].add(temp);
      }
    }
  }

  /*
   * // compute weights (weights of instances per subset m_weights = new
   * double [m_complexityIndex]; for (int i = 0; i < m_complexityIndex; i++) {
   * m_weights[i] = trainingSets[i].sumOfWeights(); }
   * Utils.normalize(m_weights);
   */

  Random r = new Random(1);
  int minNumCount = 0;
  for (int i = 0; i < m_complexityIndex; i++) {
    if (trainingSets[i].numInstances() > 5) {
      minNumCount++;
      // Discretize the sets
      Discretize disc = new Discretize();
      disc.setInputFormat(trainingSets[i]);
      trainingSets[i] = Filter.useFilter(trainingSets[i], disc);

      trainingSets[i].randomize(r);
      trainingSets[i].stratify(5);
      NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
      fullModel.buildClassifier(trainingSets[i]);

      // add the errors for this branch of the split
      m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
    } else {
      for (int j = 0; j < trainingSets[i].numInstances(); j++) {
        m_errors += trainingSets[i].instance(j).weight();
      }
    }
  }

  // Check if minimum number of Instances in at least two
  // subsets.
  if (minNumCount > 1) {
    m_numSubsets = m_complexityIndex;
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:78,代码来源:NBTreeSplit.java

示例8: handleNumericAttribute

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
  * Creates split on numeric attribute.
  *
  * @exception Exception if something goes wrong
  */
 private void handleNumericAttribute(Instances trainInstances)
      throws Exception {

   m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights, true);
   m_c45S.buildClassifier(trainInstances);
   if (m_c45S.numSubsets() == 0) {
     return;
   }
   m_errors = 0;

   Instances [] trainingSets = new Instances [m_complexityIndex];
   trainingSets[0] = new Instances(trainInstances, 0);
   trainingSets[1] = new Instances(trainInstances, 0);
   int subset = -1;
   
   // populate the subsets
   for (int i = 0; i < trainInstances.numInstances(); i++) {
     Instance instance = trainInstances.instance(i);
     subset = m_c45S.whichSubset(instance);
     if (subset != -1) {
trainingSets[subset].add((Instance)instance.copy());
     } else {
double [] weights = m_c45S.weights(instance);
for (int j = 0; j < m_complexityIndex; j++) {
  Instance temp = (Instance)instance.copy();
  if (weights.length == m_complexityIndex) {
    temp.setWeight(temp.weight() * weights[j]);
  } else {
    temp.setWeight(temp.weight() / m_complexityIndex);
  }
  trainingSets[j].add(temp); 
}
     }
   }
   
   /*    // compute weights (weights of instances per subset
   m_weights = new double [m_complexityIndex];
   for (int i = 0; i < m_complexityIndex; i++) {
     m_weights[i] = trainingSets[i].sumOfWeights();
   }
   Utils.normalize(m_weights); */

   Random r = new Random(1);
   int minNumCount = 0;
   for (int i = 0; i < m_complexityIndex; i++) {
     if (trainingSets[i].numInstances() > 5) {
minNumCount++;
// Discretize the sets
	Discretize disc = new Discretize();
disc.setInputFormat(trainingSets[i]);
trainingSets[i] = Filter.useFilter(trainingSets[i], disc);

trainingSets[i].randomize(r);
trainingSets[i].stratify(5);
NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
fullModel.buildClassifier(trainingSets[i]);

// add the errors for this branch of the split
m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
     } else {
for (int j = 0; j < trainingSets[i].numInstances(); j++) {
  m_errors += trainingSets[i].instance(j).weight();
}
     }
   }
   
   // Check if minimum number of Instances in at least two
   // subsets.
   if (minNumCount > 1) {
     m_numSubsets = m_complexityIndex;
   }
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:78,代码来源:NBTreeSplit.java

示例9: handleNumericAttribute

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
  * Creates split on numeric attribute.
  *
  * @exception Exception if something goes wrong
  */
 private void handleNumericAttribute(Instances trainInstances)
      throws Exception {

   m_c45S = new C45Split(m_attIndex, 2, m_sumOfWeights);
   m_c45S.buildClassifier(trainInstances);
   if (m_c45S.numSubsets() == 0) {
     return;
   }
   m_errors = 0;

   Instances [] trainingSets = new Instances [m_complexityIndex];
   trainingSets[0] = new Instances(trainInstances, 0);
   trainingSets[1] = new Instances(trainInstances, 0);
   int subset = -1;
   
   // populate the subsets
   for (int i = 0; i < trainInstances.numInstances(); i++) {
     Instance instance = trainInstances.instance(i);
     subset = m_c45S.whichSubset(instance);
     if (subset != -1) {
trainingSets[subset].add((Instance)instance.copy());
     } else {
double [] weights = m_c45S.weights(instance);
for (int j = 0; j < m_complexityIndex; j++) {
  Instance temp = (Instance)instance.copy();
  if (weights.length == m_complexityIndex) {
    temp.setWeight(temp.weight() * weights[j]);
  } else {
    temp.setWeight(temp.weight() / m_complexityIndex);
  }
  trainingSets[j].add(temp); 
}
     }
   }
   
   /*    // compute weights (weights of instances per subset
   m_weights = new double [m_complexityIndex];
   for (int i = 0; i < m_complexityIndex; i++) {
     m_weights[i] = trainingSets[i].sumOfWeights();
   }
   Utils.normalize(m_weights); */

   Random r = new Random(1);
   int minNumCount = 0;
   for (int i = 0; i < m_complexityIndex; i++) {
     if (trainingSets[i].numInstances() > 5) {
minNumCount++;
// Discretize the sets
	Discretize disc = new Discretize();
disc.setInputFormat(trainingSets[i]);
trainingSets[i] = Filter.useFilter(trainingSets[i], disc);

trainingSets[i].randomize(r);
trainingSets[i].stratify(5);
NaiveBayesUpdateable fullModel = new NaiveBayesUpdateable();
fullModel.buildClassifier(trainingSets[i]);

// add the errors for this branch of the split
m_errors += NBTreeNoSplit.crossValidate(fullModel, trainingSets[i], r);
     } else {
for (int j = 0; j < trainingSets[i].numInstances(); j++) {
  m_errors += trainingSets[i].instance(j).weight();
}
     }
   }
   
   // Check if minimum number of Instances in at least two
   // subsets.
   if (minNumCount > 1) {
     m_numSubsets = m_complexityIndex;
   }
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:78,代码来源:NBTreeSplit.java

示例10: getNaiveBayesModel

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
 * Get the naive bayes model at this node
 *
 * @return a <code>NaiveBayesUpdateable</code> value
 */
public NaiveBayesUpdateable getNaiveBayesModel() {
  return m_nb;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:9,代码来源:NBTreeNoSplit.java

示例11: NBNode

import weka.classifiers.bayes.NaiveBayesUpdateable; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:14,代码来源:NBNode.java


注:本文中的weka.classifiers.bayes.NaiveBayesUpdateable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。