本文整理汇总了Java中weka.core.Instances.attributeStats方法的典型用法代码示例。如果您正苦于以下问题:Java Instances.attributeStats方法的具体用法?Java Instances.attributeStats怎么用?Java Instances.attributeStats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instances
的用法示例。
在下文中一共展示了Instances.attributeStats方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: orderByLargestClass
import weka.core.Instances; //导入方法依赖的package包/类
/**
* Reorder the dataset by its largest class
* @param data
* @return
*/
public static Instances orderByLargestClass(Instances data) {
Instances newData = new Instances(data, data.numInstances());
// get the number of class in the data
int nbClass = data.numClasses();
int[] instancePerClass = new int[nbClass];
int[] labels = new int[nbClass];
int[] classIndex = new int[nbClass];
// sort the data base on its class
data.sort(data.classAttribute());
// get the number of instances per class in the data
for (int i = 0; i < nbClass; i++) {
instancePerClass[i] = data.attributeStats(data.classIndex()).nominalCounts[i];
labels[i] = i;
if (i > 0)
classIndex[i] = classIndex[i-1] + instancePerClass[i-1];
}
QuickSort.sort(instancePerClass, labels);
for (int i = nbClass-1; i >=0 ; i--) {
for (int j = 0; j < instancePerClass[i]; j++) {
newData.add(data.instance(classIndex[labels[i]] + j));
}
}
return newData;
}
示例2: 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
}
示例3: findBestPerfIndex
import weka.core.Instances; //导入方法依赖的package包/类
public static int findBestPerfIndex(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 i;
return -1;//should never return -1
}
示例4: orderByCompactClass
import weka.core.Instances; //导入方法依赖的package包/类
/**
* Reorder the data by compactness of each class using Euclidean distance
* @param data
* @return
*/
public static Instances orderByCompactClass(Instances data) {
Instances newData = new Instances(data, data.numInstances());
// get the number of class in the data
int nbClass = data.numClasses();
int[] instancePerClass = new int[nbClass];
int[] labels = new int[nbClass];
int[] classIndex = new int[nbClass];
double[] compactness = new double[nbClass];
// sort the data base on its class
data.sort(data.classAttribute());
int start = 0;
// get the number of instances per class in the data
for (int i = 0; i < nbClass; i++) {
instancePerClass[i] = data.attributeStats(data.classIndex()).nominalCounts[i];
labels[i] = i;
if (i > 0)
classIndex[i] = classIndex[i-1] + instancePerClass[i-1];
int end = start + instancePerClass[i];
int counter = 0;
double[][] dataPerClass = new double[instancePerClass[i]][data.numAttributes()-1];
for (int j = start; j < end; j++) {
dataPerClass[counter++] = data.instance(j).toDoubleArray();
}
double[] mean = arithmeticMean(dataPerClass);
double d = 0;
for (int j = 0; j < instancePerClass[i]; j++) {
double temp = euclideanDistance(mean, dataPerClass[j]);
temp *= temp;
temp -= (mean[0] - dataPerClass[j][0]) * (mean[0] - dataPerClass[j][0]);
d += temp;
}
compactness[i] = d / instancePerClass[i];
start = end;
}
QuickSort.sort(compactness, labels);
for (int i = nbClass-1; i >=0 ; i--) {
for (int j = 0; j < instancePerClass[labels[i]]; j++) {
newData.add(data.instance(classIndex[labels[i]] + j));
}
}
return newData;
}