本文整理汇总了Java中weka.core.Instance.setDataset方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.setDataset方法的具体用法?Java Instance.setDataset怎么用?Java Instance.setDataset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instance
的用法示例。
在下文中一共展示了Instance.setDataset方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Main
import weka.core.Instance; //导入方法依赖的package包/类
public Main() {
try {
BufferedReader datafile;
datafile = readDataFile("camping.txt");
Instances data = new Instances(datafile);
data.setClassIndex(data.numAttributes() - 1);
Instances trainingData = new Instances(data, 0, 14);
Instances testingData = new Instances(data, 14, 5);
Evaluation evaluation = new Evaluation(trainingData);
SMO smo = new SMO();
smo.buildClassifier(data);
evaluation.evaluateModel(smo, testingData);
System.out.println(evaluation.toSummaryString());
// Test instance
Instance instance = new DenseInstance(3);
instance.setValue(data.attribute("age"), 78);
instance.setValue(data.attribute("income"), 125700);
instance.setValue(data.attribute("camps"), 1);
instance.setDataset(data);
System.out.println("The instance: " + instance);
System.out.println(smo.classifyInstance(instance));
} catch (Exception ex) {
ex.printStackTrace();
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:30,代码来源:Main-SVG.java
示例2: classifySentence
import weka.core.Instance; //导入方法依赖的package包/类
public SentenceType classifySentence(Sentence sentence) {
SpeechActsClassifier.Features features = speechActsClassifier.classifyFeatures(sentence);
Instance inst = new DenseInstance(6);
inst.setDataset(dataSet);
inst.setValue(0, features.getSentenceLength());
inst.setValue(1, features.getNumberOfNouns());
inst.setValue(2, (features.isEndingInNounOrAdjective() ? 1 : 0));
inst.setValue(3, (features.isBeginningInVerb() ? 1 : 0));
inst.setValue(4, features.getCountOfWhMarkers());
inst.setValue(5, Utils.missingValue());
try {
return SentenceType.valueOf(classifier.classifyInstance(inst));
} catch (Exception e) {
throw new RuntimeException("Can't classify");
}
}
示例3: classifyQuestion
import weka.core.Instance; //导入方法依赖的package包/类
public QuestionType classifyQuestion(Sentence sentence) {
if (!sentence.isQuestion()) {
return QuestionType.NA;
}
QuestionTypeClassifier.Features features = questionTypeClassifier.classifyFeatures(sentence);
Instance inst = new DenseInstance(5);
inst.setDataset(dataSet);
inst.setValue(0, features.getWhWord());
inst.setValue(1, features.getWhWordPos());
inst.setValue(2, features.getPosOfNext());
inst.setValue(3, features.getRootPos());
inst.setValue(4, Utils.missingValue());
try {
int ndx = (int) classifier.classifyInstance(inst);
return QuestionType.valueOf(ndx);
} catch (Exception e) {
throw new RuntimeException("Not classified");
}
}
示例4: getInstanceObject
import weka.core.Instance; //导入方法依赖的package包/类
public static Instance getInstanceObject (String[] instanceText,
String[] globalFeatureVector, String docID, String classValue, Instances ds) throws Exception {
FeatureVector instanceFeatureVector = getInstanceFeatureVector(instanceText,
globalFeatureVector, docID);
Instance instance = new Instance(globalFeatureVector.length + 2);
instance.setDataset(ds);
instance.setValue(0, docID);
for(int i = 0; i < globalFeatureVector.length; i++) {
double value = 0;
if(instanceFeatureVector.m_FeatureVector[0].containsKey(i)) {
value = instanceFeatureVector.m_FeatureVector[0].get(i);
}
instance.setValue(i + 1, value);
}
instance.setValue(globalFeatureVector.length + 1, classValue);
return new SparseInstance(instance);
}
示例5: getTestInstance
import weka.core.Instance; //导入方法依赖的package包/类
private Instance getTestInstance(
String binding, String multicolor, String genre) {
Instance instance = new DenseInstance(3);
instance.setDataset(trainingData);
instance.setValue(trainingData.attribute(0), binding);
instance.setValue(trainingData.attribute(1), multicolor);
instance.setValue(trainingData.attribute(2), genre);
return instance;
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:10,代码来源:BookDecisionTree.java
示例6: reloadSeries
import weka.core.Instance; //导入方法依赖的package包/类
private void reloadSeries(Number xValue, Number yValue) {
try {
Instance instance = new DenseInstance(NUMBER_OF_CLASSES);
instance.setDataset(data);
instance.setValue(0, xValue.doubleValue());
instance.setValue(1, yValue.doubleValue());
double predictedClass = tree.classifyInstance(instance);
instance.setValue(2, predictedClass);
data.add(instance);
reloadSeries();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: addExample
import weka.core.Instance; //导入方法依赖的package包/类
Instance addExample(IdentifiedInstances<Element> instances, EvaluationContext ctx, Element example, boolean train, boolean withId) {
double[] values = evaluateExample(ctx, example, train);
Instance inst = new Instance(1, values);
if (withId)
instances.add(example, inst);
else
instances.add(inst);
inst.setDataset(instances);
return inst;
}