當前位置: 首頁>>代碼示例>>Java>>正文


Java Filter類代碼示例

本文整理匯總了Java中weka.filters.Filter的典型用法代碼示例。如果您正苦於以下問題:Java Filter類的具體用法?Java Filter怎麽用?Java Filter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Filter類屬於weka.filters包,在下文中一共展示了Filter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildAssociate

import weka.filters.Filter; //導入依賴的package包/類
public static String buildAssociate() throws Exception {
    InstanceQuery query = new InstanceQuery();
    query.setUsername("root");
    query.setPassword("cs6310");
    query.setDatabaseURL("jdbc:mysql://localhost/system?#characterEncoding=UTF-8");
    query.setQuery("select * from courses_sessions;");
    // You can declare that your data set is sparse
    // query.setSparseData(true);
    Instances data = query.retrieveInstances();
    data.setClassIndex(data.numAttributes() - 1);

    final NumericToNominal filter = new NumericToNominal();

    filter.setInputFormat(data);
    data = Filter.useFilter(data, filter);
    if (data.size() > 0) {
        // build associator
        Apriori apriori = new Apriori();
        apriori.setClassIndex(data.classIndex());
        apriori.buildAssociations(data);
        return String.valueOf(apriori);
    } else {
        return "Not enough data provided";
    }
}
 
開發者ID:ejesposito,項目名稱:CS6310O01,代碼行數:26,代碼來源:WekaDataMiner.java

示例2: testScoreWithClassifierSomeMissingFields

import weka.filters.Filter; //導入依賴的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: applyAndSaveFilters

import weka.filters.Filter; //導入依賴的package包/類
private void applyAndSaveFilters(String pathToSaveFilter) throws ClassifierException {
        try {
            log.info("Applying StringToWordVector filter...");
//            String[] options = Utils.splitOptions("-R first-last -W 5000 -prune-rate 20.0 -C -N 0 " +
//                    "-stemmer weka.core.stemmers.NullStemmer -M 3 -tokenizer \"weka.core.tokenizers.NGramTokenizer " +
//                    "-delimiters \\\" \\\\r\\\\n\\\\t.,;:\\\\\\'\\\\\\\"()?!\\\" -max 1 -min 1\"");
//
            String[] options = Utils.splitOptions("-R first-last -W 5000 -prune-rate 20.0 -T -I -N 0 -L -stemmer weka" +
                    ".core.stemmers.NullStemmer -M 1 -tokenizer \"weka.core.tokenizers.WordTokenizer -delimiters \\\" \\\\r\\\\n\\\\t.,;:\\\\\\'\\\\\\\"()?!\\\"\"");
            StringToWordVector filter = new StringToWordVector();
            filter.setOptions(options);
            filter.setInputFormat(loaderInstance);
            loaderInstance = Filter.useFilter(loaderInstance, filter);
            log.info("StringToWordVector Filter applied");
            loaderInstance.setClass(loaderInstance.attribute(0));
            FilterUtil.saveFilter(filter, pathToSaveFilter);
        } catch (Exception e) {
            log.error("Failed to apply filter.", e);
            throw new ClassifierException("Data Filtering failed.", e);
        }
    }
 
開發者ID:sasinda,項目名稱:OntologyBasedInormationExtractor,代碼行數:22,代碼來源:WekaPreProcessor.java

示例4: preProcessData

import weka.filters.Filter; //導入依賴的package包/類
public static Instances preProcessData(Instances data) throws Exception{
	
	/* 
	 * Remove useless attributes
	 */
	RemoveUseless removeUseless = new RemoveUseless();
	removeUseless.setOptions(new String[] { "-M", "99" });	// threshold
	removeUseless.setInputFormat(data);
	data = Filter.useFilter(data, removeUseless);

	
	/* 
	 * Remove useless attributes
	 */
	ReplaceMissingValues fixMissing = new ReplaceMissingValues();
	fixMissing.setInputFormat(data);
	data = Filter.useFilter(data, fixMissing);
	

	/* 
	 * Remove useless attributes
	 */
	Discretize discretizeNumeric = new Discretize();
	discretizeNumeric.setOptions(new String[] {
			"-O",
			"-M",  "-1.0", 
			"-B",  "4",  // no of bins
			"-R",  "first-last"}); //range of attributes
	fixMissing.setInputFormat(data);
	data = Filter.useFilter(data, fixMissing);

	/* 
	 * Select only informative attributes
	 */
	InfoGainAttributeEval eval = new InfoGainAttributeEval();
	Ranker search = new Ranker();
	search.setOptions(new String[] { "-T", "0.001" });	// information gain threshold
	AttributeSelection attSelect = new AttributeSelection();
	attSelect.setEvaluator(eval);
	attSelect.setSearch(search);
	
	// apply attribute selection
	attSelect.SelectAttributes(data);
	
	// remove the attributes not selected in the last run
	data = attSelect.reduceDimensionality(data);
	
	

	return data;
}
 
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:52,代碼來源:KddCup.java

示例5: createFilter

import weka.filters.Filter; //導入依賴的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

示例6: splitWorkload

import weka.filters.Filter; //導入依賴的package包/類
/**
 * 
 * @param data
 * @return
 */
protected Instances[] splitWorkload(Instances data) {
    int offset = 0;
    int all_cnt = data.numInstances();
    for (SplitType stype : SplitType.values()) {
        int idx = stype.ordinal();
        this.split_counts[idx] = (int)Math.round(all_cnt * stype.percentage);
        
        try {
            this.splits[idx] = new Instances(data, offset, this.split_counts[idx]);
        
            // Apply NumericToNominal filter!
            NumericToNominal filter = new NumericToNominal();
            filter.setInputFormat(this.splits[idx]);
            this.splits[idx] = Filter.useFilter(this.splits[idx], filter);
            
        } catch (Exception ex) {
            throw new RuntimeException("Failed to split " + stype + " workload", ex);
        }
        
        offset += this.split_counts[idx];
        if (debug.val) LOG.debug(String.format("%-12s%d", stype.toString()+":", this.split_counts[idx]));
    } // FOR
    return (this.splits);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:30,代碼來源:FeatureClusterer.java

示例7: testCreateMarkovAttributeSetFilter

import weka.filters.Filter; //導入依賴的package包/類
/**
     * testCreateMarkovAttributeSetFilter
     */
    @Test
    public void testCreateMarkovAttributeSetFilter() throws Exception {
        // Test that we can create a filter from an MarkovAttributeSet
        MarkovAttributeSet aset = new MarkovAttributeSet(data, FeatureUtil.getFeatureKeyPrefix(ParamArrayLengthFeature.class));
        assertEquals(CatalogUtil.getArrayProcParameters(catalog_proc).size(), aset.size());
        
        Filter filter = aset.createFilter(data);
        Instances newData = Filter.useFilter(data, filter);
        for (int i = 0, cnt = newData.numInstances(); i < cnt; i++) {
            Instance processed = newData.instance(i);
//            System.err.println(processed);
            assertEquals(aset.size(), processed.numAttributes());
        } // WHILE
        assertEquals(data.numInstances(), newData.numInstances());
//        System.err.println("MarkovAttributeSet: " + aset);
        
    }
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:21,代碼來源:TestFeatureClusterer.java

示例8: predictInstanceDistribution

import weka.filters.Filter; //導入依賴的package包/類
public double[] predictInstanceDistribution(Reader reader) throws Exception {
    // assume that the file contains only 1 instance
    // load instances
    Instances data = new Instances(reader);
    // remove reportID attribute
    String[] options = weka.core.Utils.splitOptions("-R 1");  // removes the first attribute in instances (should be the document id?)
    String filterName = "weka.filters.unsupervised.attribute.Remove";
    Filter filter = (Filter) Class.forName(filterName).newInstance();
    if (filter instanceof OptionHandler) {
        ((OptionHandler) filter).setOptions(options);
    }
    filter.setInputFormat(data);
    // make the instances
    Instances unlabeled = Filter.useFilter(data, filter);

    double[][] dist = this.predictDataDistribution(unlabeled);
    return dist[0];
}
 
開發者ID:NLPReViz,項目名稱:emr-nlp-server,代碼行數:19,代碼來源:CertSVMPredictor.java

示例9: trainModelFromFile

import weka.filters.Filter; //導入依賴的package包/類
public void trainModelFromFile(String fnTrainData) throws Exception {
    // load instances
    Instances data = new Instances(new BufferedReader(new FileReader(fnTrainData)));
    // preprocess instances
    String[] options = weka.core.Utils.splitOptions("-R 1");
    String filterName = "weka.filters.unsupervised.attribute.Remove";
    Filter filter = (Filter) Class.forName(filterName).newInstance();
    if (filter instanceof OptionHandler) {
        ((OptionHandler) filter).setOptions(options);
    }
    filter.setInputFormat(data);
    // make the instances
    Instances unlabeled = Filter.useFilter(data, filter);
    // train model
    this.trainModel(unlabeled);
}
 
開發者ID:NLPReViz,項目名稱:emr-nlp-server,代碼行數:17,代碼來源:CertSVMPredictor.java

示例10: buildClusteredSeries

import weka.filters.Filter; //導入依賴的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

示例11: loadFilter

import weka.filters.Filter; //導入依賴的package包/類
/**
 * Load the PreconstructedFilter to use from the file system
 * 
 * @throws Exception if a problem occurs
 */
protected void loadFilter() throws Exception {
  File f = new File(getPathToPreConstructedFilter());

  if (!f.exists()) {
    throw new IOException("The serialized filter '"
      + getPathToPreConstructedFilter()
      + "' does not seem to exit on the file system!");
  }

  ObjectInputStream ois = null;
  try {
    ois = new ObjectInputStream(new BufferedInputStream(
      new FileInputStream(f)));
    setPreConstructedFilter((Filter) ois.readObject());
  } finally {
    if (ois != null) {
      ois.close();
    }
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:26,代碼來源:AggregateableFilteredClassifier.java

示例12: buildClassifier

import weka.filters.Filter; //導入依賴的package包/類
@Override
public void buildClassifier(Instances data) throws Exception {

  if (getPathToPreConstructedFilter() != null
    && getPathToPreConstructedFilter().length() > 0) {
    loadFilter();
  }

  if (getClassifier() == null) {
    throw new Exception("No base classifier set!");
  }

  if (getPreConstructedFilter() == null) {
    throw new Exception("No filter set!");
  }

  Instances filtered = Filter.useFilter(data, getPreConstructedFilter());
  m_filteredInstances = filtered.stringFreeStructure();

  getClassifier().buildClassifier(filtered);
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:22,代碼來源:AggregateableFilteredClassifier.java

示例13: getFinalizedClusterer

import weka.filters.Filter; //導入依賴的package包/類
public Clusterer getFinalizedClusterer() throws DistributedWekaException {
  if (m_canopy == null) {
    throw new DistributedWekaException(
      "CanopyMapTask has not been initialized yet!");
  }

  if (!m_finalized) {
    throw new DistributedWekaException(
      "This map task has note been finalized yet!");
  }

  if (m_finalFullPreprocess == null) {
    return m_canopy;
  }

  PreconstructedFilteredClusterer fc = new PreconstructedFilteredClusterer();
  fc.setFilter((Filter) m_finalFullPreprocess);
  fc.setClusterer(m_canopy);

  return fc;
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:22,代碼來源:CanopyMapTask.java

示例14: stripSummaryAtts

import weka.filters.Filter; //導入依賴的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

示例15: setOptions

import weka.filters.Filter; //導入依賴的package包/類
@Override
public void setOptions(String[] options) throws Exception {
  setDontReplaceMissingValues(Utils.getFlag("dont-replace-missing", options));

  m_filtersToUse = new ArrayList<Filter>();
  while (true) {
    String filterString = Utils.getOption("filter", options);
    if (DistributedJobConfig.isEmpty(filterString)) {
      break;
    }

    String[] spec = Utils.splitOptions(filterString);
    if (spec.length == 0) {
      throw new IllegalArgumentException(
        "Invalid filter specification string");
    }
    String filterClass = spec[0];
    Filter f = (Filter) Class.forName(filterClass).newInstance();
    spec[0] = "";
    if (f instanceof OptionHandler) {
      ((OptionHandler) f).setOptions(spec);
    }
    m_filtersToUse.add(f);
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:26,代碼來源:KMeansMapTask.java


注:本文中的weka.filters.Filter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。