使用varimp进行特征选择

时间:2017-12-09 14:07:54

标签: machine-learning feature-selection

# ensure results are repeatable
set.seed(7)
# load the library
library(mlbench)
library(caret)
library(randomForest)
# load the dataset
data(liver)
# prepare training scheme
control1 <- trainControl(method="repeatedcv", number=10, repeats=3)
# train the model
liver.imputed <- rfImpute(datset2 ~ ., Liver12)

liver.imputed <- as.data.frame(liver.imputed)

str(liver.imputed)

model <- train(Dataset~., data=liver.imputed, method="lvq", preProcess="scale", trControl=control)

# estimate variable importance

importance <- varImp(model, scale=FALSE)
# summarize importance

print(importance)
# plot importance
plot(importance)

收到此错误 如果有人可以调查它,我正在使用varimp进行功能选择,但是当我运行我的模型时它会显示以下错误

错误:回归的模型类型错误

1 个答案:

答案 0 :(得分:0)

尝试:

y <-read.csv ("file.csv", header = T, sep=",", stringsAsFactors=F, colClasses=c("Dataset"="character"))