Neural Networks using nnet

nn(
  dataset,
  rvar,
  evar,
  type = "classification",
  lev = "",
  size = 1,
  decay = 0.5,
  wts = "None",
  seed = NA,
  check = "standardize",
  form,
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

rvar

The response variable in the model

evar

Explanatory variables in the model

type

Model type (i.e., "classification" or "regression")

lev

The level in the response variable defined as _success_

size

Number of units (nodes) in the hidden layer

decay

Parameter decay

wts

Weights to use in estimation

seed

Random seed to use as the starting point

check

Optional estimation parameters ("standardize" is the default)

form

Optional formula to use instead of rvar and evar

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list with all variables defined in nn as an object of class nn

Details

See https://radiant-rstats.github.io/docs/model/nn.html for an example in Radiant

See also

summary.nn to summarize results

plot.nn to plot results

predict.nn for prediction

Examples

nn(titanic, "survived", c("pclass", "sex"), lev = "Yes") %>% summary()
#> Neural Network #> Activation function : Logistic (classification) #> Data : titanic #> Response variable : survived #> Level : Yes in survived #> Explanatory variables: pclass, sex #> Network size : 1 #> Parameter decay : 0.5 #> Network : 3-1-1 with 6 weights #> Nr obs : 1,043 #> Weights : #> b->h1 i1->h1 i2->h1 i3->h1 #> -1.93 0.90 2.46 3.12 #> b->o h1->o #> 2.94 -4.73
nn(titanic, "survived", c("pclass", "sex")) %>% str()
#> List of 20 #> $ coefnames : chr [1:3] "pclass|2nd" "pclass|3rd" "sex|male" #> $ model :List of 21 #> ..$ n : num [1:3] 3 1 1 #> ..$ nunits : int 6 #> ..$ nconn : num [1:7] 0 0 0 0 0 4 6 #> ..$ conn : num [1:6] 0 1 2 3 0 4 #> ..$ nsunits : int 6 #> ..$ decay : num 0.5 #> ..$ entropy : logi TRUE #> ..$ softmax : logi FALSE #> ..$ censored : logi FALSE #> ..$ value : num 515 #> ..$ wts : num [1:6] -1.931 0.903 2.463 3.119 2.941 ... #> ..$ convergence : int 0 #> ..$ fitted.values: num [1:1043, 1] 0.912 0.336 0.912 0.336 0.912 ... #> .. ..- attr(*, "dimnames")=List of 2 #> .. .. ..$ : chr [1:1043] "1" "2" "3" "4" ... #> .. .. ..$ : NULL #> ..$ residuals : Named num [1:1043] 0.0877 0.6639 -0.9123 -0.3361 -0.9123 ... #> .. ..- attr(*, "names")= chr [1:1043] "1" "2" "3" "4" ... #> ..$ lev : chr [1:2] "0" "1" #> ..$ call : language nnet.formula(formula = survived ~ ., data = list(survived = c(TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE| __truncated__ ... #> ..$ terms :Classes 'terms', 'formula' language survived ~ pclass + sex #> .. .. ..- attr(*, "variables")= language list(survived, pclass, sex) #> .. .. ..- attr(*, "factors")= int [1:3, 1:2] 0 1 0 0 0 1 #> .. .. .. ..- attr(*, "dimnames")=List of 2 #> .. .. .. .. ..$ : chr [1:3] "survived" "pclass" "sex" #> .. .. .. .. ..$ : chr [1:2] "pclass" "sex" #> .. .. ..- attr(*, "term.labels")= chr [1:2] "pclass" "sex" #> .. .. ..- attr(*, "order")= int [1:2] 1 1 #> .. .. ..- attr(*, "intercept")= int 1 #> .. .. ..- attr(*, "response")= int 1 #> .. .. ..- attr(*, ".Environment")=<environment: 0x12141108> #> .. .. ..- attr(*, "predvars")= language list(survived, pclass, sex) #> .. .. ..- attr(*, "dataClasses")= Named chr [1:3] "logical" "factor" "factor" #> .. .. .. ..- attr(*, "names")= chr [1:3] "survived" "pclass" "sex" #> ..$ coefnames : chr [1:3] "pclass2nd" "pclass3rd" "sexmale" #> ..$ contrasts :List of 2 #> .. ..$ pclass: chr "contr.treatment" #> .. ..$ sex : chr "contr.treatment" #> ..$ xlevels :List of 2 #> .. ..$ pclass: chr [1:3] "1st" "2nd" "3rd" #> .. ..$ sex : chr [1:2] "female" "male" #> ..$ model : tibble [1,043 × 3] (S3: tbl_df/tbl/data.frame) #> .. ..$ survived: logi [1:1043] TRUE TRUE FALSE FALSE FALSE TRUE ... #> .. ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> .. ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> .. ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> ..- attr(*, "class")= chr [1:2] "nnet.formula" "nnet" #> $ nninput :List of 11 #> ..$ formula:Class 'formula' language survived ~ . #> .. .. ..- attr(*, ".Environment")=<environment: 0x12141108> #> ..$ rang : num 0.1 #> ..$ size : num 1 #> ..$ decay : num 0.5 #> ..$ weights: NULL #> ..$ maxit : num 10000 #> ..$ linout : logi FALSE #> ..$ entropy: logi TRUE #> ..$ skip : logi FALSE #> ..$ trace : logi FALSE #> ..$ data : tibble [1,043 × 3] (S3: tbl_df/tbl/data.frame) #> .. ..$ survived: logi [1:1043] TRUE TRUE FALSE FALSE FALSE TRUE ... #> .. ..$ pclass : Factor w/ 3 levels "1st","2nd","3rd": 1 1 1 1 1 1 1 1 1 1 ... #> .. ..$ sex : Factor w/ 2 levels "female","male": 1 2 1 2 1 2 1 2 1 2 ... #> .. ..- attr(*, "description")= chr "## Titanic\n\nThis dataset describes the survival status of individual passengers on the Titanic. The titanic d"| __truncated__ #> $ entropy : logi TRUE #> $ linout : logi FALSE #> $ rv : Factor w/ 2 levels "Yes","No": 1 1 2 2 2 1 1 2 1 2 ... #> $ not_vary : chr(0) #> $ df_name : chr "titanic" #> $ vars : chr [1:2] "pclass" "sex" #> $ rvar : chr "survived" #> $ evar : chr [1:2] "pclass" "sex" #> $ type : chr "classification" #> $ lev : chr "Yes" #> $ size : num 1 #> $ decay : num 0.5 #> $ wts : NULL #> $ seed : chr NA #> $ check : chr "standardize" #> $ form :Class 'formula' language survived ~ . #> .. ..- attr(*, ".Environment")=<environment: 0x12141108> #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:3] "nn" "model" "list"
nn(diamonds, "price", c("carat", "clarity"), type = "regression") %>% summary()
#> Neural Network #> Activation function : Linear (regression) #> Data : diamonds #> Response variable : price #> Explanatory variables: carat, clarity #> Network size : 1 #> Parameter decay : 0.5 #> Network : 8-1-1 with 11 weights #> Nr obs : 3,000 #> Weights : #> b->h1 i1->h1 i2->h1 i3->h1 i4->h1 i5->h1 i6->h1 i7->h1 i8->h1 #> -1.71 2.01 0.31 0.50 0.69 0.76 0.96 0.94 1.01 #> b->o h1->o #> -0.72 2.56