RUVIDEO
Поделитесь видео 🙏

R Tutorial: Hyperparameter tuning in caret

Want to learn more? Take the full course at https://learn.datacamp.com/courses/hyperparameter-tuning-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---
Caret makes hyperparameter tuning very easy. By default, it performs automatic tuning for you with every training run. But you can also manually define how you want to tune your models.

Here you see the random forest model with the `rf` method from before. In the output we see that we only have one hyperparameter to tune:

`mtry` defines the number of variables that are randomly sampled as candidates at each split. caret automatically tried three different `mtry` values and includes the performance of each with the output. The best model is chosen with the metric `accuracy`, which in this case was for mtry = 6.

Different algorithms have different hyperparameters. You might be wondering how you would know which hyperparameters you can tune with these different `method` in caret.

If you know the model abbreviation, you can use the modellookup function.

But the easiest way is to use the online documentation for caret. Click this link on the slides to go to the page.

There, you will find an overview of the different algorithms you can set as `method` in the train function. This table includes the name of the model, the string you need to put into the train function, whether it can be used for classification or regression and what the original R package of the implementation is.
But most importantly, you will find which hyperparameters can be tuned.
Here, I will not discuss the mathematics behind hyperparameters, instead, I will focus on HOW to perform the hyperparameter tuning.

Let's change things up a bit and build a Support Vector Machine with Polynomial Kernel similar to the Random Forest model from before: this time I am using the `svmPoly` model.

And I am again calculating the training time.

When we examine the model object again,

we see that this time `caret` performed a more complex hyperparameter tuning. If we have more than one hyperparameter to tune, `train` automatically creates a grid of tuning parameters.
By default, caret tries all possible combinations of three hyperparameters, in our model:
- degree being 1, 2, or 3
- scale being 0.001, 0.01 or 0.1
- and c being 0.25, 0.5 or 1
Because the output shows the performance for every possible combination of hyperparameters, the output is too long to fit on this slide and I am only showing the best model with degree of 1, scale of 0.1 and c equal to 1.

We can also set the option `tuneLength` to specify the number of different values to try for each hyperparameter,

for example 5.

Now, caret tries all possible combinations of five hyperparameters:
- degree being 1, 2, 3, 4 or 5
- scale being 1e-03, 1e-02, 1e-01, 1e+00 and 1e+01
- and c being 0.25, 0.5, 1, 2 or 4

The best model now has degree, scale and c of 1.

Of course, you could also manually try out different hyperparameters.

This, we can do with the option `tuneGrid()`, to which we can feed a grid of hyperparameters. This grid is defined with the `expand.grid()` function.
If we use that function, we need to define all hyperparameters. Let's see what happens if we set the degree to 4 and keep scale and c at 1

and retrain the model.

This time, we only trained with one combination of hyperparameters, so our output gives the performance for these hyperparameters only!

Now it's your turn to apply simple hyperparameter tuning in caret.

#R #RTutorial #DataCamp #Hyperparameter #Tuning

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «R Tutorial: Hyperparameter tuning in caret», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.