本文整理汇总了Java中weka.filters.unsupervised.attribute.Remove.setInputFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Remove.setInputFormat方法的具体用法?Java Remove.setInputFormat怎么用?Java Remove.setInputFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weka.filters.unsupervised.attribute.Remove
的用法示例。
在下文中一共展示了Remove.setInputFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testScoreWithClassifierSomeMissingFields
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
@Test
public void testScoreWithClassifierSomeMissingFields() throws Exception {
Instances train = new Instances(new BufferedReader(new StringReader(
CorrelationMatrixMapTaskTest.IRIS)));
train.setClassIndex(train.numAttributes() - 1);
NaiveBayes bayes = new NaiveBayes();
bayes.buildClassifier(train);
WekaScoringMapTask task = new WekaScoringMapTask();
Remove r = new Remove();
r.setAttributeIndices("1");
r.setInputFormat(train);
Instances test = Filter.useFilter(train, r);
task.setModel(bayes, train, test);
assertTrue(task.getMissingMismatchAttributeInfo().length() > 0);
assertTrue(task.getMissingMismatchAttributeInfo().equals(
"sepallength missing from incoming data\n"));
assertEquals(3, task.getPredictionLabels().size());
for (int i = 0; i < test.numInstances(); i++) {
assertEquals(3, task.processInstance(test.instance(i)).length);
}
}
示例2: createFilter
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
public Filter createFilter(Instances data) throws Exception {
Set<Integer> indexes = new HashSet<Integer>();
for (int i = 0, cnt = this.size(); i < cnt; i++) {
indexes.add(this.get(i).index());
} // FOR
SortedSet<Integer> to_remove = new TreeSet<Integer>();
for (int i = 0, cnt = data.numAttributes(); i < cnt; i++) {
if (indexes.contains(i) == false) {
to_remove.add(i+1);
}
} // FOR
Remove filter = new Remove();
filter.setInputFormat(data);
String options[] = { "-R", StringUtil.join(",", to_remove) };
filter.setOptions(options);
return (filter);
}
示例3: buildClusteredSeries
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
private List<Series<Number, Number>> buildClusteredSeries() throws Exception {
List<XYChart.Series<Number, Number>> clusteredSeries = new ArrayList<>();
// to build the cluster we remove the class information
Remove remove = new Remove();
remove.setAttributeIndices("3");
remove.setInputFormat(data);
Instances dataToBeClustered = Filter.useFilter(data, remove);
SimpleKMeans kmeans = new SimpleKMeans();
kmeans.setSeed(10);
kmeans.setPreserveInstancesOrder(true);
kmeans.setNumClusters(3);
kmeans.buildClusterer(dataToBeClustered);
IntStream.range(0, 3).mapToObj(i -> {
Series<Number, Number> newSeries = new XYChart.Series<>();
newSeries.setName(String.valueOf(i));
return newSeries;
}).forEach(clusteredSeries::add);
int[] assignments = kmeans.getAssignments();
for (int i = 0; i < assignments.length; i++) {
int clusterNum = assignments[i];
clusteredSeries.get(clusterNum).getData().add(instancetoChartData(data.get(i)));
}
return clusteredSeries;
}
示例4: stripSummaryAtts
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Utility method that returns a header Instances object without any summary
* attributes.
*
* @param insts the header to remove summary attributes from
* @return a new Instances object that does not contain any summary attributes
* @throws DistributedWekaException if a problem occurs
*/
public static Instances stripSummaryAtts(Instances insts)
throws DistributedWekaException {
int startOfSummary = 0;
for (int i = 0; i < insts.numAttributes(); i++) {
if (insts.attribute(i).name()
.startsWith(CSVToARFFHeaderMapTask.ARFF_SUMMARY_ATTRIBUTE_PREFIX)) {
startOfSummary = i + 1;
break;
}
}
if (startOfSummary > 0) {
Remove r = new Remove();
r.setAttributeIndices("" + startOfSummary + "-" + "last");
try {
r.setInputFormat(insts);
insts = Filter.useFilter(insts, r);
} catch (Exception ex) {
throw new DistributedWekaException(ex);
}
}
return insts;
}
示例5: removeClass
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
private Instances removeClass(Instances inst) {
Remove af = new Remove();
Instances retI = null;
try {
if (inst.classIndex() < 0) {
retI = inst;
} else {
af.setAttributeIndices("" + (inst.classIndex() + 1));
af.setInvertSelection(false);
af.setInputFormat(inst);
retI = Filter.useFilter(inst, af);
}
} catch (Exception e) {
e.printStackTrace();
}
return retI;
}
示例6: removeIgnoreCols
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
private Instances removeIgnoreCols(Instances inst) {
// If the user is doing classes to clusters evaluation and
// they have opted to ignore the class, then unselect the class in
// the ignore list
if (m_ClassesToClustersBut.isSelected()) {
int classIndex = m_ClassCombo.getSelectedIndex();
if (m_ignoreKeyList.isSelectedIndex(classIndex)) {
m_ignoreKeyList.removeSelectionInterval(classIndex, classIndex);
}
}
int[] selected = m_ignoreKeyList.getSelectedIndices();
Remove af = new Remove();
Instances retI = null;
try {
af.setAttributeIndicesArray(selected);
af.setInvertSelection(false);
af.setInputFormat(inst);
retI = Filter.useFilter(inst, af);
} catch (Exception e) {
e.printStackTrace();
}
return retI;
}
示例7: setUp
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
protected void setUp() throws Exception {
super.setUp();
Instances temp = new Instances(m_Instances);
for (int j = 0; j < 2; j++) {
for (int i = 0; i < temp.numInstances(); i++) {
m_Instances.add(temp.instance(i));
}
}
// now just filter the instances to convert String attributes
// and binarize nominal attributes
StringToNominal stn = new StringToNominal();
stn.setAttributeRange("first-last");
stn.setInputFormat(m_Instances);
m_Instances = Filter.useFilter(m_Instances, stn);
NominalToBinary ntb = new NominalToBinary();
ntb.setInputFormat(m_Instances);
m_Instances = Filter.useFilter(m_Instances, ntb);
// remove the last column (date attribute)
Remove r = new Remove();
r.setAttributeIndices("last");
r.setInputFormat(m_Instances);
m_Instances = Filter.useFilter(m_Instances, r);
}
示例8: removeLabels
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Remove Indices - Remove ALL labels (assume they are the first L attributes) from D.
* @param D Dataset
* @param L number of labels
* @return New dataset with labels removed.
*/
public static Instances removeLabels(Instances D, int L) throws Exception {
Remove remove = new Remove();
remove.setAttributeIndices("1-"+L);
remove.setInputFormat(D);
return Filter.useFilter(D, remove);
}
示例9: setAttributesToIgnore
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Sets up a Remove filter to remove attributes that
* are to be ignored by the clusterer. setHeader must
* be called before this method.
*
* @param attsToIgnore any attributes to ignore during the scoring process
*/
public void setAttributesToIgnore(int[] attsToIgnore) throws Exception {
Instances headerI = getHeader();
m_ignoredAtts = new Remove();
m_ignoredAtts.setAttributeIndicesArray(attsToIgnore);
m_ignoredAtts.setInvertSelection(false);
m_ignoredAtts.setInputFormat(headerI);
StringBuffer temp = new StringBuffer();
temp.append("Attributes ignored by clusterer:\n\n");
for (int i = 0; i < attsToIgnore.length; i++) {
temp.append(headerI.attribute(attsToIgnore[i]).name() + "\n");
}
temp.append("\n\n");
m_ignoredString = temp.toString();
}
示例10: removeFirstAttribute
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
private Instances removeFirstAttribute(Instances inst) {
String[] options = new String[2];
// "range"
options[0] = "-R";
// first attribute
options[1] = "1";
// new instance of filter
Remove remove = new Remove();
// set options
try {
remove.setOptions(options);
// inform filter about dataset **AFTER** setting options
remove.setInputFormat(inst);
// apply filter
return Filter.useFilter(inst, remove);
} catch (Exception e) {
System.err.println("Can't remove first attribute.");
return null;
}
}
示例11: generateClassToCluster
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
public void generateClassToCluster(){
Remove filter = new Remove();
filter.setAttributeIndices("" + (weather.classIndex() + 1));
try {
filter.setInputFormat(weather);
Instances dataClusterer = Filter.useFilter(weather, filter);
clusterer = new EM();
clusterer.buildClusterer(dataClusterer);
ClusterEvaluation eval = new ClusterEvaluation();
eval.setClusterer(clusterer);
eval.evaluateClusterer(weather);
System.out.println(eval.clusterResultsToString());
} catch (Exception e) {
}
}
示例12: buildLinearModel
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Build a linear model for this node using those attributes specified in
* indices.
*
* @param indices an array of attribute indices to include in the linear model
* @throws Exception if something goes wrong
*/
private void buildLinearModel(int[] indices) throws Exception {
// copy the training instances and remove all but the tested
// attributes
Instances reducedInst = new Instances(m_instances);
Remove attributeFilter = new Remove();
attributeFilter.setInvertSelection(true);
attributeFilter.setAttributeIndicesArray(indices);
attributeFilter.setInputFormat(reducedInst);
reducedInst = Filter.useFilter(reducedInst, attributeFilter);
// build a linear regression for the training data using the
// tested attributes
LinearRegression temp = new LinearRegression();
temp.buildClassifier(reducedInst);
double[] lmCoeffs = temp.coefficients();
double[] coeffs = new double[m_instances.numAttributes()];
for (int i = 0; i < lmCoeffs.length - 1; i++) {
if (indices[i] != m_classIndex) {
coeffs[indices[i]] = lmCoeffs[i];
}
}
m_nodeModel = new PreConstructedLinearModel(coeffs,
lmCoeffs[lmCoeffs.length - 1]);
m_nodeModel.buildClassifier(m_instances);
}
示例13: buildClusterer
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Builds the clusters
*/
private void buildClusterer() throws Exception {
if (m_trainingSet.classIndex() < 0) {
m_Clusterer.buildClusterer(m_trainingSet);
} else { // class based evaluation if class attribute is set
Remove removeClass = new Remove();
removeClass.setAttributeIndices("" + (m_trainingSet.classIndex() + 1));
removeClass.setInvertSelection(false);
removeClass.setInputFormat(m_trainingSet);
Instances clusterTrain = Filter.useFilter(m_trainingSet, removeClass);
m_Clusterer.buildClusterer(clusterTrain);
}
}
示例14: applyRemoveFilter
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
/**
* Remove desired attribute from Weka data
* @param data weka data from which attribute is to be removed
* @param attriId ID in Weka of attribute to be removed
* @return data after desired attribute is removed
* @throws Exception
*/
private static Instances applyRemoveFilter(Instances data, String attriId) throws Exception {
Remove keepAttributes = new Remove();
keepAttributes.setAttributeIndices(attriId+ ","+ Integer.toString(data.numAttributes() - 1) + ",last");
keepAttributes.setInvertSelection(true);
keepAttributes.setInputFormat(data);
data = Filter.useFilter(data, keepAttributes);
System.out.println("RemoveFilter applied.");
return data;
}
示例15: dropClass
import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
private Instances dropClass(Instances instances) throws Exception {
if (instances.classIndex() == -1) {
return instances;
}
Remove removeFilter = new Remove();
String[] options = new String[2];
options[0] = "-R";
options[1] = Integer.toString(instances.classIndex());
removeFilter.setOptions(options);
removeFilter.setInputFormat(instances);
return Filter.useFilter(instances, removeFilter);
}