Calculate base_score based on input labels for mae. (#8107)
Fit an intercept as base score for abs loss.
This commit is contained in:
@@ -429,11 +429,12 @@ class CPUPredictor : public Predictor {
|
||||
}
|
||||
out_preds->resize(model.learner_model_param->num_output_group *
|
||||
(model.param.size_leaf_vector + 1));
|
||||
auto base_score = model.learner_model_param->BaseScore(ctx_)(0);
|
||||
// loop over output groups
|
||||
for (uint32_t gid = 0; gid < model.learner_model_param->num_output_group; ++gid) {
|
||||
(*out_preds)[gid] = PredValue(inst, model.trees, model.tree_info, gid,
|
||||
&feat_vecs[0], 0, ntree_limit) +
|
||||
model.learner_model_param->base_score;
|
||||
(*out_preds)[gid] =
|
||||
PredValue(inst, model.trees, model.tree_info, gid, &feat_vecs[0], 0, ntree_limit) +
|
||||
base_score;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,7 +505,8 @@ class CPUPredictor : public Predictor {
|
||||
common::ParallelFor(ntree_limit, n_threads, [&](bst_omp_uint i) {
|
||||
FillNodeMeanValues(model.trees[i].get(), &(mean_values[i]));
|
||||
});
|
||||
auto base_margin = info.base_margin_.View(GenericParameter::kCpuId);
|
||||
auto base_margin = info.base_margin_.View(Context::kCpuId);
|
||||
auto base_score = model.learner_model_param->BaseScore(Context::kCpuId)(0);
|
||||
// start collecting the contributions
|
||||
for (const auto &batch : p_fmat->GetBatches<SparsePage>()) {
|
||||
auto page = batch.GetView();
|
||||
@@ -548,7 +550,7 @@ class CPUPredictor : public Predictor {
|
||||
CHECK_EQ(base_margin.Shape(1), ngroup);
|
||||
p_contribs[ncolumns - 1] += base_margin(row_idx, gid);
|
||||
} else {
|
||||
p_contribs[ncolumns - 1] += model.learner_model_param->base_score;
|
||||
p_contribs[ncolumns - 1] += base_score;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -511,7 +511,7 @@ void ExtractPaths(
|
||||
n = d_nodes[n.Parent() + tree_offset];
|
||||
path_length++;
|
||||
}
|
||||
return PathInfo{int64_t(idx), path_length, tree_idx};
|
||||
return PathInfo{static_cast<int64_t>(idx), path_length, tree_idx};
|
||||
});
|
||||
auto end = thrust::copy_if(
|
||||
thrust::cuda::par(alloc), nodes_transform,
|
||||
@@ -859,13 +859,13 @@ class GPUPredictor : public xgboost::Predictor {
|
||||
// Add the base margin term to last column
|
||||
p_fmat->Info().base_margin_.SetDevice(ctx_->gpu_id);
|
||||
const auto margin = p_fmat->Info().base_margin_.Data()->ConstDeviceSpan();
|
||||
float base_score = model.learner_model_param->base_score;
|
||||
dh::LaunchN(
|
||||
p_fmat->Info().num_row_ * model.learner_model_param->num_output_group,
|
||||
[=] __device__(size_t idx) {
|
||||
phis[(idx + 1) * contributions_columns - 1] +=
|
||||
margin.empty() ? base_score : margin[idx];
|
||||
});
|
||||
|
||||
auto base_score = model.learner_model_param->BaseScore(ctx_);
|
||||
dh::LaunchN(p_fmat->Info().num_row_ * model.learner_model_param->num_output_group,
|
||||
[=] __device__(size_t idx) {
|
||||
phis[(idx + 1) * contributions_columns - 1] +=
|
||||
margin.empty() ? base_score(0) : margin[idx];
|
||||
});
|
||||
}
|
||||
|
||||
void PredictInteractionContributions(DMatrix* p_fmat,
|
||||
@@ -918,17 +918,17 @@ class GPUPredictor : public xgboost::Predictor {
|
||||
// Add the base margin term to last column
|
||||
p_fmat->Info().base_margin_.SetDevice(ctx_->gpu_id);
|
||||
const auto margin = p_fmat->Info().base_margin_.Data()->ConstDeviceSpan();
|
||||
float base_score = model.learner_model_param->base_score;
|
||||
|
||||
auto base_score = model.learner_model_param->BaseScore(ctx_);
|
||||
size_t n_features = model.learner_model_param->num_feature;
|
||||
dh::LaunchN(
|
||||
p_fmat->Info().num_row_ * model.learner_model_param->num_output_group,
|
||||
[=] __device__(size_t idx) {
|
||||
size_t group = idx % ngroup;
|
||||
size_t row_idx = idx / ngroup;
|
||||
phis[gpu_treeshap::IndexPhiInteractions(
|
||||
row_idx, ngroup, group, n_features, n_features, n_features)] +=
|
||||
margin.empty() ? base_score : margin[idx];
|
||||
});
|
||||
dh::LaunchN(p_fmat->Info().num_row_ * model.learner_model_param->num_output_group,
|
||||
[=] __device__(size_t idx) {
|
||||
size_t group = idx % ngroup;
|
||||
size_t row_idx = idx / ngroup;
|
||||
phis[gpu_treeshap::IndexPhiInteractions(row_idx, ngroup, group, n_features,
|
||||
n_features, n_features)] +=
|
||||
margin.empty() ? base_score(0) : margin[idx];
|
||||
});
|
||||
}
|
||||
|
||||
void PredictInstance(const SparsePage::Inst&,
|
||||
|
||||
@@ -80,14 +80,15 @@ void Predictor::InitOutPredictions(const MetaInfo& info, HostDeviceVector<bst_fl
|
||||
if (ctx_->gpu_id >= 0) {
|
||||
out_preds->SetDevice(ctx_->gpu_id);
|
||||
}
|
||||
if (base_margin->Size() != 0) {
|
||||
if (!base_margin->Empty()) {
|
||||
out_preds->Resize(n);
|
||||
ValidateBaseMarginShape(info.base_margin_, info.num_row_, n_classes);
|
||||
out_preds->Copy(*base_margin);
|
||||
} else {
|
||||
out_preds->Resize(n);
|
||||
// cannot rely on the Resize to fill as it might skip if the size is already correct.
|
||||
out_preds->Fill(model.learner_model_param->base_score);
|
||||
out_preds->Resize(n);
|
||||
auto base_score = model.learner_model_param->BaseScore(Context::kCpuId)(0);
|
||||
out_preds->Fill(base_score);
|
||||
}
|
||||
}
|
||||
} // namespace xgboost
|
||||
|
||||
Reference in New Issue
Block a user