本文整理了Java中weka.filters.unsupervised.attribute.Add
类的一些代码示例,展示了Add
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Add
类的具体详情如下:
包路径:weka.filters.unsupervised.attribute.Add
类名称:Add
[英]An instance filter that adds a new attribute to the dataset. The new attribute will contain all missing values.
Valid options are:
-T <NUM|NOM|STR|DAT>
The type of attribute to create:
NUM = Numeric attribute
NOM = Nominal attribute
STR = String attribute
DAT = Date attribute
(default: NUM)
-C <index>
Specify where to insert the column. First and last
are valid indexes.(default: last)
-N <name>
Name of the new attribute.
(default: 'Unnamed')
-L <label1,label2,...>
Create nominal attribute with given labels
(default: numeric attribute)
-F <format>
The format of the date values (see ISO-8601)
(default: yyyy-MM-dd'T'HH:mm:ss)
-W <double>
The weight for the new attribute (default: 1.0)
[中]向数据集添加新属性的实例筛选器。新属性将包含所有缺少的值。
有效选项包括:
-T <NUM|NOM|STR|DAT>
The type of attribute to create:
NUM = Numeric attribute
NOM = Nominal attribute
STR = String attribute
DAT = Date attribute
(default: NUM)
-C <index>
Specify where to insert the column. First and last
are valid indexes.(default: last)
-N <name>
Name of the new attribute.
(default: 'Unnamed')
-L <label1,label2,...>
Create nominal attribute with given labels
(default: numeric attribute)
-F <format>
The format of the date values (see ISO-8601)
(default: yyyy-MM-dd'T'HH:mm:ss)
-W <double>
The weight for the new attribute (default: 1.0)
代码示例来源: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: stackoverflow.com
Add add = new Add();
if ( addWindow == false ) { //Thanks to @TofuBeer's comment. I didn't notice this at all.
add.setVisible(true);
}
else
add.setVisible(true);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Main method for testing this class.
*
* @param argv should contain arguments to the filter: use -h for help
*/
public static void main(String[] argv) {
runFilter(new Add(), argv);
}
}
代码示例来源:origin: stackoverflow.com
Add obj1 = new Add();
c = obj1.addfn(obj1.a,obj1.b);
return (c-d);
代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka
int numTrainLabels = trainData.classIndex();
int numTestLabels = testData.classIndex();
Add filter = new Add();
for (int i = 0; i < numTrainLabels; i++) {
filter.setAttributeIndex(Integer.toString(numTestLabels + i + 1));
filter.setNominalLabels("0,1");
filter.setAttributeName(trainData.attribute(i).name() + COMPATIBLE_OUTCOME_CLASS);
filter.setInputFormat(testData);
testData = Filter.useFilter(testData, filter);
代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka
Enumeration trainOutcomeValues = trainData.classAttribute().enumerateValues();
Enumeration testOutcomeValues = testData.classAttribute().enumerateValues();
List trainLabels = Collections.list(trainOutcomeValues);
List testLabels = Collections.list(testOutcomeValues);
Add addFilter = new Add();
addFilter.setNominalLabels(StringUtils.join(trainLabels, ','));
addFilter.setAttributeName(Constants.CLASS_ATTRIBUTE_NAME + COMPATIBLE_OUTCOME_CLASS);
addFilter.setInputFormat(testData);
testData = Filter.useFilter(testData, addFilter);
compTestData = new Instances(testData, testData.numInstances());
for (int i = 0; i < testData.numInstances(); i++) {
weka.core.Instance instance = testData.instance(i);
代码示例来源:origin: org.dkpro.tc/dkpro-tc-ml-weka
if (oldData.attribute(Constants.ID_FEATURE_NAME) != null) {
int instanceIdOffset = oldData.attribute(Constants.ID_FEATURE_NAME).index();
Add add = new Add();
add.setAttributeName(Constants.ID_FEATURE_NAME);
add.setAttributeIndex("last");
add.setAttributeIndex("first");
add.setAttributeType(new SelectedTag(Attribute.STRING, Add.TAGS_TYPE));
add.setInputFormat(newData);
filteredData = Filter.useFilter(newData, add);
int j = isMultilabel ? filteredData.numAttributes() - 1 : 0;
for (int i = 0; i < filteredData.numInstances(); i++) {
String outcomeId = oldData.instance(i).stringValue(instanceIdOffset);
代码示例来源:origin: net.sf.meka.thirdparty/mulan
Add add = new Add();
add.setAttributeIndex("first");
add.setAttributeName("instanceID");
add.setInputFormat(transformed);
transformed = Filter.useFilter(transformed, add);
for (int i=0; i<transformed.numInstances(); i++) {
transformed.instance(i).setValue(0, i);
transformed.setClassIndex(transformed.numAttributes()-1);
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.tc/de.tudarmstadt.ukp.dkpro.tc.weka-gpl
Instances randData = new Instances(data);
randData.randomize(new Random(new Date().getTime()));
randData.stratify(FOLDS);
Add filter = new Add();
for (int i = 0; i < numLabels; i++) {
filter.setAttributeIndex(new Integer(numLabels + i + 1).toString());
filter.setNominalLabels("0,1");
filter.setAttributeName(test.attribute(i).name() + "_classification");
filter.setInputFormat(test);
test = Filter.useFilter(test, filter);
weka.core.SerializationHelper.write(evalOutput.getAbsolutePath(), eval);
Add filter = new Add();
filter.setAttributeIndex(new Integer(test.classIndex() + 1).toString());
filter.setAttributeName("goldlabel");
filter.setInputFormat(test);
test = Filter.useFilter(test, filter);
代码示例来源: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: 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: nz.ac.waikato.cms.weka/weka-stable
return m_clusterInstances.toString();
tempNode.m_clusterInstances = new Instances(m_clusterInstances, 1);
for (int i = 0; i < m_children.size(); i++) {
tempNode.addChildNode(m_children.get(i));
tempNode = null;
Add af = new Add();
af.setAttributeName("Cluster");
String labels = "";
for (int i = 0; i < m_children.size(); i++) {
af.setNominalLabels(labels);
af.setInputFormat(tempInst);
tempInst = Filter.useFilter(tempInst, af);
tempInst.setRelationName("Cluster " + m_clusterNum);
代码示例来源: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: 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: nz.ac.waikato.cms.weka/weka-stable
setAttributeType(new SelectedTag(tmpStr, TAGS_TYPE));
} else {
setAttributeType(new SelectedTag(Attribute.NUMERIC, TAGS_TYPE));
tmpStr = "last";
setAttributeIndex(tmpStr);
setAttributeName(Utils.unbackQuoteChars(Utils.getOption('N', options)));
setNominalLabels(tmpStr);
setDateFormat(tmpStr);
setWeight(1.0);
} else {
setWeight(Double.parseDouble(tmpStr));
if (getInputFormat() != null) {
setInputFormat(getInputFormat());
代码示例来源:origin: stackoverflow.com
function Add(x) {
this.counter = x;
this.addOne = function() {
return this.counter += 1;
}
}
var add = new Add(0);
function myFunction() {
document.getElementById("demo").innerHTML = add.addOne();
}
代码示例来源: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: nz.ac.waikato.cms.moa/moa
tempNode = null;
Add af = new Add();
af.setAttributeName("Cluster");
String labels = "";
for (int i = 0; i < m_children.size(); i++) {
af.setNominalLabels(labels);
代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable
/**
* Input an instance for filtering. Ordinarily the instance is processed and
* made available for output immediately. Some filters require all instances
* be read before producing output.
*
* @param instance the input instance
* @return true if the filtered instance may now be collected with output().
* @throws IllegalStateException if no input format has been defined.
*/
@Override
public boolean input(Instance instance) {
if (getInputFormat() == null) {
throw new IllegalStateException("No input instance format defined");
}
if (m_NewBatch) {
resetQueue();
m_NewBatch = false;
}
Instance inst = (Instance) instance.copy();
// First copy string values from input to output
copyValues(inst, true, inst.dataset(), outputFormatPeek());
// Insert the new attribute and reassign to output
inst.setDataset(null);
inst.insertAttributeAt(m_Insert.getIndex());
push(inst); // No need to copy instance
return true;
}
代码示例来源:origin: stackoverflow.com
Add a = new Add();
mOut.print(a.toString(argumentOne, argumentTwo));
内容来源于网络,如有侵权,请联系作者删除!