本文整理匯總了Java中weka.core.Attribute.numValues方法的典型用法代碼示例。如果您正苦於以下問題:Java Attribute.numValues方法的具體用法?Java Attribute.numValues怎麽用?Java Attribute.numValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類weka.core.Attribute
的用法示例。
在下文中一共展示了Attribute.numValues方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isClassTheMajortiy
import weka.core.Attribute; //導入方法依賴的package包/類
private boolean isClassTheMajortiy(ArrayList<Instance> instances, double classification){
List<Instance> instancesList = new ArrayList<>(instances);
TreeMap<Double, Double> classificationProbability = new TreeMap<>();
Attribute classAttribute = instances.get(0).classAttribute();
for (double i = 0; i < classAttribute.numValues(); i++) {
int matchedClassCount = 0;
for (Instance instance : instancesList) {
if(instance.classValue() == i){
matchedClassCount++;
}
}
classificationProbability.put(((double) matchedClassCount / (double) instancesList.size()), i);
}
return (classificationProbability.lastEntry().getValue() == classification);
}
示例2: getClasses
import weka.core.Attribute; //導入方法依賴的package包/類
protected static String[] getClasses(Instances instances) {
Attribute classAttribute = instances.classAttribute();
String[] result = new String[classAttribute.numValues()];
for (int i = 0; i < result.length; ++i)
result[i] = classAttribute.value(i);
return result;
}
示例3: getMultiDim
import weka.core.Attribute; //導入方法依賴的package包/類
/**
* Assumptions:(1)Numberic is continuous and has lower/upper bounds; (2) Nominals have domains permutable
*
* @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
*/
private static Instances getMultiDim(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid){
int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
ArrayList<Integer>[] setWithMaxMinDist=null;
//generate L sets of sampleSetSize points
for(int i=0; i<L; i++){
ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
//compute the minimum distance minDist between any sample pair for each set
crntMinDist = minDistForSet(setPerm);
//select the set with the maximum minDist
if(crntMinDist>maxMinDist){
setWithMaxMinDist = setPerm;
maxMinDist = crntMinDist;
}
}
//generate and output the set with the maximum minDist as the result
//first, divide the domain of each attribute into sampleSetSize equal subdomain
double[][] bounds = new double[atts.size()][sampleSetSize+1];//sampleSetSize+1 to include the lower and upper bounds
Iterator<Attribute> itr = atts.iterator();
Attribute crntAttr;
double pace;
for(int i=0;i<bounds.length;i++){
crntAttr = itr.next();
if(crntAttr.isNumeric()){
bounds[i][0] = crntAttr.getLowerNumericBound();
bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
pace = (crntAttr.getUpperNumericBound() - crntAttr.getLowerNumericBound())/sampleSetSize;
for(int j=1;j<sampleSetSize;j++){
bounds[i][j] = bounds[i][j-1] + pace;
}
}else{//crntAttr.isNominal()
if(crntAttr.numValues()>=sampleSetSize){
//randomly select among the set
for(int j=0;j<=sampleSetSize;j++)
bounds[i][j] = uniRand.nextInt(crntAttr.numValues());//the position of one of the nominal values
}else{
//first round-robin
int lastPart = sampleSetSize%crntAttr.numValues();
for(int j=0;j<sampleSetSize-lastPart;j++)
bounds[i][j] = j%crntAttr.numValues();
//then randomly select
for(int j=sampleSetSize-lastPart;j<=sampleSetSize;j++)
bounds[i][j] = uniRand.nextInt(crntAttr.numValues());
}
}//nominal attribute
}//get all subdomains
//second, generate the set according to setWithMaxMinDist
Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
for(int i=0;i<sampleSetSize;i++){
double[] vals = new double[atts.size()];
for(int j=0;j<vals.length;j++){
if(atts.get(j).isNumeric()){
vals[j] = useMid?
(bounds[j][setWithMaxMinDist[j].get(i)]+bounds[j][setWithMaxMinDist[j].get(i)+1])/2:
bounds[j][setWithMaxMinDist[j].get(i)]+
(
(bounds[j][setWithMaxMinDist[j].get(i)+1]-bounds[j][setWithMaxMinDist[j].get(i)])*uniRand.nextDouble()
);
}else{//isNominal()
vals[j] = bounds[j][setWithMaxMinDist[j].get(i)];
}
}
data.add(new DenseInstance(1.0, vals));
}
//third, return the generated points
return data;
}
示例4: getMultiDim
import weka.core.Attribute; //導入方法依賴的package包/類
/**
* Assumptions:(1)Numberic is continuous and has lower/upper bounds; (2) Nominals have domains permutable
*
* @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
*/
public static Instances getMultiDim(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid){
int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
ArrayList<Integer>[] setWithMaxMinDist=null;
//generate L sets of sampleSetSize points
for(int i=0; i<L; i++){
ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
//compute the minimum distance minDist between any sample pair for each set
crntMinDist = minDistForSet(setPerm);
//select the set with the maximum minDist
if(crntMinDist>maxMinDist){
setWithMaxMinDist = setPerm;
maxMinDist = crntMinDist;
}
}
//generate and output the set with the maximum minDist as the result
//first, divide the domain of each attribute into sampleSetSize equal subdomain
double[][] bounds = new double[atts.size()][sampleSetSize+1];//sampleSetSize+1 to include the lower and upper bounds
Iterator<Attribute> itr = atts.iterator();
Attribute crntAttr;
double pace;
for(int i=0;i<bounds.length;i++){
crntAttr = itr.next();
if(crntAttr.isNumeric()){
bounds[i][0] = crntAttr.getLowerNumericBound();
bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
pace = (crntAttr.getUpperNumericBound() - crntAttr.getLowerNumericBound())/sampleSetSize;
for(int j=1;j<sampleSetSize;j++){
bounds[i][j] = bounds[i][j-1] + pace;
}
}else{//crntAttr.isNominal()
if(crntAttr.numValues()>=sampleSetSize){
//randomly select among the set
for(int j=0;j<=sampleSetSize;j++)
bounds[i][j] = uniRand.nextInt(crntAttr.numValues());//the position of one of the nominal values
}else{
//first round-robin
int lastPart = sampleSetSize%crntAttr.numValues();
for(int j=0;j<sampleSetSize-lastPart;j++)
bounds[i][j] = j%crntAttr.numValues();
//then randomly select
for(int j=sampleSetSize-lastPart;j<=sampleSetSize;j++)
bounds[i][j] = uniRand.nextInt(crntAttr.numValues());
}
}//nominal attribute
}//get all subdomains
//second, generate the set according to setWithMaxMinDist
Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
for(int i=0;i<sampleSetSize;i++){
double[] vals = new double[atts.size()];
for(int j=0;j<vals.length;j++){
if(atts.get(j).isNumeric()){
vals[j] = useMid?
(bounds[j][setWithMaxMinDist[j].get(i)]+bounds[j][setWithMaxMinDist[j].get(i)+1])/2:
bounds[j][setWithMaxMinDist[j].get(i)]+
(
(bounds[j][setWithMaxMinDist[j].get(i)+1]-bounds[j][setWithMaxMinDist[j].get(i)])*uniRand.nextDouble()
);
}else{//isNominal()
vals[j] = bounds[j][setWithMaxMinDist[j].get(i)];
}
}
data.add(new DenseInstance(1.0, vals));
}
//third, return the generated points
return data;
}