本文整理匯總了Java中weka.core.Instances.get方法的典型用法代碼示例。如果您正苦於以下問題:Java Instances.get方法的具體用法?Java Instances.get怎麽用?Java Instances.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.core.Instances
的用法示例。
在下文中一共展示了Instances.get方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: instancesToDMatrix
import weka.core.Instances; //導入方法依賴的package包/類
public static DMatrix instancesToDMatrix(Instances instances) throws XGBoostError {
long[] rowHeaders = new long[instances.size()+1];
rowHeaders[0]=0;
List<Float> dataList = new ArrayList<>();
List<Integer> colList = new ArrayList<>();
float[] labels = new float[instances.size()];
for(int i=0; i<instances.size(); i++) {
Instance instance = instances.get(i);
rowHeaders[i] = dataList.size();
processInstance(instance, dataList, colList);
labels[i] = (float) instance.classValue();
}
rowHeaders[rowHeaders.length - 1] = dataList.size();
int colNum = instances.numAttributes()-1;
DMatrix dMatrix = createDMatrix(rowHeaders, dataList, colList, colNum);
dMatrix.setLabel(labels);
return dMatrix;
}
示例2: instancesToDenseDMatrix
import weka.core.Instances; //導入方法依賴的package包/類
public static DMatrix instancesToDenseDMatrix(Instances instances) throws XGBoostError {
int colNum = instances.numAttributes()-1;
int rowNum = instances.size();
float[] data = new float[colNum*rowNum];
float[] labels = new float[instances.size()];
Attribute classAttribute = instances.classAttribute();
int classAttrIndex = classAttribute.index();
for(int i=0, dataIndex = 0; i<instances.size(); i++) {
Instance instance = instances.get(i);
labels[i] = (float) instance.classValue();
Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
while (attributeEnumeration.hasMoreElements()) {
Attribute attribute = attributeEnumeration.nextElement();
int attrIndex = attribute.index();
if(attrIndex == classAttrIndex){
continue;
}
data[dataIndex]= (float) instance.value(attribute);
dataIndex++;
}
}
DMatrix dMatrix = new DMatrix(data, rowNum, colNum);
dMatrix.setLabel(labels);
return dMatrix;
}
示例3: findBestPerf
import weka.core.Instances; //導入方法依賴的package包/類
public static Instance findBestPerf(Instances data){
int idx = data.numAttributes()-1;
double bestPerf = data.attributeStats(idx).numericStats.max;
for(int i=0;i<data.numInstances();i++)
if(data.get(i).value(idx)==bestPerf)
return data.get(i);
return null;//should never return NULL
}
示例4: 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;
}
示例5: calcualteWRA
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Calculate Weighted Relative Accuracy (WRA) for from the input dataset for a given rule.
*
* @param dataset the dataset
* @param aLeftHandSide left-side (BODY) of the rule
* @param aRightHandSide right-side (HEAD) of the rule
* @return WRA value of the rule on the dataset
*/
public double calcualteWRA(Instances dataset, List<Term> aLeftHandSide, List<Term> aRightHandSide){
double totalPositive;
double totalNegative;
double ruleTruePositive = 0;
double ruleFalsePositive = 0;
double ruleTrueNegative = 0;
double ruleFalseNegative = 0;
// calcualte truePositive, trueNegative, falsePostive, falseNegative for the Rules
for (int instanceI = 0; instanceI < dataset.size(); instanceI++) {
Instance anInstance = dataset.get(instanceI);
// calculate true postive and true negative instances for the rules
if(instanceCoveredByTermsList(anInstance, aLeftHandSide)){
if(instanceCoveredByTermsList(anInstance, aRightHandSide)){
ruleTruePositive++;
}else{
ruleFalsePositive++;
}
}else if(instanceCoveredByTermsList(anInstance, aRightHandSide)){
ruleFalsePositive++;
}else{
ruleTrueNegative++;
}
}
// calculate totalPositive and totalNegative
totalPositive = ruleTruePositive + ruleFalseNegative;
totalNegative = ruleFalsePositive + ruleTrueNegative;
// start calcualting WRA
double ruleWRA = (ruleTruePositive + ruleFalsePositive) / (totalPositive + totalNegative) *
( (ruleTruePositive / (ruleTruePositive + ruleFalsePositive) - ( totalPositive / (totalPositive + totalNegative) )));
return ruleWRA;
}
示例6: runExp
import weka.core.Instances; //導入方法依賴的package包/類
public Instances runExp(Instances samplePoints, String perfAttName){
Instances retVal = null;
if(samplePoints.attribute(perfAttName) == null){
Attribute performance = new Attribute(perfAttName);
samplePoints.insertAttributeAt(performance, samplePoints.numAttributes());
}
int pos = samplePoints.numInstances();
int count = 0;
for (int i = 0; i < pos; i++) {
Instance ins = samplePoints.get(i);
HashMap hm = new HashMap();
int tot = 0;
for (int j = 0; j < ins.numAttributes(); j++) {
hm.put(ins.attribute(j).name(), ins.value(ins.attribute(j)));
}
boolean testRet;
if (Double.isNaN(ins.value(ins.attribute(ins.numAttributes() - 1)))) {
testRet = this.startTest(hm, i, isInterrupt);
double y = 0;
if (!testRet) {// the setting does not work, we skip it
y = -1;
count++;
if (count >= targetTestErrorNum) {
System.out.println("There must be somthing wrong with the system. Please check and restart.....");
System.exit(1);
}
} else {
y = getPerformanceByType(performanceType);
count = 0;
}
ins.setValue(samplePoints.numAttributes() - 1, y);
writePerfstoFile(ins);
} else {
continue;
}
}
retVal = samplePoints;
retVal.setClassIndex(retVal.numAttributes()-1);
return retVal;
}