
In base R, you can fit one using the lmmethod. Linear regression is one of the most well known algorithms. Our first caret example consists of fitting a simple linear regression. I’ll do a small tweak to make the iris problem a binary one (unfortunately glm, the logistic regression implementation in R doesn’t support multiclass problems): iris$target <- ifelse( iris$Species = 'setosa', 1, 0 )Īs we’ll want to evaluate the predict method, let’s split our two dataframes into train and test first - I’ll use a personal favorite, caTools: library(caTools) # Train Test Split on both Iris and Mtcars train_test_split <- function(df) # Unwrapping mtcars mtcars_train <- train_test_split(mtcars)] mtcars_test <- train_test_split(mtcars)] # Unwrapping iris iris_train <- train_test_split(iris)] iris_test <- train_test_split(iris)] The mtcars dataset that will be used as our regression task.The iris dataset, a very well known dataset that will represent our classification task.

We’ll wrap everything by checking how the predict works with different caretmodels.įor simplicity, and because we want to focus on the library itself, we’ll use two of the most famous toy datasets available in R:.Experimenting with our own hyperparameter tuning.
CARET IN R HOW TO
