Skip to contents

Polynomial 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

  • degree

    • Actual default: 1

    • Adjusted default: 2

    • Reason for change: A degree of 1 is plain linear regression, so the lowest degree that makes this learner differ from stats::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.

Dictionary

This Learner can be instantiated via lrn():

lrn("regr.polynomial")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”, “se”

  • Feature Types: “integer”, “numeric”

  • Required Packages: mlr3, mlr3extralearners, 'stats'

Parameters

IdTypeDefaultLevelsRange
degreeinteger1\([1, \infty)\)
rawlogicalFALSETRUE, FALSE-

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

Author

imanechadli2003

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrPolynomial

Methods

Inherited methods


LearnerRegrPolynomial$new()

Creates a new instance of this R6 class.

Usage


LearnerRegrPolynomial$clone()

The objects of this class are cloneable with this method.

Usage

LearnerRegrPolynomial$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

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