本文整理汇总了Java中edu.berkeley.nlp.classify.LabeledInstance类的典型用法代码示例。如果您正苦于以下问题:Java LabeledInstance类的具体用法?Java LabeledInstance怎么用?Java LabeledInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LabeledInstance类属于edu.berkeley.nlp.classify包,在下文中一共展示了LabeledInstance类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import edu.berkeley.nlp.classify.LabeledInstance; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
// create datums
int k = 2;
double[] dummyWeights = DoubleArrays.constantArray(1.0 / k, k);
LabeledInstance<WordInSentence, String> datum1 = new LabeledInstance<WordInSentence, String>(
"NN", new WordInSentence("The cats died", 1));
LabeledInstance<WordInSentence, String> datum2 = new LabeledInstance<WordInSentence, String>(
"VB", new WordInSentence("I killing the cat", 1));
LabeledInstance<WordInSentence, String> datum3 = new LabeledInstance<WordInSentence, String>(
"NN", new WordInSentence("A cats killed me", 1));
LabeledInstance<WordInSentence, String> datum4 = new LabeledInstance<WordInSentence, String>(
"NN", new WordInSentence("The cats lived", 1));
// create training set
List<LabeledInstance<WordInSentence, String>> trainingData = new ArrayList<LabeledInstance<WordInSentence, String>>();
trainingData.add(datum1);
trainingData.add(datum2);
trainingData.add(datum3);
// create test set
List<LabeledInstance<WordInSentence, String>> testData = new ArrayList<LabeledInstance<WordInSentence, String>>();
testData.add(datum4);
// build classifier
LexiconFeatureExtractor featureExtractor = new LexiconFeatureExtractor();
MaximumEntropyClassifier.Factory<WordInSentence, LexiconFeature, String> maximumEntropyClassifierFactory = new MaximumEntropyClassifier.Factory<WordInSentence, LexiconFeature, String>(
1.0, 20, featureExtractor);
MaximumEntropyClassifier<WordInSentence, LexiconFeature, String> maximumEntropyClassifier = (MaximumEntropyClassifier<WordInSentence, LexiconFeature, String>) maximumEntropyClassifierFactory
.trainClassifier(trainingData);
System.out.println("Probabilities on test instance: "
+ maximumEntropyClassifier.getProbabilities(datum4.getInput()));
}