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;
}
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);
}
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);
}
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();
}
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;
}
Aggregations