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


Java Filter.useFilter方法代碼示例

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


在下文中一共展示了Filter.useFilter方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: buildClusterer

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * Build the clusterer on the filtered data.
 * 
 * @param data the training data
 * @throws Exception if the clusterer could not be built successfully
 */
@Override
public void buildClusterer(Instances data) throws Exception {
  if (m_Clusterer == null) {
    throw new Exception("No base clusterer has been set!");
  }

  // remove instances with missing class
  if (data.classIndex() > -1) {
    data = new Instances(data);
    data.deleteWithMissingClass();
  }

  m_Filter.setInputFormat(data); // filter capabilities are checked here
  data = Filter.useFilter(data, m_Filter);

  // can clusterer handle the data?
  getClusterer().getCapabilities().testWithFail(data);

  m_FilteredInstances = data.stringFreeStructure();
  m_Clusterer.buildClusterer(data);
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:28,代碼來源:FilteredClusterer.java

示例8: removeClass

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

示例9: distributionsForInstances

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * Batch scoring method. Calls the appropriate method for the base learner if
 * it implements BatchPredictor. Otherwise it simply calls the
 * distributionForInstance() method repeatedly.
 * 
 * @param insts the instances to get predictions for
 * @return an array of probability distributions, one for each instance
 * @throws Exception if a problem occurs
 */
public double[][] distributionsForInstances(Instances insts) throws Exception {

  if (getClassifier() instanceof BatchPredictor) {
    Instances filteredInsts = Filter.useFilter(insts, m_Filter);
    if (filteredInsts.numInstances() != insts.numInstances()) {
      throw new WekaException(
        "FilteredClassifier: filter has returned more/less instances than required.");
    }
    return ((BatchPredictor) getClassifier())
      .distributionsForInstances(filteredInsts);
  } else {
    double[][] result = new double[insts.numInstances()][insts.numClasses()];
    for (int i = 0; i < insts.numInstances(); i++) {
      result[i] = distributionForInstance(insts.instance(i));
    }
    return result;
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:28,代碼來源:FilteredClassifier.java

示例10: buildEvaluator

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * Initializes a gain ratio attribute evaluator. Discretizes all attributes
 * that are numeric.
 * 
 * @param data set of instances serving as training data
 * @throws Exception if the evaluator has not been generated successfully
 */
@Override
public void buildEvaluator(Instances data) throws Exception {

  // can evaluator handle data?
  getCapabilities().testWithFail(data);

  m_trainInstances = data;
  m_classIndex = m_trainInstances.classIndex();
  m_numInstances = m_trainInstances.numInstances();
  Discretize disTransform = new Discretize();
  disTransform.setUseBetterEncoding(true);
  disTransform.setInputFormat(m_trainInstances);
  m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
  m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:23,代碼來源:GainRatioAttributeEval.java

示例11: buildClassifier

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * Builds the classifiers.
 *
 * @param insts the training data.
 * @throws Exception if a classifier can't be built
 */
public void buildClassifier(Instances insts) throws Exception {

  Instances newInsts;

  // can classifier handle the data?
  getCapabilities().testWithFail(insts);

  // remove instances with missing class
  insts = new Instances(insts);
  insts.deleteWithMissingClass();
  
  m_Classifiers = AbstractClassifier.makeCopies(m_Classifier, insts.numClasses());
  m_ClassFilters = new MakeIndicator[insts.numClasses()];
  for (int i = 0; i < insts.numClasses(); i++) {
    m_ClassFilters[i] = new MakeIndicator();
    m_ClassFilters[i].setAttributeIndex("" + (insts.classIndex() + 1));
    m_ClassFilters[i].setValueIndex(i);
    m_ClassFilters[i].setNumeric(true);
    m_ClassFilters[i].setInputFormat(insts);
    newInsts = Filter.useFilter(insts, m_ClassFilters[i]);
    m_Classifiers[i].buildClassifier(newInsts);
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:30,代碼來源:ClassificationViaRegression.java

示例12: buildEvaluator

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * Initializes a symmetrical uncertainty attribute evaluator. Discretizes all
 * attributes that are numeric.
 * 
 * @param data set of instances serving as training data
 * @throws Exception if the evaluator has not been generated successfully
 */
@Override
public void buildEvaluator(Instances data) throws Exception {

  // can evaluator handle data?
  getCapabilities().testWithFail(data);

  m_trainInstances = data;
  m_classIndex = m_trainInstances.classIndex();
  m_numInstances = m_trainInstances.numInstances();
  Discretize disTransform = new Discretize();
  disTransform.setUseBetterEncoding(true);
  disTransform.setInputFormat(m_trainInstances);
  m_trainInstances = Filter.useFilter(m_trainInstances, disTransform);
  m_numClasses = m_trainInstances.attribute(m_classIndex).numValues();
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:23,代碼來源:SymmetricalUncertAttributeEval.java

示例13: addInstanceNumberAttribute

import weka.filters.Filter; //導入方法依賴的package包/類
/**
 * 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();
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:22,代碼來源:PlotData2D.java

示例14: removeAttribute

import weka.filters.Filter; //導入方法依賴的package包/類
public Instances removeAttribute(String attrIndex, Instances data) throws Exception {
    String[] options = weka.core.Utils.splitOptions("-R " + attrIndex);
    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
    return Filter.useFilter(data, filter);
}
 
開發者ID:NLPReViz,項目名稱:emr-nlp-server,代碼行數:12,代碼來源:SVMPredictor.java

示例15: generateClassToCluster

import weka.filters.Filter; //導入方法依賴的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) {
	}
}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Cookbook,代碼行數:17,代碼來源:WekaClassesToClusterTest.java


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