pcaNNet: Neural Networks with a Principal Component Step

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Run PCA on a dataset, then use it in a neural network model

Usage

1
2
3
4
5
6
7
8
## Default S3 method:
pcaNNet(x, y, thresh = 0.99, ...)
## S3 method for class 'formula'
pcaNNet(formula, data, weights, ..., 
        thresh = .99, subset, na.action, contrasts = NULL)

## S3 method for class 'pcaNNet'
predict(object, newdata, type = c("raw", "class"), ...)

Arguments

formula

A formula of the form class ~ x1 + x2 + ...

x

matrix or data frame of x values for examples.

y

matrix or data frame of target values for examples.

weights

(case) weights for each example – if missing defaults to 1.

thresh

a threshold for the cumulative proportion of variance to capture from the PCA analysis. For example, to retain enough PCA components to capture 95 percent of variation, set thresh = .95

data

Data frame from which variables specified in formula are preferentially to be taken.

subset

An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.)

na.action

A function to specify the action to be taken if NAs are found. The default action is for the procedure to fail. An alternative is na.omit, which leads to rejection of cases with missing values on any required variable. (NOTE: If given, this argument must be named.)

contrasts

a list of contrasts to be used for some or all of the factors appearing as variables in the model formula.

object

an object of class pcaNNet as returned by pcaNNet.

newdata

matrix or data frame of test examples. A vector is considered to be a row vector comprising a single case.

type

Type of output

...

arguments passed to nnet

Details

The function first will run principal component analysis on the data. The cumulative percentage of variance is computed for each principal component. The function uses the thresh argument to determine how many components must be retained to capture this amount of variance in the predictors.

The principal components are then used in a neural network model.

When predicting samples, the new data are similarly transformed using the information from the PCA analysis on the training data and then predicted.

Because the variance of each predictor is used in the PCA analysis, the code does a quick check to make sure that each predictor has at least two distinct values. If a predictor has one unique value, it is removed prior to the analysis.

Value

For pcaNNet, an object of "pcaNNet" or "pcaNNet.formula". Items of interest in the output are:

pc

the output from preProcess

model

the model generated from nnet

names

if any predictors had only one distinct value, this is a character string of the remaining columns. Otherwise a value of NULL

Author(s)

These are heavily based on the nnet code from Brian Ripley.

References

Ripley, B. D. (1996) Pattern Recognition and Neural Networks. Cambridge.

See Also

nnet, preProcess

Examples

1
2
3
4
5
data(BloodBrain)
modelFit <- pcaNNet(bbbDescr[, 1:10], logBBB, size = 5, linout = TRUE, trace = FALSE)
modelFit

predict(modelFit, bbbDescr[, 1:10])

Example output

Loading required package: lattice
Loading required package: ggplot2
Neural Network Model with PCA Pre-Processing

Created from 208 samples and 10 variables
PCA needed 9 components to capture 99 percent of the variance

a 9-5-1 network with 56 weights
options were - linear output units 

             [,1]
1    0.2159740690
2   -0.4940397843
3   -0.3189546805
4   -0.3189546805
5    0.6644140268
6    0.2984668589
7   -0.4940397843
8    0.6644140268
9    0.6637908931
10   0.8809244764
11   0.8480413725
12   0.6643960277
13   0.6644140268
14  -1.4774084917
15  -0.4940397843
16  -0.4940397843
17  -0.1097359522
18  -0.7717542849
19   0.2984664369
20  -0.2474263481
21  -0.3079830492
22   0.6644140268
23   0.6644140268
24   0.6644140268
25  -0.3222436969
26   0.8809244764
27   0.2984664369
28  -1.1114609017
29   0.6644140268
30   0.5905638048
31  -0.4940397843
32  -1.8442186388
33  -0.7712287401
34  -0.3189546805
35   0.6644140268
36   0.6644140268
37   0.0013889970
38  -0.4940397843
39   0.6644140268
40   0.0817745174
41   0.8791014434
42  -0.4940397843
43   0.2159740690
44   0.6644140268
45  -1.0289685339
46   0.6643935264
47  -0.3189546805
48   0.6644140268
49   0.6644140268
50   0.6644140268
51   0.6644140268
52   0.6644140268
53  -0.3189546805
54   0.6644140268
55   0.6644140268
56   0.2367931066
57  -0.3189546805
58  -0.4940397843
59  -0.4940397843
60  -0.4940397843
61  -0.4940397843
62   0.2159740690
63   0.3259348364
64  -0.3189546805
65  -0.3189546805
66   0.6644140268
67   0.6644140268
68  -0.3189546805
69   0.2159740690
70   0.6644140268
71   0.6644140268
72   0.6643812610
73   0.6644140268
74   0.6644140268
75   0.6644140268
76  -0.4463456994
77  -0.3189546805
78   1.0084687002
79   0.2159740690
80  -0.4940397843
81  -0.0250059763
82   0.6644140268
83   0.5798620703
84   0.8806635605
85  -0.0009665261
86   0.6644140268
87  -0.9329167365
88   0.2159740690
89   0.8903087390
90   0.6644140268
91   0.8463490504
92   0.6644091233
93  -0.0005363805
94  -0.9566188736
95   0.6644140268
96   0.2984664369
97  -0.0005363805
98  -0.0005558975
99   0.2978661798
100  0.2159740690
101  0.1457987686
102  0.6644140268
103 -0.3664883018
104  0.5999708393
105  0.1180847156
106 -1.3973611386
107  0.0093211718
108 -0.4940397843
109 -0.4940397843
110  0.6644140268
111  0.6644140268
112 -1.4774084917
113 -0.3189546805
114 -0.3664839705
115 -0.4940397843
116  0.2984664369
117  0.2984664369
118 -0.3658343984
119  0.2981620726
120  0.2984664369
121 -0.4940397843
122  0.6644140268
123 -1.4774084917
124 -0.4940397843
125  0.2159740690
126  0.2159740690
127 -0.4940397843
128  0.0132987861
129  0.2159740690
130  0.6644140268
131  0.6644140268
132  0.6644140268
133  0.6644140268
134 -0.4940397843
135  0.6644140268
136 -0.0005363805
137 -1.4774084917
138 -0.8315896254
139 -0.0005363805
140 -0.4940397843
141 -0.4940397843
142  0.6644140268
143 -1.4773319765
144  0.6644140268
145  0.2159740690
146  0.6644140268
147 -1.1113987768
148  0.6644140268
149  0.2159740690
150 -0.3164284513
151 -0.4940397843
152  0.4869327550
153  0.2159740690
154 -0.3164284513
155 -0.3664839705
156 -0.4940397843
157 -0.4940397843
158 -1.0275683046
159 -0.4940397843
160  0.2159740690
161 -0.4940397843
162  0.6644140268
163 -0.4940397843
164 -0.4940397843
165 -0.3664839705
166  0.6644140268
167 -0.3189546805
168 -0.3181413821
169  0.2159740690
170  0.6168581445
171 -0.4940397843
172 -0.4940397843
173  0.1709115855
174  0.4893538399
175 -0.3119173564
176 -1.1114609017
177 -0.4940397843
178 -0.3189546805
179  0.6168413512
180 -0.4940397843
181 -1.4774084917
182 -1.4774084917
183 -1.4774084917
184 -1.4774084917
185 -1.4774084917
186 -1.4774084917
187 -1.0911204351
188 -0.4940397843
189  0.6644140268
190 -0.4940397843
191 -0.4940397843
192  0.8818371166
193  0.8809244764
194 -0.0005360343
195  0.6644140268
196 -0.4940397843
197 -0.3189546805
198 -0.8124088979
199  0.0684805609
200  0.6644140268
201  0.6644140268
202 -1.4774084917
203 -0.3162759647
204 -0.0387525927
205  0.6644140268
206  0.2383560728
207 -0.4940397843
208  0.2159740690

caret documentation built on May 2, 2019, 5:47 p.m.

Related to pcaNNet in caret...