# show grouped code output instead of single lines
knitr::opts_chunk$set(collapse = TRUE)

This document provides an in-depth introduction to Machine Learning in R: mlr, a framework for machine learning experiments in R.

In this tutorial, we focus on basic functions and applications. More detailed technical information can be found in the manual pages{target="_blank"} which are regularly updated and reflect the documentation of the current package development version.

The tutorial aims to walkthrough basic data analysis tasks step by step. We will use simple examples from classification, regression, cluster and survival analysis to illustrate the main features of the package.

Enjoy reading!

Quick start

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))


berndbischl/mlr documentation built on Jan. 6, 2023, 12:45 p.m.