Predict from a fitted dnn model
Usage
# S3 method for citodnn
predict(
object,
newdata = NULL,
type = c("link", "response", "class"),
device = c("cpu", "cuda", "mps"),
reduce = c("mean", "median", "none"),
...
)
# S3 method for citodnnBootstrap
predict(
object,
newdata = NULL,
type = c("link", "response", "class"),
device = c("cpu", "cuda", "mps"),
reduce = c("mean", "median", "none"),
...
)
Arguments
- object
a model created by
dnn
- newdata
new data for predictions
- type
type of predictions. The default is on the scale of the linear predictor, "response" is on the scale of the response, and "class" means that class predictions are returned (if it is a classification task)
- device
device on which network should be trained on.
- reduce
predictions from bootstrapped model are by default reduced (mean, optional median or none)
- ...
additional arguments
Examples
# \donttest{
if(torch::torch_is_installed()){
library(cito)
set.seed(222)
validation_set<- sample(c(1:nrow(datasets::iris)),25)
# Build and train Network
nn.fit<- dnn(Sepal.Length~., data = datasets::iris[-validation_set,])
# Use model on validation set
predictions <- predict(nn.fit, iris[validation_set,])
# Scatterplot
plot(iris[validation_set,]$Sepal.Length,predictions)
# MAE
mean(abs(predictions-iris[validation_set,]$Sepal.Length))
}
#> Loss at epoch 1: 3.586854, lr: 0.01000
#> Loss at epoch 2: 0.233678, lr: 0.01000
#> Loss at epoch 3: 0.224022, lr: 0.01000
#> Loss at epoch 4: 0.249248, lr: 0.01000
#> Loss at epoch 5: 0.188980, lr: 0.01000
#> Loss at epoch 6: 0.179890, lr: 0.01000
#> Loss at epoch 7: 0.145290, lr: 0.01000
#> Loss at epoch 8: 0.160906, lr: 0.01000
#> Loss at epoch 9: 0.218249, lr: 0.01000
#> Loss at epoch 10: 0.149768, lr: 0.01000
#> Loss at epoch 11: 0.371025, lr: 0.01000
#> Loss at epoch 12: 0.211587, lr: 0.01000
#> Loss at epoch 13: 0.200101, lr: 0.01000
#> Loss at epoch 14: 0.144127, lr: 0.01000
#> Loss at epoch 15: 0.382679, lr: 0.01000
#> Loss at epoch 16: 0.198287, lr: 0.01000
#> Loss at epoch 17: 0.231600, lr: 0.01000
#> Loss at epoch 18: 0.207276, lr: 0.01000
#> Loss at epoch 19: 0.240353, lr: 0.01000
#> Loss at epoch 20: 0.241369, lr: 0.01000
#> Loss at epoch 21: 0.192301, lr: 0.01000
#> Loss at epoch 22: 0.137686, lr: 0.01000
#> Loss at epoch 23: 0.139112, lr: 0.01000
#> Loss at epoch 24: 0.131222, lr: 0.01000
#> Loss at epoch 25: 0.157817, lr: 0.01000
#> Loss at epoch 26: 0.157765, lr: 0.01000
#> Loss at epoch 27: 0.131632, lr: 0.01000
#> Loss at epoch 28: 0.172455, lr: 0.01000
#> Loss at epoch 29: 0.149791, lr: 0.01000
#> Loss at epoch 30: 0.187516, lr: 0.01000
#> Loss at epoch 31: 0.141653, lr: 0.01000
#> Loss at epoch 32: 0.132171, lr: 0.01000
#> Loss at epoch 33: 0.186483, lr: 0.01000
#> Loss at epoch 34: 0.189016, lr: 0.01000
#> Loss at epoch 35: 0.201429, lr: 0.01000
#> Loss at epoch 36: 0.162950, lr: 0.01000
#> Loss at epoch 37: 0.181528, lr: 0.01000
#> Loss at epoch 38: 0.144312, lr: 0.01000
#> Loss at epoch 39: 0.172193, lr: 0.01000
#> Loss at epoch 40: 0.192515, lr: 0.01000
#> Loss at epoch 41: 0.278933, lr: 0.01000
#> Loss at epoch 42: 0.170923, lr: 0.01000
#> Loss at epoch 43: 0.142766, lr: 0.01000
#> Loss at epoch 44: 0.137611, lr: 0.01000
#> Loss at epoch 45: 0.143853, lr: 0.01000
#> Loss at epoch 46: 0.212035, lr: 0.01000
#> Loss at epoch 47: 0.147285, lr: 0.01000
#> Loss at epoch 48: 0.252667, lr: 0.01000
#> Loss at epoch 49: 0.149278, lr: 0.01000
#> Loss at epoch 50: 0.198065, lr: 0.01000
#> Loss at epoch 51: 0.190264, lr: 0.01000
#> Loss at epoch 52: 0.211254, lr: 0.01000
#> Loss at epoch 53: 0.176133, lr: 0.01000
#> Loss at epoch 54: 0.138431, lr: 0.01000
#> Loss at epoch 55: 0.164541, lr: 0.01000
#> Loss at epoch 56: 0.167527, lr: 0.01000
#> Loss at epoch 57: 0.197569, lr: 0.01000
#> Loss at epoch 58: 0.145900, lr: 0.01000
#> Loss at epoch 59: 0.207023, lr: 0.01000
#> Loss at epoch 60: 0.247980, lr: 0.01000
#> Loss at epoch 61: 0.197434, lr: 0.01000
#> Loss at epoch 62: 0.209850, lr: 0.01000
#> Loss at epoch 63: 0.106996, lr: 0.01000
#> Loss at epoch 64: 0.123253, lr: 0.01000
#> Loss at epoch 65: 0.202730, lr: 0.01000
#> Loss at epoch 66: 0.142491, lr: 0.01000
#> Loss at epoch 67: 0.137190, lr: 0.01000
#> Loss at epoch 68: 0.181485, lr: 0.01000
#> Loss at epoch 69: 0.124664, lr: 0.01000
#> Loss at epoch 70: 0.150870, lr: 0.01000
#> Loss at epoch 71: 0.323931, lr: 0.01000
#> Loss at epoch 72: 0.243239, lr: 0.01000
#> Loss at epoch 73: 0.106061, lr: 0.01000
#> Loss at epoch 74: 0.222324, lr: 0.01000
#> Loss at epoch 75: 0.132279, lr: 0.01000
#> Loss at epoch 76: 0.128675, lr: 0.01000
#> Loss at epoch 77: 0.137400, lr: 0.01000
#> Loss at epoch 78: 0.180058, lr: 0.01000
#> Loss at epoch 79: 0.170246, lr: 0.01000
#> Loss at epoch 80: 0.179324, lr: 0.01000
#> Loss at epoch 81: 0.123262, lr: 0.01000
#> Loss at epoch 82: 0.132939, lr: 0.01000
#> Loss at epoch 83: 0.115004, lr: 0.01000
#> Loss at epoch 84: 0.166284, lr: 0.01000
#> Loss at epoch 85: 0.144304, lr: 0.01000
#> Loss at epoch 86: 0.162562, lr: 0.01000
#> Loss at epoch 87: 0.235232, lr: 0.01000
#> Loss at epoch 88: 0.142425, lr: 0.01000
#> Loss at epoch 89: 0.171156, lr: 0.01000
#> Loss at epoch 90: 0.149908, lr: 0.01000
#> Loss at epoch 91: 0.137795, lr: 0.01000
#> Loss at epoch 92: 0.134873, lr: 0.01000
#> Loss at epoch 93: 0.178529, lr: 0.01000
#> Loss at epoch 94: 0.263008, lr: 0.01000
#> Loss at epoch 95: 0.169682, lr: 0.01000
#> Loss at epoch 96: 0.153956, lr: 0.01000
#> Loss at epoch 97: 0.151924, lr: 0.01000
#> Loss at epoch 98: 0.149321, lr: 0.01000
#> Loss at epoch 99: 0.123444, lr: 0.01000
#> Loss at epoch 100: 0.104437, lr: 0.01000
#> [1] 0.238509
# }