當前位置: 首頁>>代碼示例>>Java>>正文


Java Instances.deleteAttributeAt方法代碼示例

本文整理匯總了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);
}
 
開發者ID:optimusmoose,項目名稱:miniML,代碼行數:25,代碼來源:DatasetBuilder.java

示例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;
}
 
開發者ID:zhuyuqing,項目名稱:bestconf,代碼行數:40,代碼來源:BestConf.java


注:本文中的weka.core.Instances.deleteAttributeAt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。