R Programming Language Certification Machine Learning with R 2 — Questions and Answers
Question 1: Which R package is used to implement random forest models outside of the tidymodels ecosystem?
- randomForest (Correct answer)
- forest
- treepack
- rfmodel
Correct answer: randomForest
The randomForest package by Breiman and Cutler directly implements the random forest algorithm and provides functions like randomForest() and importance() for training and interpreting models.
Question 2: In R, which package and function are most commonly used to fit Support Vector Machine (SVM) models?
- svmR::svm()
- e1071::svm() (Correct answer)
- kernlab::svc()
- caret::svmFit()
Correct answer: e1071::svm()
The e1071 package provides the svm() function, which wraps LIBSVM and supports both classification and regression SVMs with multiple kernel options.
Question 3: Which R package is the most widely used for gradient boosting, particularly for tabular data competitions?
- gbm
- adaboost
- xgboost (Correct answer)
- lightR
Correct answer: xgboost
xgboost (eXtreme Gradient Boosting) is highly optimized for speed and performance, supports regularization, and has been the dominant package for gradient boosting in R competitions and production.
Question 4: What does the 'tuneGrid' parameter control when passed to caret's train() function?
- The number of cross-validation folds
- The grid of hyperparameter values to search over (Correct answer)
- The preprocessing steps to apply
- The train/test split ratio
Correct answer: The grid of hyperparameter values to search over
tuneGrid accepts a data frame where each column is a tunable hyperparameter and each row is one combination to evaluate, enabling grid search over the specified hyperparameter space.
Question 5: Which R function from the nnet package fits a single-hidden-layer neural network?
- neural()
- nnet() (Correct answer)
- neuralnet()
- mlp()
Correct answer: nnet()
nnet() from the nnet package fits a feed-forward neural network with one hidden layer using backpropagation, making it the base R option for simple neural network models.
Question 6: What is the purpose of regularization parameters (lambda) in regression-based machine learning models in R?
- To increase model complexity
- To penalize large coefficients and prevent overfitting (Correct answer)
- To speed up gradient descent convergence
- To scale the input features
Correct answer: To penalize large coefficients and prevent overfitting
Regularization adds a penalty term proportional to coefficient magnitude (L1/Lasso or L2/Ridge) to the loss function, discouraging overly complex models and improving generalization.
Question 7: Which R package provides the glmnet() function for fitting Lasso, Ridge, and Elastic Net regression models?
- lars
- glmnet (Correct answer)
- penalized
- elasticnet
Correct answer: glmnet
glmnet fits generalized linear models with L1 (Lasso), L2 (Ridge), or a mix (Elastic Net) regularization via an extremely efficient coordinate descent algorithm.
Which R package is used to implement random forest models outside of the tidymodels ecosystem?