List of usage examples for weka.attributeSelection AttributeEvaluator evaluateAttribute
public abstract double evaluateAttribute(int attribute) throws Exception;
From source file:com.rapidminer.operator.features.weighting.GenericWekaAttributeWeighting.java
License:Open Source License
public AttributeWeights calculateWeights(ExampleSet exampleSet) throws OperatorException { AttributeWeights weights = new AttributeWeights(); ASEvaluation evaluator = getWekaAttributeEvaluator(getOperatorClassName(), WekaTools.getWekaParametersFromTypes(this, wekaParameters)); log("Converting to Weka instances."); Instances instances = WekaTools.toWekaInstances(exampleSet, "WeightingInstances", WekaInstancesAdaptor.WEIGHTING); try {//w ww . j a v a2 s .c o m log("Building Weka attribute evaluator."); evaluator.buildEvaluator(instances); //evaluator.buildEvaluator(instances); } catch (UnassignedClassException e) { throw new UserError(this, e, 105, new Object[] { getOperatorClassName(), e }); } catch (ArrayIndexOutOfBoundsException e) { throw new UserError(this, e, 105, new Object[] { getOperatorClassName(), e }); } catch (Exception e) { throw new UserError(this, e, 905, new Object[] { getOperatorClassName(), e }); } int index = 0; if (evaluator instanceof AttributeEvaluator) { AttributeEvaluator singleEvaluator = (AttributeEvaluator) evaluator; for (Attribute attribute : exampleSet.getAttributes()) { try { double result = singleEvaluator.evaluateAttribute(index++); weights.setWeight(attribute.getName(), result); } catch (Exception e) { logWarning("Cannot evaluate attribute '" + attribute.getName() + "', use unknown weight."); } } } else { logWarning("Cannot evaluate attributes, use unknown weights."); } return weights; }
From source file:mulan.experiments.ENTCS13FeatureSelection.java
License:Open Source License
/** * Given an array with feature indices, this method returns a double matrix * similar to the one returned by the method rankedAttributes from the Weka * {@link weka.attributeSelection.Ranker} class * * @param featureIndices an array of feature indices * @param attributeEval the attribute evaluator to guide the evaluation * @return a matrix of sorted attribute indices and evaluations *//*from ww w .ja v a 2s . c om*/ public static double[][] sortedEvaluatedAttributeList(int[] featureIndices, AttributeEvaluator attributeEval) { double[][] result = new double[featureIndices.length][2]; try { for (int i = 0; i < featureIndices.length; i++) { //the feature indices after problem transformation range from 0 to featureIndices.length result[i][0] = featureIndices[i]; //actual feature index result[i][1] = attributeEval.evaluateAttribute(i); } sortAttributeRanking(result, 1, DESCENDING); } catch (Exception ex) { Logger.getLogger(ENTCS13FeatureSelection.class.getName()).log(Level.SEVERE, null, ex); } return result; }