<NME> LSBoostInspector.java
<BEF> ADDFILE
<MSG> LSBoostInspector

<DFF> @@ -0,0 +1,48 @@
+package edu.neu.ccs.pyramid.regression.least_squares_boost;
+
+import edu.neu.ccs.pyramid.classification.lkboost.LKBoost;
+import edu.neu.ccs.pyramid.dataset.LabelTranslator;
+import edu.neu.ccs.pyramid.feature.Feature;
+import edu.neu.ccs.pyramid.feature.TopFeatures;
+import edu.neu.ccs.pyramid.regression.Regressor;
+import edu.neu.ccs.pyramid.regression.regression_tree.RegTreeInspector;
+import edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Created by chengli on 2/22/17.
+ */
+public class LSBoostInspector {
+
+    public static TopFeatures topFeatures(LSBoost boosting){
+        Map<Feature,Double> totalContributions = new HashMap<>();
+        List<Regressor> regressors = boosting.getEnsemble(0).getRegressors();
+        List<RegressionTree> trees = regressors.stream().filter(regressor ->
+                regressor instanceof RegressionTree)
+                .map(regressor -> (RegressionTree) regressor)
+                .collect(Collectors.toList());
+        for (RegressionTree tree: trees){
+            Map<Feature,Double> contributions = RegTreeInspector.featureImportance(tree);
+            for (Map.Entry<Feature,Double> entry: contributions.entrySet()){
+                Feature feature = entry.getKey();
+                Double contribution = entry.getValue();
+                double oldValue = totalContributions.getOrDefault(feature,0.0);
+                double newValue = oldValue+contribution;
+                totalContributions.put(feature,newValue);
+            }
+        }
+
+        System.out.println(totalContributions);
+        Comparator<Map.Entry<Feature,Double>> comparator = Comparator.comparing(Map.Entry::getValue);
+        List<Feature> list = totalContributions.entrySet().stream().sorted(comparator.reversed())
+                .map(Map.Entry::getKey).collect(Collectors.toList());
+        TopFeatures topFeatures = new TopFeatures();
+        topFeatures.setTopFeatures(list);
+        return topFeatures;
+    }
+}

LSBoostInspector