本文整理汇总了Java中cc.mallet.classify.Classifier.getInstancePipe方法的典型用法代码示例。如果您正苦于以下问题:Java Classifier.getInstancePipe方法的具体用法?Java Classifier.getInstancePipe怎么用?Java Classifier.getInstancePipe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.classify.Classifier
的用法示例。
在下文中一共展示了Classifier.getInstancePipe方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConfidencePredictingClassifier
import cc.mallet.classify.Classifier; //导入方法依赖的package包/类
public ConfidencePredictingClassifier (Classifier underlyingClassifier, Classifier confidencePredictingClassifier)
{
super (underlyingClassifier.getInstancePipe());
this.underlyingClassifier = underlyingClassifier;
this.confidencePredictingClassifier = confidencePredictingClassifier;
// for testing confidence accuracy
totalCorrect = 0.0;
totalIncorrect = 0.0;
totalIncorrectIncorrect = 0.0;
totalIncorrectCorrect = 0.0;
numCorrectInstances = 0;
numIncorrectInstances = 0;
numConfidenceCorrect = 0;
numFalsePositive = 0;
numFalseNegative = 0;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:ConfidencePredictingClassifier.java
示例2: initialize
import cc.mallet.classify.Classifier; //导入方法依赖的package包/类
@Override
public void initialize(UimaContext context)
throws ResourceInitializationException {
super.initialize(context);
try {
// load model for inference
File modelfile = new File(ReferencesHelper.REFERENCES_RESOURCES
+ "models/" + modelName);
checkArgument(modelfile.exists(), "no modelFile at " + modelName);
ObjectInputStream s = new ObjectInputStream(new FileInputStream(
modelfile));
classifier = (Classifier) s.readObject();
s.close();
checkArgument(classifier != null);
pipes = classifier.getInstancePipe();
} catch (Exception e) {
throw new ResourceInitializationException(e);
}
}
示例3: main
import cc.mallet.classify.Classifier; //导入方法依赖的package包/类
public static void main(String[] args){
String stopListFilePath = "data/stoplists/en.txt";
String dataFolderPath = "data/ex6DataEmails/train";
String testFolderPath = "data/ex6DataEmails/test";
ArrayList<Pipe> pipeList = new ArrayList<Pipe>();
pipeList.add(new Input2CharSequence("UTF-8"));
Pattern tokenPattern = Pattern.compile("[\\p{L}\\p{N}_]+");
pipeList.add(new CharSequence2TokenSequence(tokenPattern));
pipeList.add(new TokenSequenceLowercase());
pipeList.add(new TokenSequenceRemoveStopwords(new File(stopListFilePath), "utf-8", false, false, false));
pipeList.add(new TokenSequence2FeatureSequence());
pipeList.add(new FeatureSequence2FeatureVector());
pipeList.add(new Target2Label());
SerialPipes pipeline = new SerialPipes(pipeList);
FileIterator folderIterator = new FileIterator(
new File[] {new File(dataFolderPath)},
new TxtFilter(),
FileIterator.LAST_DIRECTORY);
InstanceList instances = new InstanceList(pipeline);
instances.addThruPipe(folderIterator);
ClassifierTrainer classifierTrainer = new NaiveBayesTrainer();
Classifier classifier = classifierTrainer.train(instances);
InstanceList testInstances = new InstanceList(classifier.getInstancePipe());
folderIterator = new FileIterator(
new File[] {new File(testFolderPath)},
new TxtFilter(),
FileIterator.LAST_DIRECTORY);
testInstances.addThruPipe(folderIterator);
Trial trial = new Trial(classifier, testInstances);
System.out.println("Accuracy: " + trial.getAccuracy());
System.out.println("F1 for class 'spam': " + trial.getF1("spam"));
System.out.println("Precision for class '" +
classifier.getLabelAlphabet().lookupLabel(1) + "': " +
trial.getPrecision(1));
System.out.println("Recall for class '" +
classifier.getLabelAlphabet().lookupLabel(1) + "': " +
trial.getRecall(1));
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:55,代码来源:SpamDetector.java
示例4: evaluate
import cc.mallet.classify.Classifier; //导入方法依赖的package包/类
public void evaluate(Classifier classifier, File file) throws IOException {
// Create an InstanceList that will contain the test data.
// In order to ensure compatibility, process instances
// with the pipe used to process the original training
// instances.
InstanceList testInstances = new InstanceList(classifier.getInstancePipe());
// Create a new iterator that will read raw instance data from
// the lines of a file.
// Lines should be formatted as:
//
// [name] [label] [data ... ]
CsvIterator reader =
new CsvIterator(new FileReader(file),
"(\\w+)\\s+(\\w+)\\s+(.*)",
3, 2, 1); // (data, label, name) field indices
// Add all instances loaded by the iterator to
// our instance list, passing the raw input data
// through the classifier's original input pipe.
testInstances.addThruPipe(reader);
Trial trial = new Trial(classifier, testInstances);
// The Trial class implements many standard evaluation
// metrics. See the JavaDoc API for more details.
System.out.println("Accuracy: " + trial.getAccuracy());
// precision, recall, and F1 are calcuated for a specific
// class, which can be identified by an object (usually
// a String) or the integer ID of the class
System.out.println("F1 for class 'good': " + trial.getF1("good"));
System.out.println("Precision for class '" +
classifier.getLabelAlphabet().lookupLabel(1) + "': " +
trial.getPrecision(1));
}