mlr-org / mlr3viz

Visualizations for mlr3
https://mlr3viz.mlr-org.com
GNU Lesser General Public License v3.0
42 stars 8 forks source link

Add default plot for regr.lm #46

Open mllg opened 4 years ago

missuse commented 4 years ago

In my opinion residual plots are suitable here. ggfortify has a decent autoplot method for lm objects.

autoplot.LearnerRegrLM = function(object, ...) { # nolint
  if (is.null(object$model)) {
    stopf("Learner '%s' must be trained first", object$id)
    }
  if (is.null(object$model$model)) {
    stopf("Learner '%s' must be trained with `keep_model` set to `TRUE`", object$id)
    }
  require_namespaces("ggfortify")
  autoplot(object$model, ...)
}

usage:

task = tsk("mtcars")
learner = lrn("regr.lm")
learner$train(task)
autoplot(learner)

An example of the plot: lm