• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java RemoveWithValues类的典型用法和代码示例

java 1次浏览

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

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

示例1: toString

点赞 2

import weka.filters.unsupervised.instance.RemoveWithValues; //导入依赖的package包/类
/**
 * Prints the classifiers.
 * 
 * @return a string representation of the classifier
 */
public String toString() {

  if (m_Classifiers == null) {
    return "MultiClassClassifier: No model built yet.";
  }
  StringBuffer text = new StringBuffer();
  text.append("MultiClassClassifier\n\n");
  for (int i = 0; i < m_Classifiers.length; i++) {
    text.append("Classifier ").append(i + 1);
    if (m_Classifiers[i] != null) {
      if ((m_ClassFilters != null) && (m_ClassFilters[i] != null)) {
 if (m_ClassFilters[i] instanceof RemoveWithValues) {
   Range range = new Range(((RemoveWithValues)m_ClassFilters[i])
		    .getNominalIndices());
   range.setUpper(m_ClassAttribute.numValues());
   int[] pair = range.getSelection();
   text.append(", " + (pair[0]+1) + " vs " + (pair[1]+1));
 } else if (m_ClassFilters[i] instanceof MakeIndicator) {
   text.append(", using indicator values: ");
   text.append(((MakeIndicator)m_ClassFilters[i]).getValueRange());
 }
      }
      text.append('\n');
      text.append(m_Classifiers[i].toString() + "\n\n");
    } else {
      text.append(" Skipped (no training examples)\n");
    }
  }

  return text.toString();
}
 

开发者ID:mydzigear,
项目名称:repo.kmeanspp.silhouette_score,
代码行数:37,
代码来源:MultiClassClassifier.java

示例2: removeWithValues

点赞 2

import weka.filters.unsupervised.instance.RemoveWithValues; //导入依赖的package包/类
/**
 * Removes all instances that have one of the given values.
 * 
 * @param data
 *            Array of Instances (e.g., folds).
 * @param attribute The name of the attribute according to which is filtered.
 * @param values Instances where the attribute takes one of these values are to be removed.
 * @return The filtered set of Instances, again an array of Instances.
 * @throws Exception
 */
public static Instances[] removeWithValues(Instances[] data, String attribute, String[] values) throws Exception {

	String valueRegex = "";
	for (String v : values) {
		valueRegex += v + "|";
	}
	valueRegex = valueRegex.substring(0, valueRegex.length() - 1);

	List<Integer> indicesToRemove = new LinkedList<Integer>();
	// find indices of values that should be removed
	Attribute classAttr = data[0].attribute(attribute);
	int classAttrIndex = classAttr.index();
	
	for (int i = 0; i < classAttr.numValues(); i++) {
		String value = classAttr.value(i);
		if (value.matches(valueRegex)) {
			indicesToRemove.add(i);
		}
	}
	if (!indicesToRemove.isEmpty()) {
		int[] indices = new int[indicesToRemove.size()];
		for (int i = 0; i < indicesToRemove.size(); i++) {
			indices[i] = indicesToRemove.get(i);
		}

		RemoveWithValues removeValuesFilter = new RemoveWithValues();
		// at RemoveWithValuesFilter for whatever reason the indices
		// need to be increased by 1. But that's not the case for the
		// other filters.
		removeValuesFilter.setAttributeIndex(new Integer(classAttrIndex + 1).toString());
		removeValuesFilter.setNominalIndicesArr(indices);
		removeValuesFilter.setInputFormat(data[0]);
		for (int i = 0; i < data.length; i++) {
			data[i] = Filter.useFilter(data[i], removeValuesFilter);
		}
	}

	return data;

}
 

开发者ID:annefried,
项目名称:sitent,
代码行数:51,
代码来源:WekaUtils.java

示例3: distributionForInstance

点赞 2

import weka.filters.unsupervised.instance.RemoveWithValues; //导入依赖的package包/类
/**
 * Returns the distribution for an instance.
 * 
 * @param inst the instance to get the distribution for
 * @return the distribution
 * @throws Exception if the distribution can't be computed successfully
 */
@Override
public double[] distributionForInstance(Instance inst) throws Exception {

  if (m_Classifiers.length == 1) {
    return m_Classifiers[0].distributionForInstance(inst);
  }

  double[] probs = new double[inst.numClasses()];
  if (m_Method == METHOD_1_AGAINST_1) {
    double[][] r = new double[inst.numClasses()][inst.numClasses()];
    double[][] n = new double[inst.numClasses()][inst.numClasses()];

    for (int i = 0; i < m_ClassFilters.length; i++) {
      if (m_Classifiers[i] != null && m_SumOfWeights[i] > 0) {
        Instance tempInst = (Instance) inst.copy();
        tempInst.setDataset(m_TwoClassDataset);
        double[] current = m_Classifiers[i].distributionForInstance(tempInst);
        Range range = new Range(
            ((RemoveWithValues) m_ClassFilters[i]).getNominalIndices());
        range.setUpper(m_ClassAttribute.numValues());
        int[] pair = range.getSelection();
        if (m_pairwiseCoupling && inst.numClasses() > 2) {
          r[pair[0]][pair[1]] = current[0];
          n[pair[0]][pair[1]] = m_SumOfWeights[i];
        } else {
          if (current[0] > current[1]) {
            probs[pair[0]] += 1.0;
          } else {
            probs[pair[1]] += 1.0;
          }
        }
      }
    }
    if (m_pairwiseCoupling && inst.numClasses() > 2) {
      try {
        return pairwiseCoupling(n, r);
      } catch (IllegalArgumentException ex) {
      }
    }
    if (Utils.gr(Utils.sum(probs), 0)) {
      Utils.normalize(probs);
    }
    return probs;
  } else {
    probs = super.distributionForInstance(inst);
  }

  /*
   * if (probs.length == 1) { // ZeroR made the prediction return new
   * double[m_ClassAttribute.numValues()]; }
   */

  return probs;
}
 

开发者ID:mydzigear,
项目名称:repo.kmeanspp.silhouette_score,
代码行数:62,
代码来源:MultiClassClassifierUpdateable.java

示例4: distributionForInstance

点赞 2

import weka.filters.unsupervised.instance.RemoveWithValues; //导入依赖的package包/类
/**
 * Returns the distribution for an instance.
 *
 * @param inst the instance to get the distribution for
 * @return the distribution
 * @throws Exception if the distribution can't be computed successfully
 */
public double[] distributionForInstance(Instance inst) throws Exception {
  
  double[] probs = new double[inst.numClasses()];
  if (m_Method == METHOD_1_AGAINST_1) {
    double[][] r = new double[inst.numClasses()][inst.numClasses()];
    double[][] n = new double[inst.numClasses()][inst.numClasses()];

    for(int i = 0; i < m_ClassFilters.length; i++) {
      if (m_Classifiers[i] != null && m_SumOfWeights[i] > 0) {
        Instance tempInst = (Instance)inst.copy(); 
        tempInst.setDataset(m_TwoClassDataset);
        double [] current = m_Classifiers[i].distributionForInstance(tempInst);  
        Range range = new Range(((RemoveWithValues)m_ClassFilters[i])
                                .getNominalIndices());
        range.setUpper(m_ClassAttribute.numValues());
        int[] pair = range.getSelection();
        if (m_pairwiseCoupling && inst.numClasses() > 2) {
          r[pair[0]][pair[1]] = current[0];
          n[pair[0]][pair[1]] = m_SumOfWeights[i];
        } else {
          if (current[0] > current[1]) {
            probs[pair[0]] += 1.0;
          } else {
            probs[pair[1]] += 1.0;
          }
        }
      }
    }
    if (m_pairwiseCoupling && inst.numClasses() > 2) {
      return pairwiseCoupling(n, r);
    }
    Utils.normalize(probs);
  } else {    
    probs = super.distributionForInstance(inst);
  }
  
  if (probs.length == 1) {
    // ZeroR made the prediction
    return new double[m_ClassAttribute.numValues()];
  }
  
  return probs;
}
 

开发者ID:dsibournemouth,
项目名称:autoweka,
代码行数:51,
代码来源:MultiClassClassifierUpdateable.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)