本文整理了Java中weka.core.Instances.attribute()
方法的一些代码示例,展示了Instances.attribute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.attribute()
方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:attribute
[英]Returns an attribute.
[中]返回一个属性。
代码示例来源:origin: stackoverflow.com
System.out.println("--------------------------");
double[] instanceValue1 = new double[dataRaw.numAttributes()];
instanceValue1[0] = dataRaw.attribute(0).addStringValue("This is a string!");
instanceValue1[1] = 0;
System.out.println("--------------------------");
double[] instanceValue2 = new double[dataRaw.numAttributes()];
instanceValue2[0] = dataRaw.attribute(0).addStringValue("This is second string!");
instanceValue2[1] = 1;
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
public int getNode(String sNodeName) {
int iNode = 0;
while (iNode < m_root.m_bayesNet.m_Instances.numAttributes()) {
if (m_root.m_bayesNet.m_Instances.attribute(iNode).name()
.equals(sNodeName)) {
return iNode;
}
iNode++;
}
// throw new Exception("Could not find node [[" + sNodeName + "]]");
return -1;
}
代码示例来源:origin: Waikato/weka-trunk
public StringValue(int index) {
super(index);
assert dataset.attribute(index).isString()
|| dataset.attribute(index).isNominal();
}
代码示例来源:origin: net.sf.meka.thirdparty/mulan
private void checkLabelsConsistency(Instances dataSet, Set<LabelNode> rootLabelNodes) throws InvalidDataFormatException {
// create an index for faster access to attribute based on name
Map<String, Attribute> attributesIndex = new HashMap<String, Attribute>();
for (int index = 0; index < dataSet.numAttributes(); index++) {
Attribute attribute = dataSet.attribute(index);
attributesIndex.put(attribute.name(), attribute);
}
int numInstances = dataSet.numInstances();
for (int index = 0; index < numInstances; index++) {
Instance instance = dataSet.instance(index);
for (LabelNode labelNode : rootLabelNodes) {
checkSubtreeConsistency(labelNode, instance, true, attributesIndex);
}
}
}
代码示例来源:origin: Waikato/weka-trunk
/**
* Set the output format. Takes the current average class values and
* m_InputFormat and calls setOutputFormat(Instances) appropriately.
*/
private void setOutputFormat() {
Instances newData;
ArrayList<Attribute> newAtts = new ArrayList<Attribute>(getInputFormat()
.numAttributes());
for (int j = 0; j < getInputFormat().numAttributes(); j++) {
Attribute att = getInputFormat().attribute(j);
if (!att.isNominal() || !m_AttIndex.isInRange(j)) {
newAtts.add(att);
} else {
Attribute newAtt = new Attribute(att.name(), (ArrayList<String>) null);
newAtt.setWeight(getInputFormat().attribute(j).weight());
newAtts.add(newAtt);
}
}
// Construct new header
newData = new Instances(getInputFormat().relationName(), newAtts, 0);
newData.setClassIndex(getInputFormat().classIndex());
setOutputFormat(newData);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/NNge
/**
* Updates the minimum, maximum, sum, sumSquare values for all the attributes
*
* @param instance the new instance
*/
private void updateMinMax(Instance instance){
for (int j = 0; j < m_Train.numAttributes(); j++) {
if(m_Train.classIndex() == j || m_Train.attribute(j).isNominal())
continue;
if (instance.value(j) < m_MinArray[j])
m_MinArray[j] = instance.value(j);
if (instance.value(j) > m_MaxArray[j])
m_MaxArray[j] = instance.value(j);
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/** Need to remove attributes that are not nominal/numeric */
protected void setUp() throws Exception {
super.setUp();
// remove attributes that are not nominal/numeric
int i = 0;
while (i < m_Instances.numAttributes()) {
if ( ( !m_Instances.attribute(i).isNominal()
&& !m_Instances.attribute(i).isNumeric() )
|| m_Instances.attribute(i).isDate() )
m_Instances.deleteAttributeAt(i);
else
i++;
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
public void testTypical() {
Instances result = useFilter();
// Number of attributes and instances shouldn't change
assertEquals(m_Instances.numAttributes(), result.numAttributes());
assertEquals(m_Instances.numInstances(), result.numInstances());
assertTrue(!m_Instances.relationName().equals(result.relationName()));
for (int i = 0; i < m_Instances.numAttributes(); i++) {
Attribute inatt = m_Instances.attribute(i);
Attribute outatt = result.attribute(i);
if (!inatt.isString() && !inatt.isDate()) {
assertTrue("Attribute names should be changed",
!inatt.name().equals(outatt.name()));
if (inatt.isNominal()) {
assertEquals("Number of nominal values shouldn't change",
inatt.numValues(), outatt.numValues());
for (int j = 0; j < inatt.numValues(); j++) {
assertTrue("Nominal labels should be changed",
!inatt.value(j).equals(outatt.value(j)));
}
}
}
}
}
代码示例来源:origin: Stratio/wikipedia-parser
public GroupFeature(List<FeatureExtractor> features) {
this.features = ImmutableList.copyOf(features);
ImmutableList.Builder<Attribute> result = ImmutableList.builder();
for (FeatureExtractor fe: this.features) {
for (Attribute att: fe.attributes()) {
result.add((Attribute)att.copy());
}
}
_attributes = result.build();
_instances = new Instances("FOO", newArrayList(_attributes), 0);
result = ImmutableList.builder();
for (int i = 0; i < _instances.numAttributes(); i++) {
result.add(_instances.attribute(i));
}
_attributes = result.build();
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Returns true if all attribute weights are the same and false otherwise. Returns true if there are no attributes.
* The class attribute (if set) is skipped when this test is performed.
*/
public boolean allAttributeWeightsIdentical() {
boolean foundOne = false;
double weight = 0;
for (int i = 0; i < numAttributes(); i++) {
if (i != classIndex()) {
if (foundOne && (attribute(i).weight() != weight)) {
return false;
} else if (!foundOne) {
foundOne = true;
weight = attribute(i).weight();
}
}
}
return true;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
public void testTypical2() {
m_Filter = getFilter("3-4");
Instances result = useFilter();
assertEquals(m_Instances.numAttributes(), result.numAttributes());
for (int i = 0; i < result.numAttributes(); i++) {
if (i != 2) {
assertEquals(m_Instances.attribute(i).type(), result.attribute(i).type());
assertEquals(m_Instances.attribute(i).name(), result.attribute(i).name());
} else {
assertEquals(Attribute.NOMINAL, result.attribute(i).type());
assertEquals(1, result.attribute(i).numValues());
}
}
}
代码示例来源:origin: net.sf.meka/meka
public static final String toDebugString(Instances D) {
int L = D.classIndex();
StringBuilder sb = new StringBuilder();
sb.append("D="+D.numInstances());
sb.append(" L="+L+" {");
for(int j = 0; j < L; j++) {
sb.append(D.attribute(j).name()+" ");
}
sb.append("}");
return sb.toString();
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Initialize with data from the step
*/
protected void initialize() {
m_stringInstances = ((DataGrid) getStepToEdit()).getData();
m_listModel = new DefaultListModel<>();
m_list.setModel(m_listModel);
if (m_stringInstances != null && m_stringInstances.length() > 0) {
try {
Instances insts = new Instances(new StringReader(m_stringInstances));
for (int i = 0; i < insts.numAttributes(); i++) {
Attribute a = insts.attribute(i);
String nomOrDate = "";
if (a.isNominal()) {
for (int j = 0; j < a.numValues(); j++) {
nomOrDate += a.value(j) + ",";
}
nomOrDate = nomOrDate.substring(0, nomOrDate.length() - 1);
} else if (a.isDate()) {
nomOrDate = a.getDateFormat();
}
AttDef def = new AttDef(a.name(), a.type(), nomOrDate);
m_listModel.addElement(def);
}
m_viewerPanel.setInstances(insts);
} catch (Exception ex) {
showErrorDialog(ex);
}
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
public void testTypical() {
m_Filter = getFilter();
Instances result = useFilter();
assertEquals(m_Instances.numAttributes(), result.numAttributes());
assertEquals(m_Instances.numInstances(), result.numInstances());
// the discretized attribute must be nominal
assertTrue(result.attribute(m_AttIndex).isNominal());
}
代码示例来源:origin: net.sf.meka.thirdparty/mulan
protected void buildInternal(MultiLabelInstances mlData) throws Exception {
Instances transformedData;
transformation = new LabelPowersetTransformation();
debug("Transforming the training set.");
transformedData = transformation.transformInstances(mlData);
//debug("Transformed training set: \n + transformedData.toString());
// check for unary class
debug("Building single-label classifier.");
if (transformedData.attribute(transformedData.numAttributes() - 1).numValues() > 1) {
baseClassifier.buildClassifier(transformedData);
}
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Tests default setup.
*/
public void testTypical() {
Instances result = useFilter();
// Number of attributes and instances shouldn't change
assertEquals(m_Instances.numAttributes(), result.numAttributes());
assertEquals(m_Instances.numInstances(), result.numInstances());
Attribute mergedAtt = result.attribute(4);
// All values should be merged for this attribute
assertTrue("Attribute 5 has all values merged in result", mergedAtt
.value(0).equals("a_or_b_or_c_or_d"));
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Tests that ordering didn't change.
*/
public void testUnchangedOrder() {
m_Filter = getFilter(SortLabels.SORT_CASESENSITIVE, "first-last");
testBuffered();
Instances result = performTest();
for (int i = 0; i < m_Instances.attribute(2).numValues(); i++)
assertEquals("Values differ for index #" + (i+1), m_Instances.attribute(2).value(i), result.attribute(2).value(i));
}
代码示例来源:origin: Waikato/meka
/**
* jPMF - Joint PMF.
* @return the joint PMF of the j-th and k-th labels in D.
*/
public static double[][] jPMF(Instances D, int j, int k) {
double JOINT[][] = new double[D.attribute(j).numValues()][D.attribute(k).numValues()];
int N = D.numInstances();
for(int i = 0; i < N; i++) {
int v_j = (int)Math.round(D.instance(i).value(j));
int v_k = (int)Math.round(D.instance(i).value(k));
JOINT[v_j][v_k] += (1.0 / (double)N);
}
return JOINT;
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Set the output format. Takes the current average class values and
* m_InputFormat and calls setOutputFormat(Instances) appropriately.
*/
private void setOutputFormat() {
Instances newData;
ArrayList<Attribute> newAtts = new ArrayList<Attribute>(getInputFormat()
.numAttributes());
for (int j = 0; j < getInputFormat().numAttributes(); j++) {
Attribute att = getInputFormat().attribute(j);
if (!att.isNominal() || !m_AttIndex.isInRange(j)) {
newAtts.add(att);
} else {
Attribute newAtt = new Attribute(att.name(), (ArrayList<String>) null);
newAtt.setWeight(getInputFormat().attribute(j).weight());
newAtts.add(newAtt);
}
}
// Construct new header
newData = new Instances(getInputFormat().relationName(), newAtts, 0);
newData.setClassIndex(getInputFormat().classIndex());
setOutputFormat(newData);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase
public static List<String>
instanceHeaderToAttributeNameList(Instances header) {
List<String> attNames = new ArrayList<String>();
for (int i = 0; i < header.numAttributes(); i++) {
attNames.add(header.attribute(i).name());
}
return attNames;
}
内容来源于网络,如有侵权,请联系作者删除!