weka.core.Instances.setRelationName()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.2k)|赞(0)|评价(0)|浏览(104)

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

Instances.setRelationName介绍

[英]Sets the relation's name.
[中]设置关系的名称。

代码示例

代码示例来源:origin: com.googlecode.obvious/obviousx-weka

@Override
public void setRelationName(String newName) {
 super.setRelationName(newName);
}

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

/**
 * Apply the change to the relation name in the given Instances object
 *
 * @param insts the Instances object to operate on
 */
protected void applyRelationNameChange(Instances insts) {
 switch (m_modType) {
 case REPLACE:
  insts.setRelationName(m_relationNameModText);
  break;
 case APPEND:
  insts.setRelationName(insts.relationName() + m_relationNameModText);
  break;
 case PREPEND:
  insts.setRelationName(m_relationNameModText + insts.relationName());
  break;
 case REGEX:
  String rel = insts.relationName();
  if (m_replaceAll) {
   rel = m_regexPattern.matcher(rel).replaceAll(m_relationNameModText);
  } else {
   rel = m_regexPattern.matcher(rel).replaceFirst(m_relationNameModText);
  }
  insts.setRelationName(rel);
  break;
 }
}

代码示例来源:origin: Waikato/meka

/**
 * Fixes the relation name by adding the "-C" attribute to it if necessary.
 *
 * @param data the dataset to fix
 * @param numClassAtts the number of class attributes (0 for none, >0 for attributes at start, <0 for attributes at end)
 */
public static void fixRelationName(Instances data, int numClassAtts) {
  if (data.relationName().indexOf(":") == -1)
    data.setRelationName(data.relationName() + ": -C " + numClassAtts);
}

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

/**
 * Fixes the relation name by adding the "-C" attribute to it if necessary.
 *
 * @param data the dataset to fix
 * @param numClassAtts the number of class attributes (0 for none, >0 for attributes at start, <0 for attributes at end)
 */
public static void fixRelationName(Instances data, int numClassAtts) {
  if (data.relationName().indexOf(":") == -1)
    data.setRelationName(data.relationName() + ": -C " + numClassAtts);
}

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

/**
 * Sets the format of output instances. The derived class should use this
 * method once it has determined the outputformat. The output queue is
 * cleared.
 *
 * @param outputFormat the new output format
 */
protected void setOutputFormat(Instances outputFormat) {
 if (outputFormat != null) {
  m_OutputFormat = outputFormat.stringFreeStructure();
  initOutputLocators(m_OutputFormat, null);
  // Rename the relation
  String relationName =
   outputFormat.relationName() + "-" + this.getClass().getName();
  if (this instanceof OptionHandler) {
   String[] options = ((OptionHandler) this).getOptions();
   for (String option : options) {
    relationName += option.trim();
   }
  }
  m_OutputFormat.setRelationName(relationName);
 } else {
  m_OutputFormat = null;
 }
 m_OutputQueue = new Queue();
}

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

@Override
 public void run() {
try {
 String relName = getData().relationName();
 filter.setInputFormat(getData());
 Instances filtered = Filter.useFilter(getData(), filter);
 if (newName == null)
  filtered.setRelationName(relName);
 else
  filtered.setRelationName(newName);
 getOwner().notifyTabsDataChanged(PreprocessTab.this, filtered);
 setData(filtered);
}
catch (Exception e) {
 throw new IllegalStateException(e);
}
 }
};

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

@Override
  public void run() {
    try {
      String relName = getData().relationName();
      filter.setInputFormat(getData());
      Instances filtered = Filter.useFilter(getData(), filter);
      if (newName == null)
        filtered.setRelationName(relName);
      else
        filtered.setRelationName(newName);
      getOwner().notifyTabsDataChanged(PreprocessTab.this, filtered);
      setData(filtered);
      log("Data filtered successfully!");
    }
    catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
};

代码示例来源:origin: Waikato/meka

@Override
  public void run() {
    try {
      String relName = getData().relationName();
      filter.setInputFormat(getData());
      Instances filtered = Filter.useFilter(getData(), filter);
      if (newName == null)
        filtered.setRelationName(relName);
      else
        filtered.setRelationName(newName);
      getOwner().notifyTabsDataChanged(PreprocessTab.this, filtered);
      setData(filtered);
      log("Data filtered successfully!");
    }
    catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
};

代码示例来源: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: stackoverflow.com

Instances data = null;
 try {
   DatabaseUtils utils = new DatabaseUtils();
   InstanceQuery query = new InstanceQuery();
   query.setUsername(username);
   query.setPassword(password);
   query.setQuery(pSql);
   data = query.retrieveInstances();
   data.setRelationName(pInstanceRelationName);
   if (data.classIndex() == -1)
   {
      data.setClassIndex(data.numAttributes() - 1);
   }
         // this line will print out your header + data. 
         // add your header information to your question.
   System.out.println(data)
 } 
   catch (Exception e) {
   throw new RuntimeException(e);
 }

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

for (int i = 0; i < classes.length; i++) {
 classes[i] = new Instances(insts, 0);
 classes[i].setRelationName(insts.attribute(classIndex).value(i));

代码示例来源: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: 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: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl

/**
   * Applies a filter to reduce the dimension of attributes and reorders them to be used within
   * Meka
   * 
   * @param trainData
   * @param removeFilter
   * @return a dataset to be used with Meka
   * @throws Exception
   */
  public static Instances applyAttributeSelectionFilter(Instances trainData, Remove removeFilter)
    throws Exception
  {
    Instances filtered = Filter.useFilter(trainData, removeFilter);
    filtered.setClassIndex(trainData.classIndex());
    // swap attributes to fit MEKA
    MekaClassAttributes attFilter = new MekaClassAttributes();
    attFilter.setAttributeIndices(filtered.numAttributes() - trainData.classIndex() + 1
        + "-last");
    attFilter.setInputFormat(filtered);
    filtered = Filter.useFilter(filtered, attFilter);
    int newClassindex = filtered.classIndex();
    filtered.setRelationName(filtered.relationName().replaceAll("\\-C\\s[\\d]+",
        "-C " + newClassindex));

    return filtered;
  }
}

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

/**
 * Initializes the format for the dataset produced. Must be called before the
 * generateExample or generateExamples methods are used. Re-initializes the
 * random number generator with the given seed.
 * 
 * @return the format for the dataset
 * @throws Exception if the generating of the format failed
 * @see #getSeed()
 */
@Override
public Instances defineDataFormat() throws Exception {
 BayesNetGenerator bng;
 bng = new BayesNetGenerator();
 bng.setOptions(getGenerator().getOptions());
 setGeneratorOption(bng, "M", "1");
 bng.generateRandomNetwork();
 bng.generateInstances();
 bng.m_Instances.renameAttribute(0, "class");
 bng.m_Instances.setRelationName(getRelationNameToUse());
 return bng.m_Instances;
}

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

/**
 * Initializes the format for the dataset produced. Must be called before the
 * generateExample or generateExamples methods are used. Re-initializes the
 * random number generator with the given seed.
 * 
 * @return the format for the dataset
 * @throws Exception if the generating of the format failed
 * @see #getSeed()
 */
@Override
public Instances defineDataFormat() throws Exception {
 BayesNetGenerator bng;
 bng = new BayesNetGenerator();
 bng.setOptions(getGenerator().getOptions());
 setGeneratorOption(bng, "M", "1");
 bng.generateRandomNetwork();
 bng.generateInstances();
 bng.m_Instances.renameAttribute(0, "class");
 bng.m_Instances.setRelationName(getRelationNameToUse());
 return bng.m_Instances;
}

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

/**
 * Generates all examples of the dataset. Re-initializes the random number
 * generator with the given seed, before generating instances.
 * 
 * @return the generated dataset
 * @throws Exception if the format of the dataset is not yet defined
 * @throws Exception if the generator only works with generateExample, which
 *           means in single mode
 * @see #getSeed()
 */
@Override
public Instances generateExamples() throws Exception {
 getGenerator().setOptions(getGenerator().getOptions());
 getGenerator().generateRandomNetwork();
 getGenerator().generateInstances();
 getGenerator().m_Instances.renameAttribute(0, "class");
 getGenerator().m_Instances.setRelationName(getRelationNameToUse());
 return getGenerator().m_Instances;
}

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

/**
 * Generates all examples of the dataset. Re-initializes the random number
 * generator with the given seed, before generating instances.
 * 
 * @return the generated dataset
 * @throws Exception if the format of the dataset is not yet defined
 * @throws Exception if the generator only works with generateExample, which
 *           means in single mode
 * @see #getSeed()
 */
@Override
public Instances generateExamples() throws Exception {
 getGenerator().setOptions(getGenerator().getOptions());
 getGenerator().generateRandomNetwork();
 getGenerator().generateInstances();
 getGenerator().m_Instances.renameAttribute(0, "class");
 getGenerator().m_Instances.setRelationName(getRelationNameToUse());
 return getGenerator().m_Instances;
}

相关文章

Instances类方法