This function is mostly for convenience, since it makes it easy to
take an object from a call to cv_sgdnet()
and make predictions based
on a \(\lambda\) chosen from cross-validation results.
# S3 method for cv_sgdnet predict(object, newx, s = c("lambda_1se", "lambda_min"), ...)
object | a fit from |
---|---|
newx | new data to base predictions on |
s |
|
... | arguments passed on to |
Predictions for object
given data in newx
.
set.seed(1) train_ind <- sample(150, 100) fit <- cv_sgdnet(iris[train_ind, 1:4], iris[train_ind, 5], family = "multinomial", nfolds = 5) predict(fit, iris[-train_ind, 1:4], s = "lambda_min", type = "class")#> 1 #> [1,] "setosa" #> [2,] "setosa" #> [3,] "setosa" #> [4,] "setosa" #> [5,] "setosa" #> [6,] "setosa" #> [7,] "setosa" #> [8,] "setosa" #> [9,] "setosa" #> [10,] "setosa" #> [11,] "setosa" #> [12,] "setosa" #> [13,] "setosa" #> [14,] "setosa" #> [15,] "setosa" #> [16,] "setosa" #> [17,] "setosa" #> [18,] "setosa" #> [19,] "versicolor" #> [20,] "versicolor" #> [21,] "versicolor" #> [22,] "versicolor" #> [23,] "versicolor" #> [24,] "versicolor" #> [25,] "versicolor" #> [26,] "versicolor" #> [27,] "versicolor" #> [28,] "versicolor" #> [29,] "versicolor" #> [30,] "versicolor" #> [31,] "versicolor" #> [32,] "versicolor" #> [33,] "virginica" #> [34,] "virginica" #> [35,] "virginica" #> [36,] "virginica" #> [37,] "virginica" #> [38,] "virginica" #> [39,] "versicolor" #> [40,] "virginica" #> [41,] "virginica" #> [42,] "virginica" #> [43,] "virginica" #> [44,] "versicolor" #> [45,] "virginica" #> [46,] "versicolor" #> [47,] "virginica" #> [48,] "virginica" #> [49,] "virginica" #> [50,] "virginica"