本文整理匯總了Java中weka.core.Instances.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java Instances.iterator方法的具體用法?Java Instances.iterator怎麽用?Java Instances.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.core.Instances
的用法示例。
在下文中一共展示了Instances.iterator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: calculateSupport
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Calculate support value of a given rule on the dataset
*
* @param dataset the dataset
* @param bodySide left-side or BODY part of the rule
* @return support value for the rule on the given dataset
*/
public double calculateSupport(Instances dataset, List<Term> bodySide){
Iterator<Instance> datasetIterator = dataset.iterator();
int supportCount = 0;
while(datasetIterator.hasNext()){
Instance anInstance = datasetIterator.next();
if(instanceCoveredByTermsList(anInstance,bodySide)){
supportCount++;
}
}
return !dataset.isEmpty() ? (double) supportCount / (double) dataset.size() : 0.0d;
}
示例2: calcualteConfidence
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Calculate confidence value of a given rule on the dataset
*
* @param dataset the dataset
* @param bodySide left-side or BODY part of the rule
* @param HeadSide right-side or HEAD part of the rule
* @return confidence value for the rule on the given dataset
*/
public double calcualteConfidence(Instances dataset, List<Term> bodySide, List<Term> HeadSide){
Iterator<Instance> datasetIterator = dataset.iterator();
int confidenceCount = 0;
int supportCount = 0;
while(datasetIterator.hasNext()){
Instance anInstance = datasetIterator.next();
if(instanceCoveredByTermsList(anInstance,bodySide)){
supportCount++;
if(instanceCoveredByTermsList(anInstance,HeadSide)){
confidenceCount++;
}
}
}
return !dataset.isEmpty() ? (double) confidenceCount / (double) supportCount : 0.0d;
}
示例3: allInstancesCoveredByTermsBothSides
import weka.core.Instances; //導入方法依賴的package包/類
/**
* check if all instances from a given dataset is covered/ satisfied by both BODY and HEAD
*
* @param dataset instances to be checked
* @param leftHandSide these rule term(s) represent the BODY
* @param rightHandside these rule term(s) represent the HEAD
* @return true if all instances covered by the rule, false otherwise
*/
public boolean allInstancesCoveredByTermsBothSides(Instances dataset, List<Term> leftHandSide, List<Term> rightHandside){
if(rightHandside.isEmpty() || leftHandSide.isEmpty()){
return false;
}
Iterator<Instance> datasetIterator = dataset.iterator();
while(datasetIterator.hasNext()){
Instance anInstance = datasetIterator.next();
// 1st check if the instance is totally covered by the right hand-side
for (int termI = 0; termI < rightHandside.size(); termI++) {
if(rightHandside.get(termI).coveredInstance(anInstance) == false){
return false;
}
}
// 2nd check if the instance is totally covered by the right hand-side
for (int termI = 0; termI < leftHandSide.size(); termI++) {
if(leftHandSide.get(termI).coveredInstance(anInstance) == false){
return false;
}
}
}
return true;
}
示例4: calcuateFalsePositiveRate
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Calculate false positive rate,
* the false positive rate is calculated by no. false positive / total negative
*
* @param dataset the dataset that will be used for the calculation
* @param selectedRules the rule that is used for the calculation
* @return false positive for the given rules and the input dataset
*/
public double calcuateFalsePositiveRate(Instances dataset, List<Rule> selectedRules){
// calculate total negative example
int falsePostive = 0;
int trueNegative = 0;
Iterator<Instance> instancesIterator;
// go through each selected rule
for (Rule aRule : selectedRules) {
// got HEAD from the rules
List<Term> HeadTerms = aRule.getRightSdie();
List<Term> bodyTerm = aRule.getLeftSide();
// check whether this rule is positive (covered by the HEAD only)
instancesIterator = dataset.iterator();
while(instancesIterator.hasNext()){
Instance anInstance = instancesIterator.next();
if(instanceCoveredByTermsList(anInstance, bodyTerm) == true && instanceCoveredByTermsList(anInstance, HeadTerms) == false){
falsePostive++;
}
if(instanceCoveredByTermsList(anInstance, bodyTerm) == false && instanceCoveredByTermsList(anInstance, HeadTerms) == false){
trueNegative++;
}
}
}
double falsePositiveRate = (double) falsePostive / (double) (falsePostive + trueNegative);
return falsePositiveRate;
}
示例5: collectPerfs
import weka.core.Instances; //導入方法依賴的package包/類
@Override
public Instances collectPerfs(Instances samplePoints, String perfAttName) {
Instances retVal = null;
if(samplePoints.attribute(perfAttName) == null){
Attribute performance = new Attribute(perfAttName);
samplePoints.insertAttributeAt(performance, samplePoints.numAttributes());
}
File perfFolder = new File(perfsfilepath);
int tot=0;
if(perfFolder.exists()){
//let's get all the name set for the sample points
Iterator<Instance> itr = samplePoints.iterator();
TreeSet<String> insNameSet = new TreeSet<String>();
HashMap<String, Integer> mapping = new HashMap<String, Integer>();
int pos=0;
while(itr.hasNext()){
String mdstr = getMD5(itr.next());
insNameSet.add(mdstr);
mapping.put(mdstr, new Integer(pos++));
}
//now we collect
File[] perfFiles = perfFolder.listFiles(new PerfsFileFilter(insNameSet));
tot = perfFiles.length;
if(tot > 0) isInterrupt = true;
for(int i=0;i<tot;i++){
Instance ins = samplePoints.get(mapping.get(perfFiles[i].getName()));
double[] results = getPerf(perfFiles[i].getAbsolutePath());
if(results!=null){
ins.setValue(samplePoints.numAttributes()-1, results[0]);
}
}
}
retVal = samplePoints;
retVal.setClassIndex(retVal.numAttributes()-1);
System.out.println("Total number of collected performances is : "+tot);
return retVal;
}
示例6: removeInstancesCoveredByRule
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Remove all data instances from the dataset for a given rule
*
* @param dataset the input dataset
* @param aRule the rule is used to classify instances and these instances will be removed from the dataset
*/
public void removeInstancesCoveredByRule(Instances dataset, Rule aRule){
List<Term> aLeftSide = aRule.getLeftSide();
List<Term> aRightSide = aRule.getRightSdie();
Iterator<Instance> datasetIterator = dataset.iterator();
while(datasetIterator.hasNext()){
Instance anInstance = datasetIterator.next();
if(instanceCoveredByTermsList(anInstance, aLeftSide) == true &&
instanceCoveredByTermsList(anInstance, aRightSide) == true){
datasetIterator.remove();
}
}
}
示例7: calcualteTruePostiveRate
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Calculate true positive rate,
* The rate of true positive is calculated by no. true positive / total positive
*
* @param dataset
* @param selectedRules
* @return
*/
public double calcualteTruePostiveRate(Instances dataset, List<Rule> selectedRules){
// calculate total postive example
int truePositive = 0;
int falseNegative = 0;
Iterator<Instance> instancesIterator;
// go through each selected rule
for (Rule aRule : selectedRules) {
// got HEAD from the rules
List<Term> HeadTerms = aRule.getRightSdie();
List<Term> bodyTerm = aRule.getLeftSide();
// check whether this rule is positive (covered by the HEAD only)
instancesIterator = dataset.iterator();
while(instancesIterator.hasNext()){
Instance anInstance = instancesIterator.next();
if(instanceCoveredByTermsList(anInstance, HeadTerms) == true && instanceCoveredByTermsList(anInstance, bodyTerm) == true){
truePositive++;
}
if(instanceCoveredByTermsList(anInstance, HeadTerms) == false && instanceCoveredByTermsList(anInstance, bodyTerm) == true){
falseNegative++;
}
}
}
double truePostitveRate = (double) truePositive / (double) (truePositive + falseNegative);
return truePostitveRate;
}