nnet: Interfaces for nnet package for data science pipelines.

Description Usage Arguments Details Value Author(s) Examples

Description

Interfaces to nnet functions that can be used in a pipeline implemented by magrittr.

Usage

1
2

Arguments

data

data frame, tibble, list, ...

...

Other arguments passed to the corresponding interfaced function.

Details

Interfaces call their corresponding interfaced function.

Value

Object returned by interfaced function.

Author(s)

Roberto Bertolusso

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
## Not run: 
library(intubate)
library(magrittr)
library(nnet)

## multinom
options(contrasts = c("contr.treatment", "contr.poly"))
library(MASS)
example(birthwt)

## Original function to interface
multinom(low ~ ., bwt)

## The interface reverses the order of data and formula
ntbt_multinom(bwt, low ~ .)

## so it can be used easily in a pipeline.
bwt %>%
  ntbt_multinom(low ~ .)

## nnet
ir <- rbind(iris3[,,1],iris3[,,2],iris3[,,3])
targets <- class.ind( c(rep("s", 50), rep("c", 50), rep("v", 50)))
set.seed(6789) ## for reproducible results
samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25))
ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]),
                  species = factor(c(rep("s",50), rep("c", 50), rep("v", 50))))

## Original function to interface
set.seed(12345) ## for reproducible results
nnet(species ~ ., data = ird, subset = samp,
     size = 2, rang = 0.1, decay = 5e-4, maxit = 200)

## The interface reverses the order of data and formula
set.seed(12345) ## for reproducible results
ntbt_nnet(data = ird, species ~ ., subset = samp,
          size = 2, rang = 0.1, decay = 5e-4, maxit = 200)

## so it can be used easily in a pipeline.
set.seed(12345) ## for reproducible results
ird %>%
  ntbt_nnet(species ~ ., subset = samp,
            size = 2, rang = 0.1, decay = 5e-4, maxit = 200)

## End(Not run)

Example output

brthwt> bwt <- with(birthwt, {
brthwt+ race <- factor(race, labels = c("white", "black", "other"))
brthwt+ ptd <- factor(ptl > 0)
brthwt+ ftv <- factor(ftv)
brthwt+ levels(ftv)[-(1:2)] <- "2+"
brthwt+ data.frame(low = factor(low), age, lwt, race, smoke = (smoke > 0),
brthwt+            ptd, ht = (ht > 0), ui = (ui > 0), ftv)
brthwt+ })

brthwt> options(contrasts = c("contr.treatment", "contr.poly"))

brthwt> glm(low ~ ., binomial, bwt)

Call:  glm(formula = low ~ ., family = binomial, data = bwt)

Coefficients:
(Intercept)          age          lwt    raceblack    raceother    smokeTRUE  
    0.82302     -0.03723     -0.01565      1.19241      0.74068      0.75553  
    ptdTRUE       htTRUE       uiTRUE         ftv1        ftv2+  
    1.34376      1.91317      0.68020     -0.43638      0.17901  

Degrees of Freedom: 188 Total (i.e. Null);  178 Residual
Null Deviance:	    234.7 
Residual Deviance: 195.5 	AIC: 217.5
# weights:  12 (11 variable)
initial  value 131.004817 
iter  10 value 98.029803
final  value 97.737759 
converged
Call:
multinom(formula = low ~ ., data = bwt)

Coefficients:
(Intercept)         age         lwt   raceblack   raceother   smokeTRUE 
 0.82320102 -0.03723828 -0.01565359  1.19240391  0.74065606  0.75550487 
    ptdTRUE      htTRUE      uiTRUE        ftv1       ftv2+ 
 1.34375901  1.91320116  0.68020207 -0.43638470  0.17900392 

Residual Deviance: 195.4755 
AIC: 217.4755 
# weights:  12 (11 variable)
initial  value 131.004817 
iter  10 value 98.029803
final  value 97.737759 
converged
Call:
multinom(formula = low ~ ., data = bwt)

Coefficients:
(Intercept)         age         lwt   raceblack   raceother   smokeTRUE 
 0.82320102 -0.03723828 -0.01565359  1.19240391  0.74065606  0.75550487 
    ptdTRUE      htTRUE      uiTRUE        ftv1       ftv2+ 
 1.34375901  1.91320116  0.68020207 -0.43638470  0.17900392 

Residual Deviance: 195.4755 
AIC: 217.4755 
# weights:  12 (11 variable)
initial  value 131.004817 
iter  10 value 98.029803
final  value 97.737759 
converged
Call:
multinom(formula = low ~ ., data = .)

Coefficients:
(Intercept)         age         lwt   raceblack   raceother   smokeTRUE 
 0.82320102 -0.03723828 -0.01565359  1.19240391  0.74065606  0.75550487 
    ptdTRUE      htTRUE      uiTRUE        ftv1       ftv2+ 
 1.34375901  1.91320116  0.68020207 -0.43638470  0.17900392 

Residual Deviance: 195.4755 
AIC: 217.4755 
# weights:  19
initial  value 82.461465 
iter  10 value 22.247391
iter  20 value 7.566993
iter  30 value 5.849848
iter  40 value 5.214272
iter  50 value 4.436323
iter  60 value 1.807985
iter  70 value 1.194316
iter  80 value 1.152826
iter  90 value 1.140506
iter 100 value 1.137393
iter 110 value 1.135124
iter 120 value 1.134293
iter 130 value 1.134165
iter 140 value 1.134094
iter 150 value 1.134039
iter 160 value 1.134019
iter 170 value 1.134017
iter 180 value 1.134015
iter 190 value 1.134014
final  value 1.134013 
converged
a 4-2-3 network with 19 weights
inputs: Sepal.L. Sepal.W. Petal.L. Petal.W. 
output(s): species 
options were - softmax modelling  decay=5e-04
# weights:  19
initial  value 82.461465 
iter  10 value 22.247391
iter  20 value 7.566993
iter  30 value 5.849848
iter  40 value 5.214272
iter  50 value 4.436323
iter  60 value 1.807985
iter  70 value 1.194316
iter  80 value 1.152826
iter  90 value 1.140506
iter 100 value 1.137393
iter 110 value 1.135124
iter 120 value 1.134293
iter 130 value 1.134165
iter 140 value 1.134094
iter 150 value 1.134039
iter 160 value 1.134019
iter 170 value 1.134017
iter 180 value 1.134015
iter 190 value 1.134014
final  value 1.134013 
converged
a 4-2-3 network with 19 weights
inputs: Sepal.L. Sepal.W. Petal.L. Petal.W. 
output(s): species 
options were - softmax modelling  decay=5e-04
# weights:  19
initial  value 82.461465 
iter  10 value 22.247391
iter  20 value 7.566993
iter  30 value 5.849848
iter  40 value 5.214272
iter  50 value 4.436323
iter  60 value 1.807985
iter  70 value 1.194316
iter  80 value 1.152826
iter  90 value 1.140506
iter 100 value 1.137393
iter 110 value 1.135124
iter 120 value 1.134293
iter 130 value 1.134165
iter 140 value 1.134094
iter 150 value 1.134039
iter 160 value 1.134019
iter 170 value 1.134017
iter 180 value 1.134015
iter 190 value 1.134014
final  value 1.134013 
converged
a 4-2-3 network with 19 weights
inputs: Sepal.L. Sepal.W. Petal.L. Petal.W. 
output(s): species 
options were - softmax modelling  decay=5e-04

intubate documentation built on May 2, 2019, 2:46 p.m.