当前位置: 首页>>代码示例>>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;未经允许,请勿转载。