r-caret

Display a Loading Sign while a model is being trained in Shiny App

淺唱寂寞╮ 提交于 2021-02-04 19:11:05
问题 I am making a Shiny App in which, at the click of the actionButton, a model is trained using the caret package. As this training takes time - approximately 4-5 minutes - I wanted to display a loading sign or a loading GIF in the App where results are displayed after the model is trained. Otherwise, the User wouldn't know what is happening or when the model is trained. Thanks 回答1: There is loading spinner which you can use in your ui.R # loading the library library(shinycssloaders) withSpinner

How to create a decision boundary graph for kNN models in the Caret package?

独自空忆成欢 提交于 2021-02-04 13:55:22
问题 I'd like to plot a decision boundary for the model created by the Caret package. Ideally, I'd like a general case method for any classifier model from Caret. However, I'm currently working with the kNN method. I've included code below that uses the wine quality dataset from UCI which is what I'm working with right now. I found this method that works with the generic kNN method in R, but can't figure out how to map it to Caret -> https://stats.stackexchange.com/questions/21572/how-to-plot

PCA within cross validation; however, only with a subset of variables

扶醉桌前 提交于 2021-01-29 20:47:36
问题 This question is very similar to preprocess within cross-validation in caret; however, in a project that i'm working on I would only like to do PCA on three predictors out of 19 in my case. Here is the example from preprocess within cross-validation in caret and I'll use this data ( PimaIndiansDiabetes ) for ease (this is not my project data but concept should be the same). I would then like to do the preProcess only on a subset of variables i.e. PimaIndiansDiabetes[, c(4,5,6)]. Is there a

PCA within cross validation; however, only with a subset of variables

冷暖自知 提交于 2021-01-29 17:54:52
问题 This question is very similar to preprocess within cross-validation in caret; however, in a project that i'm working on I would only like to do PCA on three predictors out of 19 in my case. Here is the example from preprocess within cross-validation in caret and I'll use this data ( PimaIndiansDiabetes ) for ease (this is not my project data but concept should be the same). I would then like to do the preProcess only on a subset of variables i.e. PimaIndiansDiabetes[, c(4,5,6)]. Is there a

Discripencies in variable importance calculation for glmnet model in R

我们两清 提交于 2021-01-29 12:41:20
问题 I want to calculate variable importance for glmnet model in R. I am using glmnet package for fitting the elastic net model like library(glmnet) library(caret) library(vip) data_y <- as.vector(mtcars$mpg) data_x <- as.matrix(mtcars[-1]) fit.glmnet <- glmnet(data_x, data_y, family="gaussian") set.seed(123) cvfit.glmnet = cv.glmnet(data_x, data_y, standardize=T) cvfit.glmnet$lambda.min coef(cvfit.glmnet, s = "lambda.min") Then I have used vip package for variable importance as #Using vip package

R: can caret::train function for glmnet cross-validate AUC at fixed alpha and lambda?

霸气de小男生 提交于 2021-01-29 10:12:26
问题 I would like to calculate the 10-fold cross-validated AUC of an elastic net regression model with the optimal alpha and lambda using caret::train https://stats.stackexchange.com/questions/69638/does-caret-train-function-for-glmnet-cross-validate-for-both-alpha-and-lambda/69651 explains how to cross-validate alpha and lambda with caret::train My question on Cross Validated got closed, because it has been classified as a programming question: https://stats.stackexchange.com/questions/505865/r

variable encoding in K-fold validation of random forest using package 'caret'

眉间皱痕 提交于 2021-01-29 07:50:46
问题 I want to run a RF classification just like it's specified in 'randomForest' but still use the k-fold repeated cross validation method (code below). How do I stop caret from creating dummy variables out of my categorical ones? I read that this may be due to One-Hot-Encoding, but not sure how to change this. I would be very greatful for some example lines on how to fix this! database: > str(river) 'data.frame': 121 obs. of 13 variables: $ stat_bino : Factor w/ 2 levels "0","1": 2 2 1 1 2 2 2 2

Best function to compare caret model objects

旧街凉风 提交于 2021-01-28 19:06:36
问题 I have a number of caret model objects using the same data and tuning parameters. For a sanity check I want to see if each method gives me the same model object. (This is all part of a broader plan to run parallel processing and ensure my models are the same.) For example, below, I train 2 different models and want to compare. When I compare the caret objects it returns FALSE. > library(caret) > > set.seed(0) > myControl <- trainControl(method='cv', index=createFolds(iris$Species)) > > set

ROC curve for the testing set using Caret package

自闭症网瘾萝莉.ら 提交于 2021-01-28 08:56:53
问题 I am trying to obtain ROC curve for the best model from caret on the test set. I came across MLeval package which seems to be handy (the output is very thorough, providing all the needed metrics with graphs using few lines of code). A nice example is here: https://stackoverflow.com/a/59134729/12875646 I am trying the code below and able to obtain the required metrics/graphs for the training set but keep getting error when I try to work on the testing set. library(caret) library(MLeval) data

Error in table(data, reference, dnn = dnn, …) : all arguments must have the same length when run confusionMatrix with caret, in R

吃可爱长大的小学妹 提交于 2021-01-28 08:46:50
问题 I have an issue running a confusionMatrix. here is what I do: rf <- caret::train(tested ~., data = training_data, method = "rf", trControl = ctrlInside, metric = "ROC", na.action = na.exclude) rf After I get my model this is the next step I take: evalResult.rf <- predict(rf, testing_data, type = "prob") predict_rf <- as.factor(ifelse(evalResult.rf <0.5, "positive", "negative")) And then I am running my confusion matrix. cm_rf_forest <- confusionMatrix(predict_rf, testing_data$tested,