weka.filters.unsupervised.attribute.Add.setAttributeIndex()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中weka.filters.unsupervised.attribute.Add.setAttributeIndex()方法的一些代码示例,展示了Add.setAttributeIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Add.setAttributeIndex()方法的具体详情如下:
包路径:weka.filters.unsupervised.attribute.Add
类名称:Add
方法名:setAttributeIndex

Add.setAttributeIndex介绍

[英]Sets index of the attribute used.
[中]设置所用属性的索引。

代码示例

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/** Creates a specialized Add */
public Filter getFilter(int pos) {
 Add af = new Add();
 af.setAttributeIndex("" + (pos + 1));
 return af;
}

代码示例来源:origin: Waikato/weka-trunk

/** Creates a specialized Add */
public Filter getFilter(int pos) {
 Add af = new Add();
 af.setAttributeIndex("" + (pos + 1));
 return af;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

private Instances makeClusterDataSetClass(Instances format,
 weka.clusterers.Clusterer clusterer, String relationNameModifier)
 throws Exception {
 weka.filters.unsupervised.attribute.Add addF =
  new weka.filters.unsupervised.attribute.Add();
 addF.setAttributeIndex("last");
 String clustererName = clusterer.getClass().getName();
 clustererName =
  clustererName.substring(clustererName.lastIndexOf('.') + 1,
   clustererName.length());
 addF.setAttributeName("assigned_cluster: " + clustererName);
 // if (format.classAttribute().isNominal()) {
 String clusterLabels = "0";
 /*
  * Enumeration enu = format.classAttribute().enumerateValues();
  * clusterLabels += (String)enu.nextElement(); while (enu.hasMoreElements())
  * { clusterLabels += ","+(String)enu.nextElement(); }
  */
 for (int i = 1; i <= clusterer.numberOfClusters() - 1; i++) {
  clusterLabels += "," + i;
 }
 addF.setNominalLabels(clusterLabels);
 // }
 addF.setInputFormat(format);
 Instances newInstances = weka.filters.Filter.useFilter(format, addF);
 newInstances.setRelationName(format.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: Waikato/weka-trunk

private Instances makeClusterDataSetClass(Instances format,
 weka.clusterers.Clusterer clusterer, String relationNameModifier)
 throws Exception {
 weka.filters.unsupervised.attribute.Add addF =
  new weka.filters.unsupervised.attribute.Add();
 addF.setAttributeIndex("last");
 String clustererName = clusterer.getClass().getName();
 clustererName =
  clustererName.substring(clustererName.lastIndexOf('.') + 1,
   clustererName.length());
 addF.setAttributeName("assigned_cluster: " + clustererName);
 // if (format.classAttribute().isNominal()) {
 String clusterLabels = "0";
 /*
  * Enumeration enu = format.classAttribute().enumerateValues();
  * clusterLabels += (String)enu.nextElement(); while (enu.hasMoreElements())
  * { clusterLabels += ","+(String)enu.nextElement(); }
  */
 for (int i = 1; i <= clusterer.numberOfClusters() - 1; i++) {
  clusterLabels += "," + i;
 }
 addF.setNominalLabels(clusterLabels);
 // }
 addF.setInputFormat(format);
 Instances newInstances = weka.filters.Filter.useFilter(format, addF);
 newInstances.setRelationName(format.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: Waikato/weka-trunk

addF.setAttributeIndex("last");
String classifierName = classifier.getClass().getName();
classifierName =

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

addF.setAttributeIndex("last");
String classifierName = classifier.getClass().getName();
classifierName =

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

private Instances makeDataSetProbabilities(Instances insts, Instances format,
 weka.classifiers.Classifier classifier, String relationNameModifier)
 throws Exception {
 // adjust structure for InputMappedClassifier (if necessary)
 if (classifier instanceof weka.classifiers.misc.InputMappedClassifier) {
  format =
   ((weka.classifiers.misc.InputMappedClassifier) classifier)
    .getModelHeader(new Instances(format, 0));
 }
 String classifierName = classifier.getClass().getName();
 classifierName =
  classifierName.substring(classifierName.lastIndexOf('.') + 1,
   classifierName.length());
 Instances newInstances = new Instances(insts);
 for (int i = 0; i < format.classAttribute().numValues(); i++) {
  weka.filters.unsupervised.attribute.Add addF =
   new weka.filters.unsupervised.attribute.Add();
  addF.setAttributeIndex("last");
  addF.setAttributeName(classifierName + "_prob_"
   + format.classAttribute().value(i));
  addF.setInputFormat(newInstances);
  newInstances = weka.filters.Filter.useFilter(newInstances, addF);
 }
 newInstances.setRelationName(insts.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka

private Instances getPredictionInstancesMultiLabel(Instances testData, Classifier cl,
    double[] thresholdArray)
  throws Exception
{
  int numLabels = testData.classIndex();
  // get predictions
  List<double[]> labelPredictionList = new ArrayList<double[]>();
  for (int i = 0; i < testData.numInstances(); i++) {
    labelPredictionList.add(cl.distributionForInstance(testData.instance(i)));
  }
  // add attributes to store predictions in test data
  Add filter = new Add();
  for (int i = 0; i < numLabels; i++) {
    filter.setAttributeIndex(Integer.toString(numLabels + i + 1));
    filter.setNominalLabels("0,1");
    filter.setAttributeName(
        testData.attribute(i).name() + "_" + WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
    filter.setInputFormat(testData);
    testData = Filter.useFilter(testData, filter);
  }
  // fill predicted values for each instance
  for (int i = 0; i < labelPredictionList.size(); i++) {
    for (int j = 0; j < labelPredictionList.get(i).length; j++) {
      testData.instance(i).setValue(j + numLabels,
          labelPredictionList.get(i)[j] >= thresholdArray[j] ? 1. : 0.);
    }
  }
  return testData;
}

代码示例来源:origin: dkpro/dkpro-tc

private Instances getPredictionInstancesMultiLabel(Instances testData, Classifier cl,
    double[] thresholdArray)
  throws Exception
{
  int numLabels = testData.classIndex();
  // get predictions
  List<double[]> labelPredictionList = new ArrayList<double[]>();
  for (int i = 0; i < testData.numInstances(); i++) {
    labelPredictionList.add(cl.distributionForInstance(testData.instance(i)));
  }
  // add attributes to store predictions in test data
  Add filter = new Add();
  for (int i = 0; i < numLabels; i++) {
    filter.setAttributeIndex(Integer.toString(numLabels + i + 1));
    filter.setNominalLabels("0,1");
    filter.setAttributeName(
        testData.attribute(i).name() + "_" + WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
    filter.setInputFormat(testData);
    testData = Filter.useFilter(testData, filter);
  }
  // fill predicted values for each instance
  for (int i = 0; i < labelPredictionList.size(); i++) {
    for (int j = 0; j < labelPredictionList.get(i).length; j++) {
      testData.instance(i).setValue(j + numLabels,
          labelPredictionList.get(i)[j] >= thresholdArray[j] ? 1. : 0.);
    }
  }
  return testData;
}

代码示例来源:origin: Waikato/weka-trunk

private Instances makeDataSetProbabilities(Instances insts, Instances format,
 weka.classifiers.Classifier classifier, String relationNameModifier)
 throws Exception {
 // adjust structure for InputMappedClassifier (if necessary)
 if (classifier instanceof weka.classifiers.misc.InputMappedClassifier) {
  format =
   ((weka.classifiers.misc.InputMappedClassifier) classifier)
    .getModelHeader(new Instances(format, 0));
 }
 String classifierName = classifier.getClass().getName();
 classifierName =
  classifierName.substring(classifierName.lastIndexOf('.') + 1,
   classifierName.length());
 Instances newInstances = new Instances(insts);
 for (int i = 0; i < format.classAttribute().numValues(); i++) {
  weka.filters.unsupervised.attribute.Add addF =
   new weka.filters.unsupervised.attribute.Add();
  addF.setAttributeIndex("last");
  addF.setAttributeName(classifierName + "_prob_"
   + format.classAttribute().value(i));
  addF.setInputFormat(newInstances);
  newInstances = weka.filters.Filter.useFilter(newInstances, addF);
 }
 newInstances.setRelationName(insts.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

private Instances makeClusterDataSetProbabilities(Instances format,
 weka.clusterers.Clusterer clusterer, String relationNameModifier)
 throws Exception {
 Instances newInstances = new Instances(format);
 for (int i = 0; i < clusterer.numberOfClusters(); i++) {
  weka.filters.unsupervised.attribute.Add addF =
   new weka.filters.unsupervised.attribute.Add();
  addF.setAttributeIndex("last");
  addF.setAttributeName("prob_cluster" + i);
  addF.setInputFormat(newInstances);
  newInstances = weka.filters.Filter.useFilter(newInstances, addF);
 }
 newInstances.setRelationName(format.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: net.sf.meka.thirdparty/mulan

/**
 * Constructor
 *
 * @param data a multi-label dataset
 */
public BinaryRelevanceTransformation(MultiLabelInstances data) {
  try {
    this.data = data;
    remove = new Remove();
    int[] labelIndices = data.getLabelIndices();
    int[] indices = new int[labelIndices.length];
    System.arraycopy(labelIndices, 0, indices, 0, labelIndices.length);
    remove.setAttributeIndicesArray(indices);
    remove.setInvertSelection(false);
    remove.setInputFormat(data.getDataSet());
    shell = Filter.useFilter(data.getDataSet(), remove);
    add = new Add();
    add.setAttributeIndex("last");
    add.setNominalLabels("0,1");
    add.setAttributeName("BinaryRelevanceLabel");
    add.setInputFormat(shell);
    shell = Filter.useFilter(shell, add);
    shell.setClassIndex(shell.numAttributes() - 1);
  } catch (Exception ex) {
    Logger.getLogger(BinaryRelevanceTransformation.class.getName()).log(Level.SEVERE, null, ex);
  }
}

代码示例来源:origin: Waikato/weka-trunk

private Instances makeClusterDataSetProbabilities(Instances format,
 weka.clusterers.Clusterer clusterer, String relationNameModifier)
 throws Exception {
 Instances newInstances = new Instances(format);
 for (int i = 0; i < clusterer.numberOfClusters(); i++) {
  weka.filters.unsupervised.attribute.Add addF =
   new weka.filters.unsupervised.attribute.Add();
  addF.setAttributeIndex("last");
  addF.setAttributeName("prob_cluster" + i);
  addF.setInputFormat(newInstances);
  newInstances = weka.filters.Filter.useFilter(newInstances, addF);
 }
 newInstances.setRelationName(format.relationName() + relationNameModifier);
 return newInstances;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Adds an instance number attribute to the plottable instances,
 */
public void addInstanceNumberAttribute() {
 String originalRelationName = m_plotInstances.relationName();
 int originalClassIndex = m_plotInstances.classIndex();
 try {
  Add addF = new Add();
  addF.setAttributeName("Instance_number");
  addF.setAttributeIndex("first");
  addF.setInputFormat(m_plotInstances);
  m_plotInstances = Filter.useFilter(m_plotInstances, addF);
  m_plotInstances.setClassIndex(originalClassIndex + 1);
  for (int i = 0; i < m_plotInstances.numInstances(); i++) {
   m_plotInstances.instance(i).setValue(0, i);
  }
  m_plotInstances.setRelationName(originalRelationName);
 } catch (Exception ex) {
  ex.printStackTrace();
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Adds an instance number attribute to the plottable instances,
 */
public void addInstanceNumberAttribute() {
 String originalRelationName = m_plotInstances.relationName();
 int originalClassIndex = m_plotInstances.classIndex();
 try {
  Add addF = new Add();
  addF.setAttributeName("Instance_number");
  addF.setAttributeIndex("first");
  addF.setInputFormat(m_plotInstances);
  m_plotInstances = Filter.useFilter(m_plotInstances, addF);
  m_plotInstances.setClassIndex(originalClassIndex + 1);
  for (int i = 0; i < m_plotInstances.numInstances(); i++) {
   m_plotInstances.instance(i).setValue(0, i);
  }
  m_plotInstances.setRelationName(originalRelationName);
 } catch (Exception ex) {
  ex.printStackTrace();
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/** Creates a configured MultiFilter */
public Filter getConfiguredFilter() {
 MultiFilter result = new MultiFilter();
 
 Filter[] filters = new Filter[2];
 filters[0] = new Add();
 ((Add) filters[0]).setAttributeIndex("last");
 filters[1] = new AddExpression();
 ((AddExpression) filters[1]).setExpression("a3+a6");
 
 result.setFilters(filters);
 
 return result;
}

代码示例来源:origin: Waikato/weka-trunk

/** Creates a configured MultiFilter */
public Filter getConfiguredFilter() {
 MultiFilter result = new MultiFilter();
 
 Filter[] filters = new Filter[2];
 filters[0] = new Add();
 ((Add) filters[0]).setAttributeIndex("last");
 filters[1] = new AddExpression();
 ((AddExpression) filters[1]).setExpression("a3+a6");
 
 result.setFilters(filters);
 
 return result;
}

代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka

add.setAttributeIndex("last");
add.setAttributeIndex("first");

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl

add.setAttributeIndex("last");
add.setAttributeIndex("first");

代码示例来源:origin: net.sf.meka.thirdparty/mulan

add.setAttributeIndex("first");
add.setAttributeName("instanceID");
add.setInputFormat(transformed);

相关文章