Keep track of time for each ranking model in R Markdown!

Good afternoon people!

I'm taking my first steps in an RMD file where I apply classifiers to a dataset. I would like to get the runtime of each classifier on my data. In this case, the classifiers are thus in a single block.

#A. Global options that we will use in all our trained models

ctrl <- trainControl(method = 'cv',
                     number = 10,
                     classProbs = TRUE,
                     summaryFunction = twoClassSummary)

#B. Decision Tree: original data

dt_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "rpart",
                 trControl = ctrl,
                 metric = "ROC")

#C. Naive Bayes: original data

nb_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "naive_bayes",
                 trControl = ctrl,
                 metric = "ROC")

#D. Linear Discriminant Analysis: original data

lda_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "lda",
                 trControl = ctrl,
                 metric = "ROC")

#E. Logistic Regression: original data

lr_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "bayesglm",
                 trControl = ctrl,
                 metric = "ROC")

#F. Random Forest: original data

rf_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "rf",
                 trControl = ctrl,
                 metric = "ROC")

So for each applied classifier I would like to get its separate runtime. Any rather simple way to do this? I'm new to R and especially R Markdown.

I appreciate any help!

1 Like

There might be an easier way to do this but you could create start and end time variables for each individual model. The Random Forest could look like this:

rf_start <- Sys.time()

rf_orig <- train(Case ~ .,
                 data = train.orig,
                 method = "rf",
                 trControl = ctrl,
                 metric = "ROC")

rf_end <- Sys.time()

rf_runtime <- rf_end - rf_start
1 Like

Thank you! It was just what I wanted and it worked perfectly! Grateful!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.