Search in sources :

Example 1 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor in project pyramid by cheng-li.

the class LSBoostInspector method topFeatures.

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;
}
Also used : RegressionTree(edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree) List(java.util.List) Feature(edu.neu.ccs.pyramid.feature.Feature) LabelTranslator(edu.neu.ccs.pyramid.dataset.LabelTranslator) Regressor(edu.neu.ccs.pyramid.regression.Regressor) Map(java.util.Map) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) HashMap(java.util.HashMap) RegTreeInspector(edu.neu.ccs.pyramid.regression.regression_tree.RegTreeInspector) LKBoost(edu.neu.ccs.pyramid.classification.lkboost.LKBoost) Comparator(java.util.Comparator) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) RegressionTree(edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree) TopFeatures(edu.neu.ccs.pyramid.feature.TopFeatures) Feature(edu.neu.ccs.pyramid.feature.Feature) Regressor(edu.neu.ccs.pyramid.regression.Regressor) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor in project pyramid by cheng-li.

the class LSBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    double average = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToDouble(i -> labels[i] * weights[i]).average().getAsDouble();
    Regressor constant = new ConstantRegressor(average);
    boosting.getEnsemble(0).add(constant);
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 3 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor in project pyramid by cheng-li.

the class PBoostOptimizer method addPriors.

@Override
protected void addPriors() {
    double average = IntStream.range(0, dataSet.getNumDataPoints()).parallel().mapToDouble(i -> labels[i] * weights[i]).average().getAsDouble();
    Regressor constant = new ConstantRegressor(average);
    boosting.getEnsemble(0).add(constant);
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor) ConstantRegressor(edu.neu.ccs.pyramid.regression.ConstantRegressor)

Example 4 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor in project pyramid by cheng-li.

the class GBOptimizer method iterate.

public void iterate() {
    if (!isInitialized) {
        throw new RuntimeException("GBOptimizer is not initialized");
    }
    for (int k = 0; k < boosting.getNumEnsembles(); k++) {
        Regressor regressor = fitRegressor(k);
        shrink(regressor);
        boosting.getEnsemble(k).add(regressor);
        updateStagedScores(regressor, k);
    }
    updateOthers();
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor)

Example 5 with Regressor

use of edu.neu.ccs.pyramid.regression.Regressor in project pyramid by cheng-li.

the class GBOptimizer method fitRegressor.

protected Regressor fitRegressor(int ensembleIndex) {
    double[] gradients = gradient(ensembleIndex);
    Regressor regressor = factory.fit(dataSet, gradients, weights);
    return regressor;
}
Also used : Regressor(edu.neu.ccs.pyramid.regression.Regressor)

Aggregations

Regressor (edu.neu.ccs.pyramid.regression.Regressor)17 ConstantRegressor (edu.neu.ccs.pyramid.regression.ConstantRegressor)11 PriorProbClassifier (edu.neu.ccs.pyramid.classification.PriorProbClassifier)1 LKBoost (edu.neu.ccs.pyramid.classification.lkboost.LKBoost)1 LabelTranslator (edu.neu.ccs.pyramid.dataset.LabelTranslator)1 Feature (edu.neu.ccs.pyramid.feature.Feature)1 TopFeatures (edu.neu.ccs.pyramid.feature.TopFeatures)1 RegTreeInspector (edu.neu.ccs.pyramid.regression.regression_tree.RegTreeInspector)1 RegressionTree (edu.neu.ccs.pyramid.regression.regression_tree.RegressionTree)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1