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


Java ZeroR.buildClassifier方法代码示例

本文整理汇总了Java中weka.classifiers.rules.ZeroR.buildClassifier方法的典型用法代码示例。如果您正苦于以下问题:Java ZeroR.buildClassifier方法的具体用法?Java ZeroR.buildClassifier怎么用?Java ZeroR.buildClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在weka.classifiers.rules.ZeroR的用法示例。


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

示例1: buildClassifier

import weka.classifiers.rules.ZeroR; //导入方法依赖的package包/类
/**
  * Generates the classifier.
  *
  * @param instances set of instances serving as training data 
  * @throws Exception if the classifier has not been generated successfully
  */
 public void buildClassifier(Instances instances) throws Exception {
   
   // can classifier handle the data?
   getCapabilities().testWithFail(instances);

   // remove instances with missing class
   instances = new Instances(instances);
   instances.deleteWithMissingClass();
   
   m_NumClasses = instances.numClasses();
   m_ClassType = instances.classAttribute().type();
   m_Train = new Instances(instances, 0, instances.numInstances());

   // Throw away initial instances until within the specified window size
   if ((m_WindowSize > 0) && (instances.numInstances() > m_WindowSize)) {
     m_Train = new Instances(m_Train, 
		      m_Train.numInstances()-m_WindowSize, 
		      m_WindowSize);
   }

   m_NumAttributesUsed = 0.0;
   for (int i = 0; i < m_Train.numAttributes(); i++) {
     if ((i != m_Train.classIndex()) && 
  (m_Train.attribute(i).isNominal() ||
   m_Train.attribute(i).isNumeric())) {
m_NumAttributesUsed += 1.0;
     }
   }
   
   m_NNSearch.setInstances(m_Train);

   // Invalidate any currently cross-validation selected k
   m_kNNValid = false;
   
   m_defaultModel = new ZeroR();
   m_defaultModel.buildClassifier(instances);
 }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:44,代码来源:IBk.java

示例2: buildClassifier

import weka.classifiers.rules.ZeroR; //导入方法依赖的package包/类
/**
  * Builds the classifiers.
  *
  * @param insts the training data.
  * @throws Exception if a classifier can't be built
  */
 public void buildClassifier(Instances insts) throws Exception {

   Instances newInsts;

   // can classifier handle the data?
   getCapabilities().testWithFail(insts);

   // remove instances with missing class
   insts = new Instances(insts);
   insts.deleteWithMissingClass();
   
   if (m_Classifier == null) {
     throw new Exception("No base classifier has been set!");
   }
   m_ZeroR = new ZeroR();
   m_ZeroR.buildClassifier(insts);

   int numClassifiers = insts.numClasses() - 1;

   numClassifiers = (numClassifiers == 0) ? 1 : numClassifiers;

   if (numClassifiers == 1) {
     m_Classifiers = Classifier.makeCopies(m_Classifier, 1);
     m_Classifiers[0].buildClassifier(insts);
   } else {
     m_Classifiers = Classifier.makeCopies(m_Classifier, numClassifiers);
     m_ClassFilters = new MakeIndicator[numClassifiers];

     for (int i = 0; i < m_Classifiers.length; i++) {
m_ClassFilters[i] = new MakeIndicator();
m_ClassFilters[i].setAttributeIndex("" + (insts.classIndex() + 1));
m_ClassFilters[i].setValueIndices(""+(i+2)+"-last");
m_ClassFilters[i].setNumeric(false);
m_ClassFilters[i].setInputFormat(insts);
newInsts = Filter.useFilter(insts, m_ClassFilters[i]);
m_Classifiers[i].buildClassifier(newInsts);
     }
   }
 }
 
开发者ID:williamClanton,项目名称:jbossBA,代码行数:46,代码来源:OrdinalClassClassifier.java

示例3: initializeClassifier

import weka.classifiers.rules.ZeroR; //导入方法依赖的package包/类
/**
  * Initialize classifier.
  *
  * @param data the training data
  * @throws Exception if the classifier could not be initialized successfully
  */
 public void initializeClassifier(Instances data) throws Exception {

   // can classifier handle the data?
   getCapabilities().testWithFail(data);

   // remove instances with missing class
   m_Data = new Instances(data);
   m_Data.deleteWithMissingClass();

   // Add the model for the mean first
   m_zeroR = new ZeroR();
   m_zeroR.buildClassifier(m_Data);
   
   // only class? -> use only ZeroR model
   if (m_Data.numAttributes() == 1) {
     System.err.println(
  "Cannot build model (only class attribute present in data!), "
  + "using ZeroR model instead!");
     m_SuitableData = false;
     return;
   }
   else {
     m_SuitableData = true;
   }
  
   // Initialize list of classifiers and data
   m_Classifiers = new ArrayList<Classifier>(m_NumIterations);
   m_Data = residualReplace(m_Data, m_zeroR, false);

   // Calculate sum of squared errors
   m_SSE = 0;
   m_Diff = Double.MAX_VALUE;
   for (int i = 0; i < m_Data.numInstances(); i++) {
     m_SSE += m_Data.instance(i).weight() *
m_Data.instance(i).classValue() * m_Data.instance(i).classValue();
   }
   if (m_Debug) {
     System.err.println("Sum of squared residuals "
		 +"(predicting the mean) : " + m_SSE);
   }
 }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:48,代码来源:AdditiveRegression.java

示例4: buildClassifier

import weka.classifiers.rules.ZeroR; //导入方法依赖的package包/类
/**
  * Build the classifier on the supplied data
  *
  * @param data the training data
  * @throws Exception if the classifier could not be built successfully
  */
 public void buildClassifier(Instances data) throws Exception {

   super.buildClassifier(data);

   // can classifier handle the data?
   getCapabilities().testWithFail(data);

   // remove instances with missing class
   Instances newData = new Instances(data);
   newData.deleteWithMissingClass();

   double sum = 0;
   double temp_sum = 0;
   // Add the model for the mean first
   m_zeroR = new ZeroR();
   m_zeroR.buildClassifier(newData);
   
   // only class? -> use only ZeroR model
   if (newData.numAttributes() == 1) {
     System.err.println(
  "Cannot build model (only class attribute present in data!), "
  + "using ZeroR model instead!");
     m_SuitableData = false;
     return;
   }
   else {
     m_SuitableData = true;
   }
   
   newData = residualReplace(newData, m_zeroR, false);
   for (int i = 0; i < newData.numInstances(); i++) {
     sum += newData.instance(i).weight() *
newData.instance(i).classValue() * newData.instance(i).classValue();
   }
   if (m_Debug) {
     System.err.println("Sum of squared residuals "
		 +"(predicting the mean) : " + sum);
   }

   m_NumIterationsPerformed = 0;
   do {
     temp_sum = sum;

     // Build the classifier
     m_Classifiers[m_NumIterationsPerformed].buildClassifier(newData);

     newData = residualReplace(newData, m_Classifiers[m_NumIterationsPerformed], true);
     sum = 0;
     for (int i = 0; i < newData.numInstances(); i++) {
sum += newData.instance(i).weight() *
  newData.instance(i).classValue() * newData.instance(i).classValue();
     }
     if (m_Debug) {
System.err.println("Sum of squared residuals : "+sum);
     }
     m_NumIterationsPerformed++;
   } while (((temp_sum - sum) > Utils.SMALL) && 
     (m_NumIterationsPerformed < m_Classifiers.length));
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:66,代码来源:AdditiveRegression.java


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