Skip to content

Extract Model Coefficients

Usage

# S3 method for brulee_logistic_reg
coef(object, epoch = NULL, ...)

# S3 method for brulee_linear_reg
coef(object, epoch = NULL, ...)

# S3 method for brulee_mlp
coef(object, epoch = NULL, ...)

# S3 method for brulee_multinomial_reg
coef(object, epoch = NULL, ...)

Arguments

object

A model fit from brulee.

epoch

A single integer for the training iteration. If left NULL, the estimates from the best model fit (via internal performance metrics).

...

Not currently used.

Value

For logistic/linear regression, a named vector. For neural networks, a list of arrays.

Examples

# \donttest{
if (torch::torch_is_installed()) {

 data(ames, package = "modeldata")

 ames$Sale_Price <- log10(ames$Sale_Price)

 set.seed(1)
 in_train <- sample(1:nrow(ames), 2000)
 ames_train <- ames[ in_train,]
 ames_test  <- ames[-in_train,]

 # Using recipe
 library(recipes)

 ames_rec <-
  recipe(Sale_Price ~ Longitude + Latitude, data = ames_train) %>%
    step_normalize(all_numeric_predictors())

 set.seed(2)
 fit <- brulee_linear_reg(ames_rec, data = ames_train,
                           epochs = 50, batch_size = 32)

 coef(fit)
 coef(fit, epoch = 1)
}
#> Warning: 'batch_size' is only used for the SGD optimizer.
#> (Intercept)   Longitude    Latitude 
#>  5.22475100 -0.05370793  0.05004641 
# }