Run PCA on a dataset, then use it in a neural network model
pcaNNet(x, ...)# S3 method for formula
pcaNNet(formula, data, weights, ..., thresh = 0.99,
subset, na.action, contrasts = NULL)
# S3 method for default
pcaNNet(x, y, thresh = 0.99, ...)
# S3 method for pcaNNet
print(x, ...)
# S3 method for pcaNNet
predict(object, newdata, type = c("raw", "class",
"prob"), ...)
matrix or data frame of x
values for examples.
arguments passed to nnet
, such as
size
, decay
, etc.
A formula of the form class ~ x1 + x2 + …{}
Data frame from which variables specified in formula
are
preferentially to be taken.
(case) weights for each example - if missing defaults to 1.
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
An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.)
A function to specify the action to be taken if NA
s
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.)
a list of contrasts to be used for some or all of the factors appearing as variables in the model formula.
matrix or data frame of target values for examples.
an object of class pcaNNet
as returned by
pcaNNet
.
matrix or data frame of test examples. A vector is considered to be a row vector comprising a single case.
Type of output
For pcaNNet
, an object of "pcaNNet"
or
"pcaNNet.formula"
. Items of interest in the output are:
the output from preProcess
the model
generated from nnet
if any predictors had
only one distinct value, this is a character string of the remaining
columns. Otherwise a value of NULL
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.
Ripley, B. D. (1996) Pattern Recognition and Neural Networks. Cambridge.
# NOT RUN {
data(BloodBrain)
modelFit <- pcaNNet(bbbDescr[, 1:10], logBBB, size = 5, linout = TRUE, trace = FALSE)
modelFit
predict(modelFit, bbbDescr[, 1:10])
# }
Run the code above in your browser using DataLab