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


Java AbstractClassifier类代码示例

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


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

示例1: crossValidate

import weka.classifiers.AbstractClassifier; //导入依赖的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

示例2: buildInternal

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
protected void buildInternal(MultiLabelInstances train) throws Exception {

	ensemble = new Classifier[numLabels];

	correspondence = new String[numLabels];
	for (int i = 0; i < numLabels; i++) {
		correspondence[i] = train.getDataSet().attribute(labelIndices[i]).name();
	}

	debug("preparing shell");
	brt = new BinaryRelevanceTransformation(train);

	for (int i = 0; i < numLabels; i++) {
		ensemble[i] = AbstractClassifier.makeCopy(baseClassifier);
		Instances shell = brt.transformInstances(i);
		debug("Bulding model " + (i + 1) + "/" + numLabels);
		ensemble[i].buildClassifier(shell);
	}
}
 
开发者ID:ogreyesp,项目名称:JCLAL,代码行数:23,代码来源:BinaryRelevance.java

示例3: next

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
/**
 * Perform another iteration.
 */
public boolean next() throws Exception {
  
  if ((!m_SuitableData) || (m_Classifiers.size() >= m_NumIterations)  ||
      (m_Diff <= Utils.SMALL)) {
    return false;
  }
  
  // Build the classifier
  m_Classifiers.add(AbstractClassifier.makeCopy(m_Classifier));
  m_Classifiers.get(m_Classifiers.size() - 1).buildClassifier(m_Data);
  
  m_Data = residualReplace(m_Data, m_Classifiers.get(m_Classifiers.size() - 1), true);
  double sum = 0;
  for (int i = 0; i < m_Data.numInstances(); i++) {
    sum += 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 : " + sum);
  }
  m_Diff = m_SSE - sum;
  m_SSE = sum;

  return true;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:29,代码来源:AdditiveRegression.java

示例4: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的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();
  
  m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, insts.numClasses());
  m_ClassFilters = new MakeIndicator[insts.numClasses()];
  for (int i = 0; i < insts.numClasses(); i++) {
    m_ClassFilters[i] = new MakeIndicator();
    m_ClassFilters[i].setAttributeIndex("" + (insts.classIndex() + 1));
    m_ClassFilters[i].setValueIndex(i);
    m_ClassFilters[i].setNumeric(true);
    m_ClassFilters[i].setInputFormat(insts);
    newInsts = Filter.useFilter(insts, m_ClassFilters[i]);
    m_Classifiers[i].buildClassifier(newInsts);
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:30,代码来源:ClassificationViaRegression.java

示例5: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {
  	testCapabilities(D);
  	
	int L = D.classIndex();

	if(getDebug()) System.out.print("Creating "+L+" models ("+m_Classifier.getClass().getName()+"): ");
	m_MultiClassifiers = AbstractClassifier.makeCopies(m_Classifier,L);
	m_Templates = new Instances[L];

	for(int j = 0; j < L; j++) {

		//Select only class attribute 'j'
		m_Templates[j] = MLUtils.keepAttributesAt(new Instances(D),new int[]{j},L);
		m_Templates[j].setClassIndex(0);

		//Build the classifier for that class
		m_MultiClassifiers[j].buildClassifier(m_Templates[j]);
		if(getDebug()) System.out.print(" " + (m_Templates[j].classAttribute().name()));

		m_Templates[j] = new Instances(m_Templates[j], 0);
	}
}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:24,代码来源:CR.java

示例6: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {
  	testCapabilities(D);
  	
	int N = D.numInstances();
	int L = D.classIndex();
	h = new Classifier[L];
	u = new Random(m_S);
	D_templates = new Instances[L];

	// Build L probabilistic models, each to predict Y_i | X, Y_{-y}; save the templates.
	for(int j = 0; j < L; j++) {
		// X = [Y[0],...,Y[j-1],Y[j+1],...,Y[L],X]
		D_templates[j] = new Instances(D);
		D_templates[j].setClassIndex(j);
		// train H[j] : X -> Y
		h[j] = AbstractClassifier.forName(getClassifier().getClass().getName(),((AbstractClassifier)getClassifier()).getOptions());
		h[j].buildClassifier(D_templates[j]);
	}
}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:21,代码来源:CDN.java

示例7: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {
	testCapabilities(D);
  	
	int L = D.classIndex();

	if(getDebug()) System.out.print("Creating "+L+" models ("+m_Classifier.getClass().getName()+"): ");
	m_MultiClassifiers = AbstractClassifier.makeCopies(m_Classifier,L);
	m_InstancesTemplates = new Instances[L];

	for(int j = 0; j < L; j++) {

		//Select only class attribute 'j'
		Instances D_j = MLUtils.keepAttributesAt(new Instances(D),new int[]{j},L);
		D_j.setClassIndex(0);

		//Build the classifier for that class
		m_MultiClassifiers[j].buildClassifier(D_j);
		if(getDebug()) System.out.print(" " + (D_j.classAttribute().name()));

		m_InstancesTemplates[j] = new Instances(D_j, 0);
	}
}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:24,代码来源:BR.java

示例8: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {
	testCapabilities(D);

	int L = D.classIndex();
	Random r = new Random(m_S);


	if (getDebug())
		System.out.println("Building "+m_M+" models of "+m_K+" random subsets:");

	m_InstancesTemplates = new Instances[m_M];
	kMap = new int[m_M][m_K];
	m_Classifiers = AbstractClassifier.makeCopies(m_Classifier,m_M);
	for(int i = 0; i < m_M; i++) {
		kMap[i] = SuperLabelUtils.get_k_subset(L,m_K,r);
		if (getDebug()) 
			System.out.println("\tmodel "+(i+1)+"/"+m_M+": "+Arrays.toString(kMap[i])+", P="+m_P+", N="+m_N);
		Instances D_i = SuperLabelUtils.makePartitionDataset(D,kMap[i],m_P,m_N);
		m_Classifiers[i].buildClassifier(D_i);
		m_InstancesTemplates[i] = new Instances(D_i,0);
	}
}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:24,代码来源:RAkEL.java

示例9: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Override
public void buildClassifier(Instances D) throws Exception {

	int L = D.classIndex();
	int N = D.numInstances();

	// Get partition from dataset hierarchy
	kMap = SuperLabelUtils.getPartitionFromDatasetHierarchy(D); 
	m_M = kMap.length;
	m_Classifiers = AbstractClassifier.makeCopies(m_Classifier,m_M);
	m_InstancesTemplates = new Instances[m_M];

	for(int i = 0; i < m_M; i++) {

		if (getDebug()) 
			System.out.println("Building model "+(i+1)+"/"+m_M+": "+Arrays.toString(kMap[i]));
		Instances D_i = SuperLabelUtils.makePartitionDataset(D,kMap[i]);
		m_Classifiers[i].buildClassifier(D_i);
		m_InstancesTemplates[i] = new Instances(D_i,0);
	}

}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:23,代码来源:HASEL.java

示例10: MultiSearch

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
/**
 * the default constructor.
 */
public MultiSearch() {
  super();

  m_Factory           = newFactory();
  m_Metrics           = m_Factory.newMetrics();
  m_Evaluation        = m_Metrics.getDefaultMetric();
  m_ClassLabel        = new SingleIndex("1");
  m_Classifier        = defaultClassifier();
  m_DefaultParameters = defaultSearchParameters();
  m_Parameters        = defaultSearchParameters();
  m_Algorithm         = defaultAlgorithm();
  m_Trace             = new ArrayList<Entry<Integer, Performance>>();

  try {
    m_BestClassifier = new SearchResult();
    m_BestClassifier.classifier = AbstractClassifier.makeCopy(m_Classifier);
  }
  catch (Exception e) {
    System.err.println("Failed to create copy of default classifier!");
    e.printStackTrace();
  }
}
 
开发者ID:fracpete,项目名称:multisearch-weka-package,代码行数:26,代码来源:MultiSearch.java

示例11: runSVMRegression

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
public static void runSVMRegression() throws Exception {
    BufferedReader br = null;
    int numFolds = 10;
    br = new BufferedReader(new FileReader("rawData.arff"));
    Instances trainData = new Instances(br);
    trainData.setClassIndex(trainData.numAttributes() - 1);
    br.close();

    WekaPackageManager.loadPackages(false, true, false);
    AbstractClassifier classifier = (AbstractClassifier) Class.forName(
            "weka.classifiers.functions.supportVector").newInstance();
    String options = ("-S 3 -V 10 -T 0");
    String[] optionsArray = options.split(" ");
    classifier.setOptions(optionsArray);
    classifier.buildClassifier(trainData);

    Evaluation evaluation = new Evaluation(trainData);
    /*******************CROSS VALIDATION*************************/
    evaluation.crossValidateModel(classifier, trainData, numFolds, new Random(1));
    /***********************************************************/

    evaluateResults(evaluation);




}
 
开发者ID:gizemsogancioglu,项目名称:biosses,代码行数:28,代码来源:svmRegressor.java

示例12: loadModelFromFile_shouldProperlyDeserializeModel

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Test
public void loadModelFromFile_shouldProperlyDeserializeModel() throws Exception
{
    AbstractClassifier baseClassifier = MethodConfiguration.buildClassifierFor(MethodConfiguration.RT);

    File file = ioHelper.saveModelToFile("dummy.model", baseClassifier);

    Classifier recoveredClassifier = ioHelper.loadModelFromFile("dummy.model");

    assertThat(file.exists(), equalTo(Boolean.TRUE));
    assertThat(file.delete(), equalTo(Boolean.TRUE));
    assertThat(recoveredClassifier, notNullValue());
    assertThat(recoveredClassifier, instanceOf(MethodConfiguration.RT.getClazz()));
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:15,代码来源:InputOutputHelperTest.java

示例13: buildClassifierFor_validMethodConfiguration_shouldReturnNotNullClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
@Test
public void buildClassifierFor_validMethodConfiguration_shouldReturnNotNullClassifier()
{
    Arrays
        .stream(MethodConfiguration.values())
        .forEach(v ->
        {
            AbstractClassifier classifier = MethodConfiguration.buildClassifierFor(v);

            assertThat(classifier, notNullValue());
            assertThat(classifier, instanceOf(v.getClazz()));
            assertThat(classifier.getOptions(), notNullValue());
        });
}
 
开发者ID:marcelovca90,项目名称:anti-spam-weka-gui,代码行数:15,代码来源:MethodConfigurationTest.java

示例14: buildClassifier

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
/**
   * Builds the committee of randomizable classifiers.
   *
   * @param data the training data to be used for generating the
   * bagged classifier.
   * @exception Exception if the classifier could not be built successfully
   */
  public void buildClassifier(Instances data) throws Exception {

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

    // get fresh instances
    m_data = new Instances(data);
    super.buildClassifier(m_data);
    
    if (!(m_Classifier instanceof Randomizable)) {
      throw new IllegalArgumentException("Base learner must implement Randomizable!");
    }

    m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, m_NumIterations);

    Random random = m_data.getRandomNumberGenerator(m_Seed);

    // Resample data based on weights if base learner can't handle weights
    if (!(m_Classifier instanceof WeightedInstancesHandler)) {
      m_data = m_data.resampleWithWeights(random);
    }

    for (int j = 0; j < m_Classifiers.length; j++) {

      // Set the random number seed for the current classifier.
      ((Randomizable) m_Classifiers[j]).setSeed(random.nextInt());
      
      // Build the classifier.
//      m_Classifiers[j].buildClassifier(m_data);
    }
    
    buildClassifiers();
    
    // save memory
    m_data = null;
  }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:44,代码来源:RandomCommittee.java

示例15: processMetaOptions

import weka.classifiers.AbstractClassifier; //导入依赖的package包/类
/**
 * Process options setting meta classifier.
 * 
 * @param options the options to parse
 * @throws Exception if the parsing fails
 */
protected void processMetaOptions(String[] options) throws Exception {

  String classifierString = Utils.getOption('M', options);
  String [] classifierSpec = Utils.splitOptions(classifierString);
  String classifierName;
  if (classifierSpec.length == 0) {
    classifierName = "weka.classifiers.rules.ZeroR";
  } else {
    classifierName = classifierSpec[0];
    classifierSpec[0] = "";
  }
  setMetaClassifier(AbstractClassifier.forName(classifierName, classifierSpec));
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:20,代码来源:Stacking.java


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