Machine Learning in R: mlr Tutorial
This web page provides an in-depth introduction to the Machine Learning in R: mlr framework for machine learning experiments in R.
We focus on the comprehension of the basic functions and applications. More detailed technical information can be found in the manual pages which are regularly updated and reflect the documentation of the current package version on CRAN.
An offline version of this tutorial is available for download
The tutorial explains the basic analysis of a data set step by step. Please refer to sections of the menu above: Basics, Advanced, Extend and Appendix.
During the tutorial we present various simple examples from classification, regression, cluster and survival analysis to illustrate the main features of the package.
Here we show the mlr workflow to train, make predictions, and evaluate a learner on a classification problem. We walk through 5 basic steps that work on any learning problem or method supported by mlr.
library(mlr) data(iris) ## 1) Define the task ## Specify the type of analysis (e.g. classification) and provide data and response variable task = makeClassifTask(data = iris, target = "Species") ## 2) Define the learner ## Choose a specific algorithm (e.g. linear discriminant analysis) lrn = makeLearner("classif.lda") n = nrow(iris) train.set = sample(n, size = 2/3*n) test.set = setdiff(1:n, train.set) ## 3) Fit the model ## Train the learner on the task using a random subset of the data as training set model = train(lrn, task, subset = train.set) ## 4) Make predictions ## Predict values of the response variable for new observations by the trained model ## using the other part of the data as test set pred = predict(model, task = task, subset = test.set) ## 5) Evaluate the learner ## Calculate the mean misclassification error and accuracy performance(pred, measures = list(mmce, acc)) #> mmce acc #> 0.04 0.96