R Programming Language Certification Machine Learning with R 1 — Questions and Answers
Question 1: Which R package provides a unified interface to train and evaluate many machine learning models?
- lattice
- caret (Correct answer)
- forecast
- stringr
Correct answer: caret
The caret (Classification And REgression Training) package provides a standardized interface for training, tuning, and evaluating hundreds of ML models in R.
Question 2: In the caret package, which function is used to train a machine learning model?
- train() (Correct answer)
- fit()
- model()
- learn()
Correct answer: train()
The train() function in caret is the central function for fitting models, supporting cross-validation, hyperparameter tuning, and preprocessing in one call.
Question 3: Which tidymodels package is responsible for model specification (defining the model type and engine)?
- recipes
- rsample
- parsnip (Correct answer)
- yardstick
Correct answer: parsnip
parsnip provides a unified API for specifying model type (e.g., logistic_reg(), rand_forest()) and the computational engine (e.g., 'glmnet', 'ranger') separately from fitting.
Question 4: What is the primary purpose of k-fold cross-validation in machine learning?
- To increase training data size
- To obtain a more reliable estimate of model performance (Correct answer)
- To speed up model training
- To reduce the number of features
Correct answer: To obtain a more reliable estimate of model performance
K-fold cross-validation splits data into k subsets, trains on k-1 and validates on the remaining fold repeatedly, producing a more reliable and less biased performance estimate than a single train/test split.
Question 5: In R's tidymodels framework, which package handles data preprocessing and feature engineering steps?
- parsnip
- yardstick
- workflows
- recipes (Correct answer)
Correct answer: recipes
The recipes package defines preprocessing pipelines (steps) such as normalization, dummy encoding, and imputation, which are applied consistently to training and new data.
Question 6: Which function from the rsample package creates a stratified train/test split in R?
- train_test_split()
- initial_split() (Correct answer)
- split_data()
- partition()
Correct answer: initial_split()
initial_split() from rsample creates a single train/test partition, with optional stratification via the strata argument to preserve class proportions.
Question 7: Which R metric from the yardstick package is most appropriate for evaluating a binary classification model on imbalanced data?
- accuracy()
- rmse()
- roc_auc() (Correct answer)
- rsq()
Correct answer: roc_auc()
roc_auc() measures the area under the ROC curve, which remains informative on imbalanced datasets unlike raw accuracy, which can be misleading when one class dominates.
Which R package provides a unified interface to train and evaluate many machine learning models?