本文整理匯總了Java中weka.core.Instances.deleteAttributeAt方法的典型用法代碼示例。如果您正苦於以下問題:Java Instances.deleteAttributeAt方法的具體用法?Java Instances.deleteAttributeAt怎麽用?Java Instances.deleteAttributeAt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.core.Instances
的用法示例。
在下文中一共展示了Instances.deleteAttributeAt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getUserSpecifiedDataset
import weka.core.Instances; //導入方法依賴的package包/類
/**
* Create a new, smaller data Instances that contains only the attributes the user selected.
*
* It does this by counting out the indices that the user wanted and removing anything that doesn't match.
* If it were elegant, it wouldn't be java. :/
*
* @return Instances newData
*/
public Instances getUserSpecifiedDataset(){
Instances newData = new Instances(this.master);
newData.setClass(newData.attribute(this.classIndex));
//need to reverse sort them so our array doesn't get screwed up.
Integer[] keepAttributes = new Integer[this.userAttributeSelectionIndices.length];
for (int i = 0; i < this.userAttributeSelectionIndices.length; i++) {
keepAttributes[i] = Integer.valueOf(this.userAttributeSelectionIndices[i]);
}
Arrays.sort(keepAttributes, Collections.reverseOrder());
for(Integer i = this.userAttributeSelectionIndices.length; i >= 0; --i){
if(! Arrays.asList(keepAttributes).contains(i)){
newData.deleteAttributeAt(i);
}
}
return(newData);
}
示例2: preprocessInstances
import weka.core.Instances; //導入方法依賴的package包/類
public static ArrayList<String> preprocessInstances(Instances retval){
double[][] cMatrix;
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> deleteAttNames = new ArrayList<String>();
PrincipalComponents pc = new PrincipalComponents();
HashMap<Integer, ArrayList<Integer>> filter = new HashMap<Integer, ArrayList<Integer>>();
try {
pc.buildEvaluator(retval);
cMatrix = pc.getCorrelationMatrix();
for(int i = 0; i < cMatrix.length; i++){
ArrayList<Integer> record = new ArrayList<Integer>();
for(int j = i + 1; j < cMatrix.length; j++)
if(cMatrix[i][j] >= correlationFactorThreshold || cMatrix[i][j] <= -correlationFactorThreshold){
record.add(j);
}
if(record.size() != 0){
filter.put(i, record);
}
}
Iterator<Map.Entry<Integer, ArrayList<Integer>>> iter = filter.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Integer, ArrayList<Integer>> entry = iter.next();
ArrayList<Integer> arr = entry.getValue();
for(int i = 0; i < arr.size(); i++)
if(arr.get(i) != cMatrix.length - 1 && !deleteAttNames.contains(retval.attribute(arr.get(i)).name())){
deleteAttNames.add(retval.attribute(arr.get(i)).name());
}
if(arr.contains(cMatrix.length-1)){
result.add(retval.attribute(Integer.parseInt(entry.getKey().toString())).name());
}
}
for(int i = 0; i < deleteAttNames.size(); i++){
retval.deleteAttributeAt(retval.attribute(deleteAttNames.get(i)).index());
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}