本文整理汇总了Java中weka.core.Instances.attribute方法的典型用法代码示例。如果您正苦于以下问题:Java Instances.attribute方法的具体用法?Java Instances.attribute怎么用?Java Instances.attribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instances
的用法示例。
在下文中一共展示了Instances.attribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: generateDecisionTree
import weka.core.Instances; //导入方法依赖的package包/类
protected Classifier generateDecisionTree(AbstractClusterer clusterer, MarkovAttributeSet aset, Instances data) throws Exception {
// We need to create a new Attribute that has the ClusterId
Instances newData = data; // new Instances(data);
newData.insertAttributeAt(new Attribute("ClusterId"), newData.numAttributes());
Attribute cluster_attr = newData.attribute(newData.numAttributes()-1);
assert(cluster_attr != null);
assert(cluster_attr.index() > 0);
newData.setClass(cluster_attr);
// We will then tell the Classifier to predict that ClusterId based on the MarkovAttributeSet
ObjectHistogram<Integer> cluster_h = new ObjectHistogram<Integer>();
for (int i = 0, cnt = newData.numInstances(); i < cnt; i++) {
// Grab the Instance and throw it at the the clusterer to get the target cluster
Instance inst = newData.instance(i);
int c = (int)clusterer.clusterInstance(inst);
inst.setClassValue(c);
cluster_h.put(c);
} // FOR
System.err.println("Number of Elements: " + cluster_h.getValueCount());
System.err.println(cluster_h);
NumericToNominal filter = new NumericToNominal();
filter.setInputFormat(newData);
newData = Filter.useFilter(newData, filter);
String output = this.catalog_proc.getName() + "-labeled.arff";
FileUtil.writeStringToFile(output, newData.toString());
LOG.info("Wrote labeled data set to " + output);
// Decision Tree
J48 j48 = new J48();
String options[] = {
"-S", Integer.toString(this.rand.nextInt()),
};
j48.setOptions(options);
// Make sure we add the ClusterId attribute to a new MarkovAttributeSet so that
// we can tell the Classifier to classify that!
FilteredClassifier fc = new FilteredClassifier();
MarkovAttributeSet classifier_aset = new MarkovAttributeSet(aset);
classifier_aset.add(cluster_attr);
fc.setFilter(classifier_aset.createFilter(newData));
fc.setClassifier(j48);
// Bombs away!
fc.buildClassifier(newData);
return (fc);
}
示例3: scaleDownNeighbordists
import weka.core.Instances; //导入方法依赖的package包/类
private static ArrayList<Attribute> scaleDownNeighbordists(Instances previousSet, Instance center){
ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
int attNum = center.numAttributes();
int pos = -1;
if(previousSet.attribute(PerformanceAttName)!=null)
pos = previousSet.attribute(PerformanceAttName).index();
//traverse each dimension
Enumeration<Instance> enu;
double[] minDists = new double[2];
double val;
for(int i=0;i<attNum;i++){
if(i==pos)
continue;
enu = previousSet.enumerateInstances();
minDists[0] = 1-Double.MAX_VALUE;
minDists[1] = Double.MAX_VALUE;
while(enu.hasMoreElements()){
Instance ins = enu.nextElement();
if(!ins.equals(center)){
val = ins.value(i)-center.value(i);
if(val<0)
minDists[0] = Math.max((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[0]);
else
minDists[1] = Math.min((double)((int)((ins.value(i)-center.value(i))*1000))/1000.0, minDists[1]);
}
}
//now we set the range
Properties p1 = new Properties();
double upper = center.value(i)+minDists[1], lower=center.value(i)+minDists[0];
TreeSet<Double> detourSet = new TreeSet<Double>();
detourSet.add(upper);
detourSet.add(lower);
detourSet.add(previousSet.attribute(i).getUpperNumericBound());
detourSet.add(previousSet.attribute(i).getLowerNumericBound());
switch(detourSet.size()){
case 1:
upper=lower=detourSet.first();
break;
case 2:
upper = detourSet.last();
lower = detourSet.first();
break;
case 3:
upper=lower=detourSet.higher(detourSet.first());
break;
default://case 4:
upper=detourSet.lower(detourSet.last());
lower=detourSet.higher(detourSet.first());
break;
}
p1.setProperty("range", "["+String.valueOf(lower)+","+String.valueOf(upper)+"]");
ProtectedProperties prop1 = new ProtectedProperties(p1);
localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
}
return localAtts;
}
示例4: 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;
}