简体   繁体   中英

Preprocess from caret package

I was given 5000 SIFT features for each grey-scale image of either a poodle dog or fried chicken, and asked to build a model for classification.

I ran preProcess function on the matrix of sift features:

mat1=preProcess(mat, method=c("pca", "zv"))

What I get is a class "preprocessed", and I do not know how to use this object mat1 in the following function call:

model_gbm <- train(ensembleData[,predictors], ensembleData[,labelName], method='gbm',  trControl=myControl)

ensembleData[, predictors] used to contain the feature part of the sift features, and ensembleData[, labelName] contained the actual class (0 or 1) of the data.

I have thought about using the preProcess function inside of the train function, but I want to be able to use the same preprocessed data elsewhere in other models.

Thanks!

According to the caret documentation

The function preProcess estimates the required parameters for each operation and predict.preProcess is used to apply them to specific data sets

So you need to apply the estimated parameters to your data like so:

mat1=preProcess(mat, method=c("pca", "zv"))
transformed = predict(mat1, mat)
model_gbm <- train(data=transformed, method='gbm',  trControl=myControl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM