本文整理了Java中weka.filters.unsupervised.attribute.Add.setNominalLabels()
方法的一些代码示例,展示了Add.setNominalLabels()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Add.setNominalLabels()
方法的具体详情如下:
包路径:weka.filters.unsupervised.attribute.Add
类名称:Add
方法名:setNominalLabels
[英]Set the labels for nominal attribute creation.
[中]设置用于创建标称属性的标签。
代码示例来源: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: 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
classLabels += "," + (String) enu.nextElement();
addF.setNominalLabels(classLabels);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
classLabels += "," + (String) enu.nextElement();
addF.setNominalLabels(classLabels);
代码示例来源:origin: dkpro/dkpro-tc
public Instances getPredictionInstancesSingleLabel(Instances testData, Classifier cl)
throws Exception
{
StringBuffer classVals = new StringBuffer();
for (int i = 0; i < testData.classAttribute().numValues(); i++) {
if (classVals.length() > 0) {
classVals.append(",");
}
classVals.append(testData.classAttribute().value(i));
}
// get predictions
List<Double> labelPredictionList = new ArrayList<Double>();
for (int i = 0; i < testData.size(); i++) {
labelPredictionList.add(cl.classifyInstance(testData.instance(i)));
}
// add an attribute with the predicted values at the end off the attributes
Add filter = new Add();
filter.setAttributeName(WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
if (classVals.length() > 0) {
filter.setAttributeType(new SelectedTag(Attribute.NOMINAL, Add.TAGS_TYPE));
filter.setNominalLabels(classVals.toString());
}
filter.setInputFormat(testData);
testData = Filter.useFilter(testData, filter);
// fill predicted values for each instance
for (int i = 0; i < labelPredictionList.size(); i++) {
testData.instance(i).setValue(testData.classIndex() + 1, labelPredictionList.get(i));
}
return testData;
}
代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka
public Instances getPredictionInstancesSingleLabel(Instances testData, Classifier cl)
throws Exception
{
StringBuffer classVals = new StringBuffer();
for (int i = 0; i < testData.classAttribute().numValues(); i++) {
if (classVals.length() > 0) {
classVals.append(",");
}
classVals.append(testData.classAttribute().value(i));
}
// get predictions
List<Double> labelPredictionList = new ArrayList<Double>();
for (int i = 0; i < testData.size(); i++) {
labelPredictionList.add(cl.classifyInstance(testData.instance(i)));
}
// add an attribute with the predicted values at the end off the attributes
Add filter = new Add();
filter.setAttributeName(WekaTestTask.PREDICTION_CLASS_LABEL_NAME);
if (classVals.length() > 0) {
filter.setAttributeType(new SelectedTag(Attribute.NOMINAL, Add.TAGS_TYPE));
filter.setNominalLabels(classVals.toString());
}
filter.setInputFormat(testData);
testData = Filter.useFilter(testData, filter);
// fill predicted values for each instance
for (int i = 0; i < labelPredictionList.size(); i++) {
testData.instance(i).setValue(testData.classIndex() + 1, labelPredictionList.get(i));
}
return testData;
}
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl
if (classVals.length() > 0) {
filter.setAttributeType(new SelectedTag(Attribute.NOMINAL, Add.TAGS_TYPE));
filter.setNominalLabels(classVals.toString());
代码示例来源: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: 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: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl
for (int i = 0; i < numLabels; i++) {
filter.setAttributeIndex(new Integer(numLabels + i + 1).toString());
filter.setNominalLabels("0,1");
filter.setAttributeName(testData.attribute(i).name() + "_"
+ TestTask.PREDICTION_CLASS_LABEL_NAME);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
public void testAddNominal() {
m_Filter = getFilter();
((Add)m_Filter).setNominalLabels("hello,there,bob");
testBuffered();
testType(Attribute.NOMINAL);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
af.setNominalLabels(labels);
af.setInputFormat(tempInst);
tempInst = Filter.useFilter(tempInst, af);
代码示例来源:origin: Waikato/weka-trunk
public void testAddNominal() {
m_Filter = getFilter();
((Add)m_Filter).setNominalLabels("hello,there,bob");
testBuffered();
testType(Attribute.NOMINAL);
}
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
clusterLabels += "," + i;
addF.setNominalLabels(clusterLabels);
addF.setInputFormat(newData);
newData = weka.filters.Filter.useFilter(newData, addF);
代码示例来源: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
clusterLabels += "," + i;
addF.setNominalLabels(clusterLabels);
addF.setInputFormat(newData);
newData = weka.filters.Filter.useFilter(newData, addF);
代码示例来源:origin: Waikato/weka-trunk
classLabels += "," + classAttribute.value(i);
addF.setNominalLabels(classLabels);
代码示例来源:origin: dkpro/dkpro-tc
addFilter.setNominalLabels(StringUtils.join(trainLabels, ','));
addFilter.setAttributeName(Constants.CLASS_ATTRIBUTE_NAME + COMPATIBLE_OUTCOME_CLASS);
addFilter.setInputFormat(testData);
代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka
addFilter.setNominalLabels(StringUtils.join(trainLabels, ','));
addFilter.setAttributeName(Constants.CLASS_ATTRIBUTE_NAME + COMPATIBLE_OUTCOME_CLASS);
addFilter.setInputFormat(testData);
代码示例来源:origin: nz.ac.waikato.cms.moa/moa
af.setNominalLabels(labels);
内容来源于网络,如有侵权,请联系作者删除!