当前位置: 首页>>代码示例>>Java>>正文


Java Remove类代码示例

本文整理汇总了Java中weka.filters.unsupervised.attribute.Remove的典型用法代码示例。如果您正苦于以下问题:Java Remove类的具体用法?Java Remove怎么用?Java Remove使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Remove类属于weka.filters.unsupervised.attribute包,在下文中一共展示了Remove类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildFilteredClassifier

import weka.filters.unsupervised.attribute.Remove; //导入依赖的package包/类
public void buildFilteredClassifier(){
	rf = new RandomForest();
	Remove rm = new Remove();
	rm.setAttributeIndices("1");
	FilteredClassifier fc = new FilteredClassifier();
	fc.setFilter(rm);
	fc.setClassifier(rf);
	try{
		fc.buildClassifier(weather);
		for (int i = 0; i < weather.numInstances(); i++){
			double pred = fc.classifyInstance(weather.instance(i));
			System.out.print("given value: " + weather.classAttribute().value((int) weather.instance(i).classValue()));
			System.out.println("---predicted value: " + weather.classAttribute().value((int) pred));
		}
	} catch (Exception e) {
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:18,代码来源:WekaFilteredClassifierTest.java

示例2: 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);
  }
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:28,代码来源:WekaScoringTaskTest.java

示例3: classify

import weka.filters.unsupervised.attribute.Remove; //导入依赖的package包/类
/**
 * Classifies function wise test instances in the associated with the names labels mentioned in the arraylist passed as the argument.
 *
 * @param list - labels of instances contained in the test set that need to be classified.
 * @return TreeMap containing the instance labels and the associated classification results.
 * @throws ClassificationFailedException
 */
@Override
public LinkedHashMap<String, String> classify(LinkedList<String> list) throws ClassificationFailedException {
    output = new LinkedHashMap<String, String>();
    J48 j48 = new J48();
    Remove rm = new Remove();
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);
        for (int i = 0; i < testSet.numInstances(); i++) {
            double pred = fc.classifyInstance(testSet.instance(i));
            if (list.isEmpty()) {
                output.put(String.valueOf(i + 1), testSet.classAttribute().value((int) pred));
            } else {
                output.put(list.get(i), testSet.classAttribute().value((int) pred));
            }
        }
    } catch (Exception ex) {
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:32,代码来源:FunctionWiseClassifier.java

示例4: 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);
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:20,代码来源:MarkovAttributeSet.java

示例5: 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;
}
 
开发者ID:jesuino,项目名称:java-ml-projects,代码行数:30,代码来源:Clustering.java

示例6: 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;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:34,代码来源:CSVToARFFHeaderReduceTask.java

示例7: 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;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:19,代码来源:ClustererPanel.java

示例8: 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;
  }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:27,代码来源:ClustererPanel.java

示例9: 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);
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:27,代码来源:EMImputationTest.java

示例10: 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);
}
 
开发者ID:IsaacHaze,项目名称:meka,代码行数:13,代码来源:F.java

示例11: generateAndWriteFullModel

import weka.filters.unsupervised.attribute.Remove; //导入依赖的package包/类
/**
 * Generate the model with all data and write it with the appropriate filters.
 *
 * @param instances as returned from {@link WekaUtils#createInstances(String)}
 * @throws Exception
 */
private void generateAndWriteFullModel(Instances instances) throws Exception {
  StringToWordVector stringToWordVector = getStringToWordVectorFilter(instances);
  Instances stringsReplacedData = Filter.useFilter(instances, stringToWordVector);
  Instances resampled = dumbResample(stringsReplacedData);
  Remove removeFilter = getRemoveFilter(stringsReplacedData);
  LibSVM svmForOut = new LibSVM();
  svmForOut.setCost(config.getSvmCost().get(0));
  svmForOut.setGamma(config.getSvmGamma().get(0));
  FilteredClassifier filteredClassifierForOut = new FilteredClassifier();
  filteredClassifierForOut.setClassifier(svmForOut);
  filteredClassifierForOut.setFilter(removeFilter);
  filteredClassifierForOut.buildClassifier(resampled);
  weka.core.SerializationHelper.write(config.getOutputDir() + "/svm_model_c_" + config.getSvmCost().get(0) + "_gamma_" + config.getSvmGamma().get(0) + ".model", filteredClassifierForOut);
  weka.core.SerializationHelper.write(config.getOutputDir() + "/string_filter_c_" + config.getSvmCost().get(0) + "_gamma_" + config.getSvmGamma().get(0) + ".model", stringToWordVector);
}
 
开发者ID:ag-gipp,项目名称:mathosphere,代码行数:22,代码来源:WekaLearner.java

示例12: classify

import weka.filters.unsupervised.attribute.Remove; //导入依赖的package包/类
/**
 * Classifies whole program test instances,
 *
 * @return String containing the classification result of the evaluated program's dataset.
 * @throws ClassificationFailedException
 */
@Override
public Object classify() throws ClassificationFailedException {
    J48 j48 = new J48();
    Remove rm = new Remove();
    String output = null;
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);
        this.treeModel = j48.toString();
        double pred = fc.classifyInstance(testSet.instance(0));
        output = testSet.classAttribute().value((int) pred);
        classificationResult = output;
    } catch (Exception ex) {
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:27,代码来源:WholeProgramClassifier.java

示例13: classify

import weka.filters.unsupervised.attribute.Remove; //导入依赖的package包/类
/**
 * Classifies Timesliced test data instances.
 *
 * @return Resulting linked list with timelsiced classification results.
 * @throws ClassificationFailedException
 */
@Override
public Object classify() throws ClassificationFailedException {
    output = new LinkedList<String>();
    J48 j48 = new J48();
    Remove rm = new Remove();
    rm.setAttributeIndices("1");
    FilteredClassifier fc = new FilteredClassifier();
    fc.setFilter(rm);
    fc.setClassifier(j48);
    try {
        fc.buildClassifier(trainSet);


        for (int i = 0; i < testSet.numInstances(); i++) {
            //System.out.println(testSet.instance(i));
            double pred = fc.classifyInstance(testSet.instance(i));
            output.add(testSet.classAttribute().value((int) pred));
        }
    } catch (Exception ex) {
        System.out.println(ex.toString());
        throw new ClassificationFailedException();
    }
    return output;
}
 
开发者ID:sunimalr,项目名称:vimarsha,代码行数:31,代码来源:TimeslicedClassifier.java

示例14: 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();
}
 
开发者ID:pentaho,项目名称:pdi-weka-scoring-plugin,代码行数:23,代码来源:WekaScoringClusterer.java

示例15: 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;
	}
	
}
 
开发者ID:mommi84,项目名称:BALLAD,代码行数:23,代码来源:WekaClassifier.java


注:本文中的weka.filters.unsupervised.attribute.Remove类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。