Polynomial Regression Learner
Source:R/learner_stats_regr_polynomial.R
mlr_learners_regr.polynomial.RdPolynomial regression without interactions between features.
Calls stats::lm() from base package 'stats' on a model formula in which every feature is expanded with
stats::poly().
For polynomial regression that also includes interaction terms, see
regr.polyFit.
Initial parameter values
degreeActual default:
1Adjusted default:
2Reason for change: A degree of
1is plain linear regression, so the lowest degree that makes this learner differ fromstats::lm()is the more useful default.
Polynomial degree
stats::poly() requires the degree of the polynomial to be smaller than the number of distinct values of a
feature.
To keep the learner usable inside resampling, where individual folds may contain features with few distinct
values, the degree is capped per feature at min(degree, <number of distinct values> - 1).
Features that are constant in the training data enter the formula untransformed.
Meta Information
Task type: “regr”
Predict Types: “response”, “se”
Feature Types: “integer”, “numeric”
Required Packages: mlr3, mlr3extralearners, 'stats'
References
Hastie, Trevor, Tibshirani, Robert, Friedman, Jerome (2009). The Elements of Statistical Learning, series Springer Series in Statistics, 2 edition. Springer, New York. doi:10.1007/978-0-387-84858-7 .
See also
as.data.table(mlr_learners)for a table of available Learners in the running session (depending on the loaded packages).Chapter in the mlr3book: https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners
mlr3learners for a selection of recommended learners.
mlr3cluster for unsupervised clustering learners.
mlr3pipelines to combine learners with pre- and postprocessing steps.
mlr3tuning for tuning of hyperparameters, mlr3tuningspaces for established default tuning spaces.
Super classes
mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrPolynomial
Methods
Inherited methods
mlr3::Learner$base_learner()mlr3::Learner$configure()mlr3::Learner$encapsulate()mlr3::Learner$format()mlr3::Learner$help()mlr3::Learner$predict()mlr3::Learner$predict_newdata()mlr3::Learner$print()mlr3::Learner$reset()mlr3::Learner$selected_features()mlr3::Learner$train()mlr3::LearnerRegr$predict_newdata_fast()
LearnerRegrPolynomial$new()
Creates a new instance of this R6 class.
Usage
LearnerRegrPolynomial$new()Examples
# Define the Learner
learner = lrn("regr.polynomial")
print(learner)
#>
#> ── <LearnerRegrPolynomial> (regr.polynomial): Polynomial Regression ────────────
#> • Model: -
#> • Parameters: degree=2
#> • Packages: mlr3, mlr3extralearners, and stats
#> • Predict Types: [response] and se
#> • Feature Types: integer and numeric
#> • Encapsulation: none (fallback: -)
#> • Properties: weights
#> • Other settings: use_weights = 'use', predict_raw = 'FALSE'
# Define a Task
task = tsk("mtcars")
# Create train and test set
ids = partition(task)
# Train the learner on the training ids
learner$train(task, row_ids = ids$train)
print(learner$model)
#>
#> Call:
#> stats::lm(formula = formula, data = data, weights = private$.get_weights(task))
#>
#> Coefficients:
#> (Intercept) poly(am, degree = 1, raw = FALSE)
#> 19.581 5.901
#> poly(carb, degree = 2, raw = FALSE)1 poly(carb, degree = 2, raw = FALSE)2
#> -1.552 -9.264
#> poly(cyl, degree = 2, raw = FALSE)1 poly(cyl, degree = 2, raw = FALSE)2
#> 11.388 -1.374
#> poly(disp, degree = 2, raw = FALSE)1 poly(disp, degree = 2, raw = FALSE)2
#> 3.027 8.333
#> poly(drat, degree = 2, raw = FALSE)1 poly(drat, degree = 2, raw = FALSE)2
#> -3.880 -4.924
#> poly(gear, degree = 2, raw = FALSE)1 poly(gear, degree = 2, raw = FALSE)2
#> 8.728 6.738
#> poly(hp, degree = 2, raw = FALSE)1 poly(hp, degree = 2, raw = FALSE)2
#> 3.802 3.229
#> poly(qsec, degree = 2, raw = FALSE)1 poly(qsec, degree = 2, raw = FALSE)2
#> 23.356 2.530
#> poly(vs, degree = 1, raw = FALSE) poly(wt, degree = 2, raw = FALSE)1
#> -6.116 -33.407
#> poly(wt, degree = 2, raw = FALSE)2
#> -2.658
#>
# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)
# Score the predictions
predictions$score()
#> regr.mse
#> 57.09187