List of usage examples for weka.attributeSelection ASEvaluation buildEvaluator
public abstract void buildEvaluator(Instances data) 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 {/*from w w w . j av 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.dimensionalityReduction.BinaryRelevanceAttributeEvaluator.java
License:Open Source License
/** * @param ase /*from w w w .ja v a 2 s .co m*/ * @param mlData * @param combapp combination approach mode ("max", "avg", "min") * @param norm normalization mode ("dl", "dm", "none") * @param mode scoring mode ("eval", "rank") */ public BinaryRelevanceAttributeEvaluator(ASEvaluation ase, MultiLabelInstances mlData, String combapp, String norm, String mode) { CombApprMode = combapp; NormMode = norm; ScoreMode = mode; numLabels = mlData.getNumLabels(); int[] labelIndices = mlData.getLabelIndices(); try { int numAttributes = mlData.getFeatureIndices().length; double[][] evaluations = new double[numLabels][numAttributes]; for (int i = 0; i < numLabels; i++) { // create dataset Instances labelInstances = BinaryRelevanceTransformation.transformInstances(mlData.getDataSet(), labelIndices, labelIndices[i]); // build evaluator ase.buildEvaluator(labelInstances); // evaluate features for (int j = 0; j < numAttributes; j++) { evaluations[i][j] = ((AttributeEvaluator) ase).evaluateAttribute(j); } } //scoring of features scores = featureSelection(evaluations); } catch (Exception ex) { ex.printStackTrace(); } }