本文整理汇总了Java中weka.core.Instances.classAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Instances.classAttribute方法的具体用法?Java Instances.classAttribute怎么用?Java Instances.classAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.core.Instances
的用法示例。
在下文中一共展示了Instances.classAttribute方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instancesToDenseDMatrix
import weka.core.Instances; //导入方法依赖的package包/类
public static DMatrix instancesToDenseDMatrix(Instances instances) throws XGBoostError {
int colNum = instances.numAttributes()-1;
int rowNum = instances.size();
float[] data = new float[colNum*rowNum];
float[] labels = new float[instances.size()];
Attribute classAttribute = instances.classAttribute();
int classAttrIndex = classAttribute.index();
for(int i=0, dataIndex = 0; i<instances.size(); i++) {
Instance instance = instances.get(i);
labels[i] = (float) instance.classValue();
Enumeration<Attribute> attributeEnumeration = instance.enumerateAttributes();
while (attributeEnumeration.hasMoreElements()) {
Attribute attribute = attributeEnumeration.nextElement();
int attrIndex = attribute.index();
if(attrIndex == classAttrIndex){
continue;
}
data[dataIndex]= (float) instance.value(attribute);
dataIndex++;
}
}
DMatrix dMatrix = new DMatrix(data, rowNum, colNum);
dMatrix.setLabel(labels);
return dMatrix;
}
示例2: getClasses
import weka.core.Instances; //导入方法依赖的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: buildClassifier
import weka.core.Instances; //导入方法依赖的package包/类
@Override
public void buildClassifier(Instances data) throws Exception {
// Initialise training dataset
Attribute classAttribute = data.classAttribute();
classedData = new HashMap<>();
classedDataIndices = new HashMap<>();
for (int c = 0; c < data.numClasses(); c++) {
classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
}
train = new SymbolicSequence[data.numInstances()];
classMap = new String[train.length];
maxLength = 0;
for (int i = 0; i < train.length; i++) {
Instance sample = data.instance(i);
MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
maxLength = Math.max(maxLength, sequence.length);
int shift = (sample.classIndex() == 0) ? 1 : 0;
for (int t = 0; t < sequence.length; t++) {
sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
}
train[i] = new SymbolicSequence(sequence);
String clas = sample.stringValue(classAttribute);
classMap[i] = clas;
classedData.get(clas).add(train[i]);
classedDataIndices.get(clas).add(i);
}
warpingMatrix = new double[maxLength][maxLength];
U = new double[maxLength];
L = new double[maxLength];
maxWindow = Math.round(1 * maxLength);
searchResults = new String[maxWindow+1];
nns = new int[maxWindow+1][train.length];
dist = new double[train.length][train.length];
// Start searching for the best window
searchBestWarpingWindow();
// Saving best windows found
System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
示例4: buildClassifier
import weka.core.Instances; //导入方法依赖的package包/类
@Override
public void buildClassifier(Instances data) throws Exception {
// Initialise training dataset
Attribute classAttribute = data.classAttribute();
classedData = new HashMap<>();
classedDataIndices = new HashMap<>();
for (int c = 0; c < data.numClasses(); c++) {
classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
}
train = new SymbolicSequence[data.numInstances()];
classMap = new String[train.length];
maxLength = 0;
for (int i = 0; i < train.length; i++) {
Instance sample = data.instance(i);
MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
maxLength = Math.max(maxLength, sequence.length);
int shift = (sample.classIndex() == 0) ? 1 : 0;
for (int t = 0; t < sequence.length; t++) {
sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
}
train[i] = new SymbolicSequence(sequence);
String clas = sample.stringValue(classAttribute);
classMap[i] = clas;
classedData.get(clas).add(train[i]);
classedDataIndices.get(clas).add(i);
}
warpingMatrix = new double[maxLength][maxLength];
U = new double[maxLength];
L = new double[maxLength];
U1 = new double[maxLength];
L1 = new double[maxLength];
maxWindow = Math.round(1 * maxLength);
searchResults = new String[maxWindow+1];
nns = new int[maxWindow+1][train.length];
dist = new double[maxWindow+1][train.length];
cache = new SequenceStatsCache(train, maxWindow);
lazyUCR = new LazyAssessNNEarlyAbandon[train.length][train.length];
for (int i = 0; i < train.length; i++) {
for (int j = 0; j < train.length; j++) {
lazyUCR[i][j] = new LazyAssessNNEarlyAbandon(cache);
}
}
// Start searching for the best window
searchBestWarpingWindow();
// Saving best windows found
System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
示例5: buildClassifier
import weka.core.Instances; //导入方法依赖的package包/类
@Override
public void buildClassifier(Instances data) throws Exception {
// Initialise training dataset
Attribute classAttribute = data.classAttribute();
classedData = new HashMap<>();
classedDataIndices = new HashMap<>();
for (int c = 0; c < data.numClasses(); c++) {
classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
}
train = new SymbolicSequence[data.numInstances()];
classMap = new String[train.length];
maxLength = 0;
for (int i = 0; i < train.length; i++) {
Instance sample = data.instance(i);
MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
maxLength = Math.max(maxLength, sequence.length);
int shift = (sample.classIndex() == 0) ? 1 : 0;
for (int t = 0; t < sequence.length; t++) {
sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
}
train[i] = new SymbolicSequence(sequence);
String clas = sample.stringValue(classAttribute);
classMap[i] = clas;
classedData.get(clas).add(train[i]);
classedDataIndices.get(clas).add(i);
}
warpingMatrix = new double[maxLength][maxLength];
U = new double[maxLength];
L = new double[maxLength];
U1 = new double[maxLength];
L1 = new double[maxLength];
maxWindow = Math.round(1 * maxLength);
searchResults = new String[maxWindow+1];
nns = new int[maxWindow+1][train.length];
dist = new double[train.length][train.length];
cache = new SequenceStatsCache(train, maxWindow);
lazyUCR = new LazyAssessNNEarlyAbandon[train.length][train.length];
for (int i = 0; i < train.length; i++) {
for (int j = 0; j < train.length; j++) {
lazyUCR[i][j] = new LazyAssessNNEarlyAbandon(cache);
}
}
// Start searching for the best window
searchBestWarpingWindow();
// Saving best windows found
System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}
示例6: buildClassifier
import weka.core.Instances; //导入方法依赖的package包/类
@Override
public void buildClassifier(Instances data) throws Exception {
// Initialise training dataset
Attribute classAttribute = data.classAttribute();
classedData = new HashMap<>();
classedDataIndices = new HashMap<>();
for (int c = 0; c < data.numClasses(); c++) {
classedData.put(data.classAttribute().value(c), new ArrayList<SymbolicSequence>());
classedDataIndices.put(data.classAttribute().value(c), new ArrayList<Integer>());
}
train = new SymbolicSequence[data.numInstances()];
classMap = new String[train.length];
maxLength = 0;
for (int i = 0; i < train.length; i++) {
Instance sample = data.instance(i);
MonoDoubleItemSet[] sequence = new MonoDoubleItemSet[sample.numAttributes() - 1];
maxLength = Math.max(maxLength, sequence.length);
int shift = (sample.classIndex() == 0) ? 1 : 0;
for (int t = 0; t < sequence.length; t++) {
sequence[t] = new MonoDoubleItemSet(sample.value(t + shift));
}
train[i] = new SymbolicSequence(sequence);
String clas = sample.stringValue(classAttribute);
classMap[i] = clas;
classedData.get(clas).add(train[i]);
classedDataIndices.get(clas).add(i);
}
warpingMatrix = new double[maxLength][maxLength];
U = new double[maxLength];
L = new double[maxLength];
maxWindow = Math.round(1 * maxLength);
searchResults = new String[maxWindow+1];
nns = new int[maxWindow+1][train.length];
dist = new double[maxWindow+1][train.length];
// Start searching for the best window
searchBestWarpingWindow();
// Saving best windows found
System.out.println("Windows found=" + bestWarpingWindow + " Best Acc=" + (1-bestScore));
}