Summary of a fitted neuralGAM
object. Prints
the distribution family, model formula, intercept value, sample size,
as well as neural network architecture and training history.
# S3 method for class 'neuralGAM'
summary(object, ...)
The summary of the object:
Distribution family
Formula
Intercept value
Mean Squared Error (MSE)
Training sample size
Training History
Model Architecture
# \dontrun{
n <- 24500
seed <- 42
set.seed(seed)
x1 <- runif(n, -2.5, 2.5)
x2 <- runif(n, -2.5, 2.5)
x3 <- runif(n, -2.5, 2.5)
f1 <-x1**2
f2 <- 2*x2
f3 <- sin(x3)
f1 <- f1 - mean(f1)
f2 <- f2 - mean(f2)
f3 <- f3 - mean(f3)
eta0 <- 2 + f1 + f2 + f3
epsilon <- rnorm(n, 0.25)
y <- eta0 + epsilon
train <- data.frame(x1, x2, x3, y)
library(neuralGAM)
ngam <- neuralGAM(y ~ s(x1) + x2 + s(x3), data = train,
num_units = 1024, family = "gaussian",
activation = "relu",
learning_rate = 0.001, bf_threshold = 0.001,
max_iter_backfitting = 10, max_iter_ls = 10,
seed = seed
)
#> [1] "Initializing neuralGAM..."
#> [1] "BACKFITTING Iteration 1 - Current Err = 0.32048205436 BF Threshold = 0.001 Converged = FALSE"
#> [1] "BACKFITTING Iteration 2 - Current Err = 0.000623513488713123 BF Threshold = 0.001 Converged = TRUE"
summary(ngam)
#> Class: neuralGAM
#>
#> Distribution Family: gaussian
#> Formula: y ~ s(x1) + x2 + s(x3)
#> Intercept: 2.2215
#> MSE: 1.0049
#> Sample size: 24500
#>
#> Training History:
#>
#> Timestamp Model Epoch TrainLoss
#> 1 2024-09-13 13:11:55 x1 1 1.8522
#> 2 2024-09-13 13:11:56 x3 1 1.0335
#> 3 2024-09-13 13:11:59 x1 2 1.0201
#> 4 2024-09-13 13:12:01 x3 2 1.0151
#>
#>
#> Model architecture:
#>
#> $x1
#> Model: "x1"
#> ________________________________________________________________________________
#> Layer (type) Output Shape Param #
#> ================================================================================
#> dense_30 (Dense) (None, 1) 2
#> dense_31 (Dense) (None, 1024) 2048
#> dense_32 (Dense) (None, 1) 1025
#> ================================================================================
#> Total params: 3075 (12.01 KB)
#> Trainable params: 3075 (12.01 KB)
#> Non-trainable params: 0 (0.00 Byte)
#> ________________________________________________________________________________
#>
#> $x3
#> Model: "x3"
#> ________________________________________________________________________________
#> Layer (type) Output Shape Param #
#> ================================================================================
#> dense_33 (Dense) (None, 1) 2
#> dense_34 (Dense) (None, 1024) 2048
#> dense_35 (Dense) (None, 1) 1025
#> ================================================================================
#> Total params: 3075 (12.01 KB)
#> Trainable params: 3075 (12.01 KB)
#> Non-trainable params: 0 (0.00 Byte)
#> ________________________________________________________________________________
#>
#>
#> Linear model:
#> (Intercept) x2
#> 2.221469 1.981508
# }