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


Java Remove.setAttributeIndices方法代码示例

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


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

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

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

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

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

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

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

示例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) {
	}
}
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Cookbook,代码行数:17,代码来源:WekaClassesToClusterTest.java

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

示例13: 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;
}
 
开发者ID:UKPLab,项目名称:jlcl2015-pythagoras,代码行数:19,代码来源:ListMisclassifiedInstances.java

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

示例15: setUp

import weka.filters.unsupervised.attribute.Remove; //导入方法依赖的package包/类
protected void setUp() throws Exception {
  m_Filter             = getFilter();
  m_Instances          = new Instances(new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("weka/filters/data/FilterTest.arff"))));
  Remove r = new Remove();
  r.setAttributeIndices("1, 2, 4, 5");
  r.setInputFormat(m_Instances);
  m_Instances = Filter.useFilter(m_Instances, r);
  m_OptionTester       = getOptionTester();
  m_GOETester          = getGOETester();
  m_FilteredClassifier = null;
}
 
开发者ID:umple,项目名称:umple,代码行数:12,代码来源:TransposeTest.java


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