本文整理匯總了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()));
}