Skip to content

Fits a single-hidden-layer neural network regression on a 'tidyFit' R6 class. The function can be used with regress and classify.

Usage

# S3 method for nnet
.fit(self, data = NULL)

Arguments

self

a 'tidyFit' R6 class.

data

a data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

Value

A fitted 'tidyFit' class model.

Details

Hyperparameters:

  • size (number of units in the hidden layer)

  • decay (parameter for weight decay)

  • maxit (maximum number of iterations)

Important method arguments (passed to m)

The function provides a wrapper for nnet::nnet.formula. See ?nnet for more details.

Implementation

For regress, linear output units (linout=True) are used, while classify implements the default logic of nnet (entropy=TRUE for 2 target classes and softmax=TRUE for more classes).

Author

Phil Holzmeister

Examples

# Load data
data <- tidyfit::Factor_Industry_Returns

# Stand-alone function
fit <- m("nnet", Return ~ ., data)
fit
#> # A tibble: 1 × 5
#>   estimator_fct `size (MB)` grid_id  model_object settings        
#>   <chr>               <dbl> <chr>    <list>       <list>          
#> 1 nnet::nnet           1.84 #0010000 <tidyFit>    <tibble [1 × 3]>

# Within 'regress' function
fit <- regress(data, Return ~ ., m("nnet", decay=0.5, size = 8),
               .mask = c("Date", "Industry"))

# Within 'classify' function
fit <- classify(iris, Species ~ ., m("nnet", decay=0.5, size = 8))