The main purpose of this function is internal use within cv_sgdnet()
,
where it is used to score the performance over folds in cross-validation.
It can, however, be used on its own to measure performance against a
validation set, for instance by training the model via cv_sgdnet()
and holding out a validation set for
use with this function.
score(fit, ...) # S3 method for sgdnet_gaussian score(fit, x, y, type.measure = c("deviance", "mse", "mae"), s = fit$lambda, ...) # S3 method for sgdnet_binomial score(fit, x, y, type.measure = c("deviance", "mse", "mae", "class", "auc"), s = fit$lambda, ...) # S3 method for sgdnet_multinomial score(fit, x, y, type.measure = c("deviance", "mse", "mae", "class"), s = fit$lambda, ...) # S3 method for sgdnet_mgaussian score(fit, x, y, type.measure = c("deviance", "mse", "mae"), s = fit$lambda, ...) # S3 method for cv_sgdnet score(fit, x, y, type.measure, s = c("lambda_1se", "lambda_min"), ...)
fit | the model fit |
---|---|
... | arguments passed on to |
x | a feature matrix of new data |
y | response(s) for new data |
type.measure | the type of measure |
s | lambda |
Returns the prediction error along the lambda path.
set.seed(1) n <- nrow(wine$x) train_ind <- sample(n, floor(0.8*n)) cv_fit <- cv_sgdnet(wine$x[train_ind, ], wine$y[train_ind], family = "multinomial", nfolds = 5, alpha = c(0.5, 1)) score(cv_fit, wine$x[-train_ind, ], wine$y[-train_ind], "deviance")#> 1 #> 0.2717494