Description Usage Arguments Value Author(s) See Also Examples
Predictions for sgdnet Models
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## S3 method for class 'sgdnet'
predict(object, newx = NULL, s = NULL, type,
exact = FALSE, newoffset = NULL, ...)
## S3 method for class 'sgdnet_gaussian'
predict(object, newx = NULL, s = NULL,
type = c("link", "response", "coefficients", "nonzero"),
exact = FALSE, newoffset = NULL, ...)
## S3 method for class 'sgdnet_binomial'
predict(object, newx = NULL, s = NULL,
type = c("link", "response", "coefficients", "nonzero", "class"),
exact = FALSE, newoffset = NULL, ...)
## S3 method for class 'sgdnet_multinomial'
predict(object, newx = NULL, s = NULL,
type = c("link", "response", "coefficients", "nonzero", "class"),
exact = FALSE, newoffset = NULL, ...)
## S3 method for class 'sgdnet_mgaussian'
predict(object, newx = NULL, s = NULL,
type = c("link", "response", "coefficients", "nonzero"),
exact = FALSE, newoffset = NULL, ...)
|
object |
an object of class |
newx |
new data to predict on. Must be provided if |
s |
the lambda penalty value on which to base the predictions. |
type |
type of prediction to return, one of
|
exact |
if the given value of |
newoffset |
if an offset was used in the call to |
... |
arguments to be passed on to |
Predictions for object
given data in newx
.
Jerome Friedman, Trevor Hastie, Rob Tibshirani, Noah Simon (original), Johan Larsson (modifications)
sgdnet()
, coef.sgdnet()
, predict.cv_sgdnet()
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 36 37 38 39 40 41 42 43 | # Gaussian
# Split into training and test sets
n <- length(abalone$y)
train_ind <- sample(n, size = floor(0.8 * n))
# Fit the model using the training set
fit_gaussian <- sgdnet(abalone$x[train_ind, ], abalone$y[train_ind])
# Predict using the test set
pred_gaussian <- predict(fit_gaussian, newx = abalone$x[-train_ind, ])
# Mean absolute prediction error along regularization path
mae <- 1/(n - length(train_ind)) *
colSums(abs(abalone$y[-train_ind] - pred_gaussian))
# Binomial
n <- length(heart$y)
train_ind <- sample(n, size = floor(0.8 * n))
fit_binomial <- sgdnet(heart$x[train_ind, ],
heart$y[train_ind],
family = "binomial")
# Predict classes at custom lambda value (s) using linear interpolation
predict(fit_binomial, heart$x[-train_ind, ], type = "class", s = 1/n)
# Multinomial
n <- length(wine$y)
train_ind <- sample(n, size = floor(0.8 * n))
fit_multinomial <- sgdnet(wine$x[train_ind, ],
wine$y[train_ind],
family = "multinomial",
alpha = 0.25)
predict(fit_multinomial,
wine$x[-train_ind, ],
s = 0.0001,
exact = TRUE,
type = "class")
# Multivariate gaussian regression, predict nonzero coefficients
fit_mgaussian <- sgdnet(student$x, student$y, family = "mgaussian")
predict(fit_mgaussian, type = "nonzero")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.