本文整理汇总了Java中cc.mallet.classify.Classifier类的典型用法代码示例。如果您正苦于以下问题:Java Classifier类的具体用法?Java Classifier怎么用?Java Classifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Classifier类属于cc.mallet.classify包,在下文中一共展示了Classifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: main
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public static void main(String[] args) throws IOException, Exception {
ArrayList<Pipe> pipes = new ArrayList<Pipe>();
pipes.add(new Target2Label());
pipes.add(new CharSequence2TokenSequence());
pipes.add(new TokenSequence2FeatureSequence());
pipes.add(new FeatureSequence2FeatureVector());
SerialPipes pipe = new SerialPipes(pipes);
//prepare training instances
InstanceList trainingInstanceList = new InstanceList(pipe);
trainingInstanceList.addThruPipe(new CsvIterator(new FileReader("webkb-train-stemmed.txt"),
"(.*)\t(.*)", 2, 1, -1));
//prepare test instances
InstanceList testingInstanceList = new InstanceList(pipe);
testingInstanceList.addThruPipe(new CsvIterator(new FileReader("webkb-test-stemmed.txt"),
"(.*)\t(.*)", 2, 1, -1));
ClassifierTrainer trainer = new SVMClassifierTrainer(new LinearKernel());
Classifier classifier = trainer.train(trainingInstanceList);
System.out.println("Accuracy: " + classifier.getAccuracy(testingInstanceList));
}
示例3: 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);
}
}
示例4: applyModel
import cc.mallet.classify.Classifier; //导入依赖的package包/类
@Override
public List<ModelApplication> applyModel(
AnnotationSet instanceAS, AnnotationSet inputAS, AnnotationSet sequenceAS, String parms) {
// NOTE: the crm should be of type CorpusRepresentationMalletClass for this to work!
if(!(corpusRepresentation instanceof CorpusRepresentationMalletTarget)) {
throw new GateRuntimeException("Cannot perform classification with data from "+corpusRepresentation.getClass());
}
CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
data.stopGrowth();
List<ModelApplication> gcs = new ArrayList<ModelApplication>();
LFPipe pipe = (LFPipe)data.getRepresentationMallet().getPipe();
Classifier classifier = (Classifier)model;
// iterate over the instance annotations and create mallet instances
for(Annotation instAnn : instanceAS.inDocumentOrder()) {
Instance inst = data.extractIndependentFeatures(instAnn, inputAS);
inst = pipe.instanceFrom(inst);
Classification classification = classifier.classify(inst);
Labeling labeling = classification.getLabeling();
LabelVector labelvec = labeling.toLabelVector();
List<String> classes = new ArrayList<String>(labelvec.numLocations());
List<Double> confidences = new ArrayList<Double>(labelvec.numLocations());
for(int i=0; i<labelvec.numLocations(); i++) {
classes.add(labelvec.getLabelAtRank(i).toString());
confidences.add(labelvec.getValueAtRank(i));
}
ModelApplication gc = new ModelApplication(instAnn, labeling.getBestLabel().toString(),
labeling.getBestValue(), classes, confidences);
//System.err.println("ADDING GC "+gc);
// now save the class in our special class feature on the instance as well
instAnn.getFeatures().put("gate.LF.target",labeling.getBestLabel().toString());
gcs.add(gc);
}
data.startGrowth();
return gcs;
}
示例5: doTraining
import cc.mallet.classify.Classifier; //导入依赖的package包/类
private void doTraining(InstanceList trainList)
{
// train a classifier on the entire training set
logger.info("Training token classifier on entire data set (size=" + trainList.size() + ")...");
m_tokenClassifier = m_trainer.train(trainList);
Trial t = new Trial(m_tokenClassifier, trainList);
logger.info("Training set accuracy = " + t.getAccuracy());
if (m_numCV == 0)
return;
// train classifiers using cross validation
InstanceList.CrossValidationIterator cvIter = trainList.new CrossValidationIterator(m_numCV, m_randSeed);
int f = 1;
while (cvIter.hasNext()) {
f++;
InstanceList[] fold = cvIter.nextSplit();
logger.info("Training token classifier on cv fold " + f + " / " + m_numCV + " (size=" + fold[0].size() + ")...");
Classifier foldClassifier = m_trainer.train(fold[0]);
Trial t1 = new Trial(foldClassifier, fold[0]);
Trial t2 = new Trial(foldClassifier, fold[1]);
logger.info("Within-fold accuracy = " + t1.getAccuracy());
logger.info("Out-of-fold accuracy = " + t2.getAccuracy());
/*for (int x = 0; x < t2.size(); x++) {
logger.info("xxx pred:" + t2.getClassification(x).getLabeling().getBestLabel() + " true:" + t2.getClassification(x).getInstance().getLabeling());
}*/
for (int i = 0; i < fold[1].size(); i++) {
Instance inst = fold[1].get(i);
m_table.put(inst.getName(), foldClassifier);
}
}
}
示例6: classify
import cc.mallet.classify.Classifier; //导入依赖的package包/类
/**
*
* @param instance the instance to classify
* @param useOutOfFold whether to check the instance name and use the out-of-fold classifier
* if the instance name matches one in the training data
* @return the token classifier's output
*/
public Classification classify(Instance instance, boolean useOutOfFold)
{
Object instName = instance.getName();
if (! useOutOfFold || ! m_table.containsKey(instName))
return m_tokenClassifier.classify(instance);
Classifier classifier = (Classifier) m_table.get(instName);
return classifier.classify(instance);
}
示例7: readObject
import cc.mallet.classify.Classifier; //导入依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
int version = in.readInt();
if (version != CURRENT_SERIAL_VERSION)
throw new ClassNotFoundException("Mismatched TokenClassifiers versions: wanted " +
CURRENT_SERIAL_VERSION + ", got " +
version);
instancePipe = (Pipe) in.readObject();
m_numCV = in.readInt();
m_randSeed = in.readInt();
m_table = (HashMap) in.readObject();
m_tokenClassifier = (Classifier) in.readObject();
m_trainer = (ClassifierTrainer) in.readObject();
}
示例8: train
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public Classifier train (InstanceList trainingSet)
{
featureSelector.selectFeaturesFor (trainingSet);
// TODO What about also selecting features for the validation set?
this.classifier = underlyingTrainer.train (trainingSet);
return classifier;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:FeatureSelectingClassifierTrainer.java
示例9: Classification
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public Classification (Instance instance, Classifier classifier,
Labeling labeling)
{
this.instance = instance;
this.classifier = classifier;
this.labeling = labeling;
}
示例10: newClassifierTrainer
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public DecisionTreeTrainer newClassifierTrainer (Classifier initialClassifier) {
DecisionTreeTrainer t = new DecisionTreeTrainer ();
t.maxDepth = this.maxDepth;
t.minInfoGainSplit = this.minInfoGainSplit;
return t;
}
示例11: MedoidEvaluator
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public MedoidEvaluator(Classifier classifier, String scoringLabel,boolean singleLink,boolean mergeFirst)
{
super(classifier,scoringLabel);
this.singleLink=singleLink;
this.mergeFirst=mergeFirst;
System.out.println("Using Medoid Evaluator. Single link="+singleLink+".");
}
示例12: unpackageClassifier
import cc.mallet.classify.Classifier; //导入依赖的package包/类
@Override
protected void unpackageClassifier(JarInputStream modelStream) throws IOException {
super.unpackageClassifier(modelStream);
JarStreams.getNextJarEntry(modelStream, MODEL_NAME);
ObjectInputStream objectStream = new ObjectInputStream(modelStream);
try {
this.classifier = (Classifier) objectStream.readObject();
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
}
示例13: MalletClassifier_ImplBase
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public MalletClassifier_ImplBase(
FeaturesEncoder<List<NameNumber>> featuresEncoder,
OutcomeEncoder<OUTCOME_TYPE, String> outcomeEncoder,
Classifier classifier) {
super(featuresEncoder, outcomeEncoder);
this.classifier = classifier;
this.alphabet = classifier.getAlphabet();
}
示例14: train
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public Classifier train (InstanceList trainingSet)
{
featureSelector.selectFeaturesFor (trainingSet);
// TODO What about also selecting features for the validation set?
this.classifier = underlyingTrainer.train (trainingSet);
return classifier;
}
示例15: saveClassifier
import cc.mallet.classify.Classifier; //导入依赖的package包/类
public void saveClassifier(Classifier classifier, File serializedFile)
throws IOException {
ObjectOutputStream oos =
new ObjectOutputStream(new FileOutputStream(serializedFile));
oos.writeObject(classifier);
oos.close();
}