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


Java SMO.buildClassifier方法代码示例

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


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

示例1: Main

import weka.classifiers.functions.SMO; //导入方法依赖的package包/类
public Main() {
    try {
        BufferedReader datafile;
        datafile = readDataFile("camping.txt");
        Instances data = new Instances(datafile);
        data.setClassIndex(data.numAttributes() - 1);

        Instances trainingData = new Instances(data, 0, 14);
        Instances testingData = new Instances(data, 14, 5);
        Evaluation evaluation = new Evaluation(trainingData);

        SMO smo = new SMO();
        smo.buildClassifier(data);

        evaluation.evaluateModel(smo, testingData);
        System.out.println(evaluation.toSummaryString());

        // Test instance 
        Instance instance = new DenseInstance(3);
        instance.setValue(data.attribute("age"), 78);
        instance.setValue(data.attribute("income"), 125700);
        instance.setValue(data.attribute("camps"), 1);            
        instance.setDataset(data);
        System.out.println("The instance: " + instance);
        System.out.println(smo.classifyInstance(instance));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:30,代码来源:Main-SVG.java

示例2: trainClassifier

import weka.classifiers.functions.SMO; //导入方法依赖的package包/类
/**
 * Train the classifier with the given dataset
 * @param trainingData The dataset to be given for classification
 * @throws ClassifierException If classification fails for some reason
 */
public void trainClassifier(Instances trainingData,String pathToSaveModel,
                            boolean crossValidate) throws ClassifierException {
    log.info("Training the classifier with "+trainingData.numInstances()+" instances");
    SMO smoClassifier = new SMO();
    trainingData.setClass(trainingData.attribute("@@[email protected]@"));
    try {
        String[] options = Utils.splitOptions("-C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K \"weka.classifiers" +
                ".functions.supportVector.PolyKernel -C 250007 -E 1.0\"");
        smoClassifier.setOptions(options);
        smoClassifier.buildClassifier(trainingData);
        classifier = smoClassifier;
        if(crossValidate){
            crossValidate(trainingData);
        }
        saveModel(new File(pathToSaveModel,"latest.model").getAbsolutePath());
        log.info("Model built and saved");
    } catch (Exception e) {
        log.error("Training classifier failed.",e);
        throw new ClassifierException("Classification failed.",e);
    }
}
 
开发者ID:sasinda,项目名称:OntologyBasedInormationExtractor,代码行数:27,代码来源:ProductClassifier.java

示例3: classifySMO

import weka.classifiers.functions.SMO; //导入方法依赖的package包/类
public SMO classifySMO(Instances data) throws Exception {
    SMO smo = new SMO();
    smo.buildClassifier(data);
    return smo;
}
 
开发者ID:andrzejtrzaska,项目名称:VoiceStressAnalysis,代码行数:6,代码来源:Classification.java

示例4: computeWeights

import weka.classifiers.functions.SMO; //导入方法依赖的package包/类
String computeWeights(String path) throws Exception {
	weightList = new ArrayList<Double>();
	defaultWeight = 100 / noofAttributes;

	BufferedReader br = null;
	StringReader sr = new StringReader(path); // wrap your String
	br = new BufferedReader(sr);

	// br = new BufferedReader(new FileReader(path));
	Instances data = new Instances(br);

	if (data.classIndex() == -1)
		data.setClassIndex(data.numAttributes() - 1);

	// Initialize the SMO classifier
	SMO smo = new SMO();
	smo.buildClassifier(data);
	Evaluation eval = new Evaluation(data);
	// Get the weights in sparse representation
	double[][][] sparseWeights = smo.sparseWeights();
	int[][][] sparseIndices = smo.sparseIndices();

	// Transform the weights into non-sparse representation
	double[] weights = new double[10];
	for (int i = 0; i < sparseIndices[0][1].length; i++) {
		weights[sparseIndices[0][1][i]] = sparseWeights[0][1][i];
	}

	// Output the weights
	for (int i = 0; i < data.numAttributes(); i++) {

		// Skip the class
		if (i != data.classIndex()) {
			weightList.add((Double) weights[i]);
			svm_weights.put(String.valueOf(weights[i]), (String) data
					.attribute(i).name());
		}
	}
	getOldWeights();
	return scaleWeights();
}
 
开发者ID:usc-isi-i2,项目名称:record-linkage-learning,代码行数:42,代码来源:ComputeSVMWeights.java


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