r-caret

Caret obtain train & cv predictions from model to plot

梦想的初衷 提交于 2019-12-10 10:31:55
问题 I've trained a simple model: mySim <- train(Event ~ ., method = 'rf', data = train, tuneGrid = tg) Optimising the two nnet parameters weight_decay and size of the hidden layer. I'm new to trying out caret so what I would usually do is plot the train error and cv error for each model build. To do this, I'd need to have the predictive values of my train and validation pass. This is the first time I've used cross validation so I'm a little unsure how I can go about getting the predictions from

Warnings while using the Naive Bayes Classifier in the Caret Package

穿精又带淫゛_ 提交于 2019-12-09 23:41:34
问题 I am attempting to run a supervised machine learning classifier known as Naive Bayes in the caret Package. My data is called LDA.scores, and has two categorical factors called "V4" and "G8", and 12 predictor variables. The code that I am using was adapted by a kind person on stack overflow from code supplied by myself (see link below).The code does work, however, only 9 predictors were used instead of the 12 predictors in the data-set. When I tried to train the Naive Bayes model with the

Why do results using caret::train(…, method = “rpart”) differ from rpart::rpart(…)?

为君一笑 提交于 2019-12-09 15:57:19
问题 I'm taking part in the Coursera Practical Machine Learning course, and the coursework requires building predictive models using this dataset. After splitting the data into training and testing datasets, based on the outcome of interest (herewith labelled y , but is in fact the classe variable in the dataset): inTrain <- createDataPartition(y = data$y, p = 0.75, list = F) training <- data[inTrain, ] testing <- data[-inTrain, ] I have tried 2 different methods: modFit <- caret::train(y ~ .,

Pass PCA preprocessing arguments to train()

℡╲_俬逩灬. 提交于 2019-12-09 08:58:59
问题 I'm trying to build a predictive model in caret using PCA as pre-processing. The pre-processing would be as follows: preProc <- preProcess(IL_train[,-1], method="pca", thresh = 0.8) Is it possible to pass the thresh argument directly to caret's train() function? I've tried the following, but it doesn't work: modelFit_pp <- train(IL_train$diagnosis ~ . , preProcess="pca", thresh= 0.8, method="glm", data=IL_train) If not, how can I pass the separate preProc results to the train() function? 回答1:

How to extract components after performing principal component regression for further analysis in R caret package

眉间皱痕 提交于 2019-12-09 01:48:50
问题 I had a dataset that contained 151 variables, that were found to be high in colinearility, so I performed principal component regression on it by doing the following:- ctrl <- trainControl(method = "repeatedcv", repeats = 10, savePred = T) model <- train(RT..seconds.~., data = cadets100, method = "pcr", trControl = ctrl) which gives me me:- RMSE = 65.7 R-squared 0.443 I was just wondering how I went about extracting these components after so that I could get say apply further analysis (i.e.

caret/rfe-error: “there should be the same number of samples in x and y”

跟風遠走 提交于 2019-12-08 13:48:36
问题 My aim is to perform cross validation with R. Columns 1-31 are Features and column 32 is the output class. I load data from a .xls file. But I have severe issues with the rfeControl-function. Please see my code: install.packages('e1071') library(e1071) install.packages('readxl') library(readxl) library(rpart) install.packages('randomForest') library(randomForest) install.packages('party') library(party) install.packages('mlbench') library(mlbench) install.packages('caret') library(caret) #---

Caret - Setting the seeds inside the gafsControl()

一世执手 提交于 2019-12-08 09:45:39
问题 I am trying to set the seeds inside the caret's gafsControl() , but I am getting this error: Error in { : task 1 failed - "supplied seed is not a valid integer" I understand that seeds for trainControl() is a vector equal to the number of resamples plus one, with the number of combinations of models's tuning parameters (in my case 36, SVM with 6 Sigma and 6 Cost values) in each (resamples) entries. However, I couldn't figure out what I should use for gafsControl() . I've tried iters * popSize

Save/load a M5 RWeka caret model fails

﹥>﹥吖頭↗ 提交于 2019-12-07 18:31:00
问题 I'm coming up with an error after loading a saved M5 implementation of the RWeka package via Caret. Error in .jcall(o, "Ljava/lang/Class;", "getClass") : RcallMethod: attempt to call a method of a NULL object. To reproduce the error: library(caret); library(RWeka) data(GermanCredit) myModel <- train(Duration~Amount, data=GermanCredit, method="M5") predict(myModel, GermanCredit[1,]) # Works. save(myModel, file="myModel.rda") load("myModel.rda") predict(myModel, GermanCredit[1,]) # Produces the

Plot decision tree in R (Caret)

断了今生、忘了曾经 提交于 2019-12-07 16:05:32
问题 I have trained a dataset with rf method. For example: ctrl <- trainControl( method = "LGOCV", repeats = 3, savePred=TRUE, verboseIter = TRUE, preProcOptions = list(thresh = 0.95) ) preProcessInTrain<-c("center", "scale") metric_used<-"Accuracy" model <- train( Output ~ ., data = training, method = "rf", trControl = ctrl, metric=metric_used, tuneLength = 10, preProc = preProcessInTrain ) After thath, I want to plot the decission tree, but when I wirte plot(model) , I get this: plot(model). If

r caret predict returns fewer output than input

ε祈祈猫儿з 提交于 2019-12-07 06:36:30
问题 I used caret to train an rpart model below. trainIndex <- createDataPartition(d$Happiness, p=.8, list=FALSE) dtrain <- d[trainIndex, ] dtest <- d[-trainIndex, ] fitControl <- trainControl(## 10-fold CV method = "repeatedcv", number=10, repeats=10) fitRpart <- train(Happiness ~ ., data=dtrain, method="rpart", trControl = fitControl) testRpart <- predict(fitRpart, newdata=dtest) dtest contains 1296 observations, so I expected testRpart to produce a vector of length 1296. Instead it's 1077 long,