Description Usage Arguments Examples
View source: R/dcaiman.train.R
Function to train a D-CAIMAN model.
1 | dcaiman.train(y, xtrain, xvalidation, grid)
|
y |
Label. Must be a factor. |
xtrain |
train dataset |
xvalidation |
validation dataset define an \alpha (see details) with cross-validation |
grid |
values of \alpha |
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 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (y, xtrain, xvalidation, grid)
{
classes = levels(y)
df = xtrain %>% as.data.frame()
df$y = y
a = grid
xtx = .genXtX(df, classes)
centroidx = .genCentroide(df, classes)
k = .genEspace(df, classes) %>% as.data.frame()
k$y = y
xtxk = .genXtX(k, classes)
centroidk = .genCentroide(k, classes)
valx = (levels(y), x = xvalidation, xxt = xtx,
m = centroidx)
valy = (levels(y), x = valx, xxt = xtk, m = centroidk)
erro = numeric(length(a))
for (i in seq_along(a)) {
valfinal = a[i] * valx + (1 - a[i]) * valy
erro[i] = mean(validacao$V58 != genmin(levels(y), valfinal))
}
afinal = a[which.min(erro)]
return(list(xtx = xtx, xtk = xtk, cx = centroidx, ck = centroidk,
a = afinal, classes = classes))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.