本文整理匯總了Java中weka.classifiers.Classifier.buildClassifier方法的典型用法代碼示例。如果您正苦於以下問題:Java Classifier.buildClassifier方法的具體用法?Java Classifier.buildClassifier怎麽用?Java Classifier.buildClassifier使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.classifiers.Classifier
的用法示例。
在下文中一共展示了Classifier.buildClassifier方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: train
import weka.classifiers.Classifier; //導入方法依賴的package包/類
private void train(String name) {
try {
Classifier randomForest = new RandomForest();
ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + name);
dataSet = source.getDataSet();
dataSet.setClassIndex(dataSet.numAttributes() - 1);
randomForest.buildClassifier(dataSet);
classifier = randomForest;
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: train
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void train() {
try {
Classifier randomForest = new RandomForest();
ConverterUtils.DataSource source = new ConverterUtils.DataSource(FOLDER + "question-classifier.arff");
dataSet = source.getDataSet();
dataSet.setClassIndex(dataSet.numAttributes() - 1);
randomForest.buildClassifier(dataSet);
classifier = randomForest;
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: evaluate
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public static void evaluate(Classifier clf, Instances data, double minPerfomance)
throws Exception {
Instances[] split = TestUtil.splitTrainTest(data);
Instances train = split[0];
Instances test = split[1];
clf.buildClassifier(train);
Evaluation trainEval = new Evaluation(train);
trainEval.evaluateModel(clf, train);
Evaluation testEval = new Evaluation(train);
testEval.evaluateModel(clf, test);
final double testPctCorrect = testEval.pctCorrect();
final double trainPctCorrect = trainEval.pctCorrect();
log.info("Train: {}, Test: {}", trainPctCorrect, testPctCorrect);
boolean success =
testPctCorrect > minPerfomance && trainPctCorrect > minPerfomance;
Assert.assertTrue(success);
}
示例4: holdout
import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
* Perform simple holdout with a given percentage
*
* @param clf Classifier
* @param data Full dataset
* @param p Split percentage
* @throws Exception
*/
public static void holdout(Classifier clf, Instances data, double p) throws Exception {
Instances[] split = splitTrainTest(data, p);
Instances train = split[0];
Instances test = split[1];
clf.buildClassifier(train);
Evaluation trainEval = new Evaluation(train);
trainEval.evaluateModel(clf, train);
logger.info("Weka Train Evaluation:");
logger.info(trainEval.toSummaryString());
if (!data.classAttribute().isNumeric()) {
logger.info(trainEval.toMatrixString());
}
Evaluation testEval = new Evaluation(train);
logger.info("Weka Test Evaluation:");
testEval.evaluateModel(clf, test);
logger.info(testEval.toSummaryString());
if (!data.classAttribute().isNumeric()) {
logger.info(testEval.toMatrixString());
}
}
示例5: train
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void train(String datasetFilename, boolean serialise)
{
String[] lines = Utils.readLines(datasetFilename);
int i = 1; // skip legend
try
{
for(i = 1; i < lines.length; i++) // skip legend
{
dataset.add(createFeatureVector(lines[i].split(","), true));
}
model = (Classifier) new LinearRegression();
((LinearRegression)model).setRidge(1.0e-10);
model.buildClassifier(dataset);
if(serialise)
{
SerializationHelper.write(new FileOutputStream(modelFilename), model);
}
}
catch(Exception e)
{
System.err.println("Error in line " + i + ": " + lines[i]);
e.printStackTrace();
}
}
示例6: training
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public void training(double[][] trainFeatures) throws Exception {
/**
* Need to be replaced
*/
//How to preprocess trainFeatures into inst
BufferedReader reader = new BufferedReader(
new FileReader("/Users/karl/Work/database/forsimpletest/1.arff"));
Instances inst = new Instances(reader);
reader.close();
inst.setClassIndex(inst.numAttributes() - 1);
//Init classifier
Classifier cls = new J48();
cls.buildClassifier(inst);
// serialize model
weka.core.SerializationHelper.write(modelFile, cls);
}
示例7: getJ48Model
import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
* Weka implementation of C4.5
*/
public Classifier getJ48Model() throws Exception {
Classifier model = new J48();
model.buildClassifier(instances);
return model;
}
示例8: getSMO
import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
* Weka implementation of SVM
*/
public Classifier getSMO() throws Exception {
Classifier model = new SMO();
((PolyKernel) ((SMO) model).getKernel()).setExponent(2);
model.buildClassifier(instances);
return model;
}
示例9: getIBk
import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
* Weka implementation of kNN
*/
public Classifier getIBk() throws Exception {
Classifier model = new IBk();
model.buildClassifier(instances);
return model;
}
示例10: getNaiveBayes
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public Classifier getNaiveBayes() throws Exception {
Classifier model = new NaiveBayes();
model.buildClassifier(instances);
return model;
}
示例11: trainClassifier
import weka.classifiers.Classifier; //導入方法依賴的package包/類
@TimeThis(task="train", category=TimerCategory.EXTERNAL)
protected void trainClassifier(ProcessingContext<Corpus> ctx, Classifier classifier, IdentifiedInstances<Element> trainingSet) throws Exception {
getLogger(ctx).info("training classifier");
classifier.buildClassifier(trainingSet);
}
示例12: manyEvaluations
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public String manyEvaluations(Instances dataSet,Classifier classifier) throws Exception {
String saida="";
Instances iTeste;
Instances iTreinamento;
Instances instances = dataSet.resample(new Random(1));
for(int i=2;i<20;i++){
for (int j=1;j<i;j++){
iTeste = instances.testCV(i, j);
iTreinamento = instances.trainCV(i, j);
classifier.buildClassifier(iTreinamento);
super.evaluateModel(classifier,iTeste);
saida+="\nTeste: "+iTeste.numInstances()+" , Treinamento: "+iTreinamento.numInstances();
saida+="\nTaxa de Erro: "+ super.errorRate()+"\n";
}
}
return saida;
}
示例13: main
import weka.classifiers.Classifier; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("model/comments.arff"));
Instances data = new Instances(reader);
data.setClassIndex(data.numAttributes() - 1);
reader.close();
// Classifier classifier = new J48();
Classifier classifier = new NaiveBayesMultinomialText();
classifier.buildClassifier(data);
String testMessage = "Spencer, my tone? You sir are political correctness gone mad!";
double[] ret = classifyMessage(classifier, data, testMessage);
System.out.println(ret[0]+ ":" + ret[1]);
// Classifier jbClassifier = new J48();
// // Filter instance.
// StringToWordVector m_Filter = new StringToWordVector();
// m_Filter.setInputFormat(data);
//
// // Generate word counts from the training data.
// Instances filteredData = Filter.useFilter(data, m_Filter);
//
// // Rebuild classifier.
// jbClassifier.buildClassifier(filteredData);
// ret = classifyMessage(jbClassifier,m_Filter, data, testMessage);
// System.out.println(ret[0]+ ":" + ret[1]);
}
示例14: getTrainTestPredictions
import weka.classifiers.Classifier; //導入方法依賴的package包/類
/**
* Generate a bunch of predictions ready for processing, by performing a
* evaluation on a test set after training on the given training set.
*
* @param classifier the Classifier to evaluate
* @param train the training dataset
* @param test the test dataset
* @exception Exception if an error occurs
*/
public ArrayList<Prediction> getTrainTestPredictions(Classifier classifier,
Instances train, Instances test) throws Exception {
classifier.buildClassifier(train);
return getTestPredictions(classifier, test);
}