Search in sources :

Example 1 with FeatureUtility

use of edu.neu.ccs.pyramid.feature.FeatureUtility in project pyramid by cheng-li.

the class MLLogisticRegressionInspector method topFeatures.

public static TopFeatures topFeatures(MLLogisticRegression logisticRegression, int classIndex, int limit) {
    FeatureList featureList = logisticRegression.getFeatureList();
    Vector weights = logisticRegression.getWeights().getWeightsWithoutBiasForClass(classIndex);
    Comparator<FeatureUtility> comparator = Comparator.comparing(FeatureUtility::getUtility);
    List<Feature> list = IntStream.range(0, weights.size()).mapToObj(i -> new FeatureUtility(featureList.get(i)).setUtility(weights.get(i))).filter(featureUtility -> featureUtility.getUtility() > 0).sorted(comparator.reversed()).map(FeatureUtility::getFeature).limit(limit).collect(Collectors.toList());
    TopFeatures topFeatures = new TopFeatures();
    topFeatures.setTopFeatures(list);
    topFeatures.setClassIndex(classIndex);
    LabelTranslator labelTranslator = logisticRegression.getLabelTranslator();
    topFeatures.setClassName(labelTranslator.toExtLabel(classIndex));
    return topFeatures;
}
Also used : FeatureUtility(edu.neu.ccs.pyramid.feature.FeatureUtility) FeatureUtility(edu.neu.ccs.pyramid.feature.FeatureUtility) MultiLabelPredictionAnalysis(edu.neu.ccs.pyramid.multilabel_classification.MultiLabelPredictionAnalysis) IntStream(java.util.stream.IntStream) ClassProbability(edu.neu.ccs.pyramid.classification.ClassProbability) ConstantRule(edu.neu.ccs.pyramid.regression.ConstantRule) FeatureList(edu.neu.ccs.pyramid.feature.FeatureList) Rule(edu.neu.ccs.pyramid.regression.Rule) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) IMLGradientBoosting(edu.neu.ccs.pyramid.multilabel_classification.imlgb.IMLGradientBoosting) PredictionAnalysis(edu.neu.ccs.pyramid.classification.PredictionAnalysis) List(java.util.List) Feature(edu.neu.ccs.pyramid.feature.Feature) LogisticRegression(edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression) edu.neu.ccs.pyramid.dataset(edu.neu.ccs.pyramid.dataset) Vector(org.apache.mahout.math.Vector) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) LinearRule(edu.neu.ccs.pyramid.regression.LinearRule) Comparator(java.util.Comparator) ClassScoreCalculation(edu.neu.ccs.pyramid.regression.ClassScoreCalculation) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) FeatureList(edu.neu.ccs.pyramid.feature.FeatureList) Vector(org.apache.mahout.math.Vector) Feature(edu.neu.ccs.pyramid.feature.Feature)

Aggregations

ClassProbability (edu.neu.ccs.pyramid.classification.ClassProbability)1 PredictionAnalysis (edu.neu.ccs.pyramid.classification.PredictionAnalysis)1 LogisticRegression (edu.neu.ccs.pyramid.classification.logistic_regression.LogisticRegression)1 edu.neu.ccs.pyramid.dataset (edu.neu.ccs.pyramid.dataset)1 Feature (edu.neu.ccs.pyramid.feature.Feature)1 FeatureList (edu.neu.ccs.pyramid.feature.FeatureList)1 FeatureUtility (edu.neu.ccs.pyramid.feature.FeatureUtility)1 TopFeatures (edu.neu.ccs.pyramid.feature.TopFeatures)1 MultiLabelPredictionAnalysis (edu.neu.ccs.pyramid.multilabel_classification.MultiLabelPredictionAnalysis)1 IMLGradientBoosting (edu.neu.ccs.pyramid.multilabel_classification.imlgb.IMLGradientBoosting)1 ClassScoreCalculation (edu.neu.ccs.pyramid.regression.ClassScoreCalculation)1 ConstantRule (edu.neu.ccs.pyramid.regression.ConstantRule)1 LinearRule (edu.neu.ccs.pyramid.regression.LinearRule)1 Rule (edu.neu.ccs.pyramid.regression.Rule)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Vector (org.apache.mahout.math.Vector)1