本文整理汇总了Java中cc.mallet.classify.MaxEntTrainer类的典型用法代码示例。如果您正苦于以下问题:Java MaxEntTrainer类的具体用法?Java MaxEntTrainer怎么用?Java MaxEntTrainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MaxEntTrainer类属于cc.mallet.classify包,在下文中一共展示了MaxEntTrainer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initClassifier
import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public void initClassifier(Map<String, Object> parameters) throws DataMiningException {
String classifierName = "MaxEntL1";
// String classifierName = "C45";
Double gaussianPrior = null;
if (parameters != null && parameters.containsKey("classifier")) {
classifierName = (String) parameters.get("classifier");
}
if (classifierName.equals("MaxEntL1") && parameters != null && parameters.containsKey("classifier")) {
gaussianPrior = (Double) parameters.get("gaussianPrior");
}
try {
trainer = (ClassifierTrainer<?>) Class.forName("cc.mallet.classify." + classifierName + "Trainer").newInstance();
if (classifierName.equals("MaxEntL1")) {
if (gaussianPrior != null) {
((MaxEntTrainer) trainer).setGaussianPriorVariance(gaussianPrior);
}
}
// ((MaxEntTrainer)trainer).setGaussianPriorVariance(1.0);
/*
* ((C45Trainer)trainer).setMinNumInsts(3); ((C45Trainer)trainer).setDepthLimited(true); ((C45Trainer)trainer).setMaxDepth(2);
* ((C45Trainer)trainer).setDoPruning(true);
*/
} catch (Exception e) {
throw new DataMiningException("unknown classifier: " + classifierName, e);
}
}
示例2: createTrainer
import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public ClassifierTrainer<MaxEnt> createTrainer(String... args) {
MaxEntTrainer trainer = new MaxEntTrainer();
if (args != null) {
if (args.length % 2 != 0) {
throw new IllegalArgumentException("each argument must be supplied with a value: "
+ getUsageMessage());
}
for (int i = 0; i < args.length; i += 2) {
String optionName = args[i];
String optionValue = args[i + 1];
if (optionName.equals("--numIterations")) {
int numIterations = Integer.parseInt(optionValue);
if (numIterations > 0)
trainer.setNumIterations(numIterations);
else
throw new IllegalArgumentException("numIterations must be positive. "
+ getUsageMessage());
}
else if (optionName.equals("--gaussianPriorVariance"))
trainer.setGaussianPriorVariance(Double.parseDouble(optionValue));
else
throw new IllegalArgumentException(String.format(
"the argument %1$s is invalid. ",
optionName) + getUsageMessage());
}
}
return trainer;
}
示例3: testRandomTrainedOn
import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
private double testRandomTrainedOn (InstanceList training)
{
ClassifierTrainer trainer = new MaxEntTrainer();
Alphabet fd = dictOfSize (3);
String[] classNames = new String[] {"class0", "class1", "class2"};
Randoms r = new Randoms (1);
Iterator<Instance> iter = new RandomTokenSequenceIterator (r, new Dirichlet(fd, 2.0),
30, 0, 10, 200, classNames);
training.addThruPipe (iter);
InstanceList testing = new InstanceList (training.getPipe ());
testing.addThruPipe (new RandomTokenSequenceIterator (r, new Dirichlet(fd, 2.0),
30, 0, 10, 200, classNames));
System.out.println ("Training set size = "+training.size());
System.out.println ("Testing set size = "+testing.size());
Classifier classifier = trainer.train (training);
System.out.println ("Accuracy on training set:");
System.out.println (classifier.getClass().getName()
+ ": " + new Trial(classifier, training).getAccuracy());
System.out.println ("Accuracy on testing set:");
double testAcc = new Trial (classifier, testing).getAccuracy();
System.out.println (classifier.getClass().getName()
+ ": " + testAcc);
return testAcc;
}
示例4: testTrainSplit
import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public static Trial testTrainSplit(InstanceList instances) {
InstanceList[] instanceLists = instances.split(new Randoms(),
new double[] { 0.9, 0.1, 0.0 });
// LOG.debug("{} training instance, {} testing instances",
// instanceLists[0].size(), instanceLists[1].size());
@SuppressWarnings("rawtypes")
ClassifierTrainer trainer = new MaxEntTrainer();
Classifier classifier = trainer.train(instanceLists[TRAINING]);
return new Trial(classifier, instanceLists[TESTING]);
}
示例5: run
import cc.mallet.classify.MaxEntTrainer; //导入依赖的package包/类
public void run () {
Alphabet alphabet = dictOfSize(20);
// TRAIN
Clustering training = sampleClustering(alphabet);
Pipe clusterPipe = new OverlappingFeaturePipe();
System.err.println("Training with " + training);
InstanceList trainList = new InstanceList(clusterPipe);
trainList.addThruPipe(new ClusterSampleIterator(training, random, 0.5, 100));
System.err.println("Created " + trainList.size() + " instances.");
Classifier me = new MaxEntTrainer().train(trainList);
ClassifyingNeighborEvaluator eval =
new ClassifyingNeighborEvaluator(me, "YES");
Trial trial = new Trial(me, trainList);
System.err.println(new ConfusionMatrix(trial));
InfoGain ig = new InfoGain(trainList);
ig.print();
// Clusterer clusterer = new GreedyAgglomerative(training.getInstances().getPipe(),
// eval, 0.5);
Clusterer clusterer = new GreedyAgglomerativeByDensity(training.getInstances().getPipe(),
eval, 0.5, false,
new java.util.Random(1));
// TEST
Clustering testing = sampleClustering(alphabet);
InstanceList testList = testing.getInstances();
Clustering predictedClusters = clusterer.cluster(testList);
// EVALUATE
System.err.println("\n\nEvaluating System: " + clusterer);
ClusteringEvaluators evaluators = new ClusteringEvaluators(new ClusteringEvaluator[]{
new BCubedEvaluator(),
new PairF1Evaluator(),
new MUCEvaluator(),
new AccuracyEvaluator()});
System.err.println("truth:" + testing);
System.err.println("pred: " + predictedClusters);
System.err.println(evaluators.evaluate(testing, predictedClusters));
}