forked from gbm-developers/gbm3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgbm.loss.R
35 lines (34 loc) · 1.18 KB
/
gbm.loss.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
gbm.loss <- function(y, f, w, offset, dist, baseline, group=NULL, max.rank=NULL)
{
if (!is.na(offset))
{
f <- offset+f
}
if (dist$name != "pairwise")
{
switch(dist$name,
gaussian = weighted.mean((y - f)^2,w) - baseline,
bernoulli = -2*weighted.mean(y*f - log(1+exp(f)),w) - baseline,
laplace = weighted.mean(abs(y-f),w) - baseline,
adaboost = weighted.mean(exp(-(2*y-1)*f),w) - baseline,
poisson = -2*weighted.mean(y*f-exp(f),w) - baseline,
stop(paste("Distribution",dist$name,"is not yet supported for method=permutation.test.gbm")))
}
else # dist$name == "pairwise"
{
if (is.null(dist$metric))
{
stop("No metric specified for distribution 'pairwise'")
}
if (!is.element(dist$metric, c("conc", "ndcg", "map", "mrr")))
{
stop("Invalid metric '", dist$metric, "' specified for distribution 'pairwise'")
}
if (is.null(group))
{
stop("For distribution 'pairwise', parameter 'group' has to be supplied")
}
# Loss = 1 - utility
(1 - perf.pairwise(y, f, group, dist$metric, w, max.rank)) - baseline
}
}