mlr
is a R package that offers a unified interface to
machine learning models. By writing an interface between
condvis2
and mlr
a vast number of machine
learning fits may be explored with condvis
. Presently,
regression, classification and clustering varieties of mlr
learners work with `condvis’.
A list of models supported by mlr
is found on this link:
https://mlr.mlr-org.com/articles/tutorial/integrated_learners.html
Set up the task, learner and train the model.
library(mlr)
library(MASS)
library(condvis2)
<- Boston[,9:14]
Boston1
<- makeRegrTask(id = "bh", data = Boston1, target = "medv")
rtask <- train(makeLearner("regr.lm"), rtask)
rmod <- train(makeLearner("regr.fnn"), rtask) rmod1
Use condvis to explore the models:
condvis(Boston1, model=list(rmod,rmod1), response="medv", sectionvars="lstat")
Choose tour “Diff fits” to explore differences between the fits
Some tasks, for example linear regression, support standard errors
and so confidence intervals. This option needs to be added to
makeLearner
. Then, tell condvis
to plot an
interval using pinterval="confidence
for that fit.
<- train(makeLearner("regr.lm", predict.type="se"), rtask)
rmod condvis(Boston1, model=rmod, response="medv", sectionvars="lstat", predictArgs=list(list(pinterval="confidence")))
Set up the task, learner and train the model.
= makeClassifTask(data = iris, target = "Species")
cltask = makeLearner("classif.lda",predict.type = "prob") # need predict.type ="probs" to get probs
cllrn = train(cllrn, cltask) clmod
Explore with condvis
:
condvis(iris, model=clmod, response="Species", sectionvars=c("Petal.Length", "Petal.Width"), pointColor="Species")
Click on “Show probs” to see class probabilities.
= makeClusterTask(data = iris[,-5])
ctask = makeLearner("cluster.kmeans")
clrn = train(clrn, ctask) cmod
Add the predicted class to the data to act as the response:
library(dplyr)
<- iris
iris1
$pclass <- cmod %>%
iris1predict(newdata=iris[,-5]) %>%
getPredictionResponse() %>%
as.factor()
condvis(data = iris1, model = cmod,
response="pclass",
sectionvars=c("Petal.Length", "Petal.Width"),
conditionvars=c("Sepal.Length", "Sepal.Width"),pointColor="Species"
)