Skip to contents

Fast Nearest Neighbour Regression. Calls FNN::knn.reg() from FNN.

Dictionary

This Learner can be instantiated via lrn():

lrn("regr.fnn")

Meta Information

  • Task type: “regr”

  • Predict Types: “response”

  • Feature Types: “integer”, “numeric”

  • Required Packages: mlr3, mlr3extralearners, FNN

Parameters

IdTypeDefaultLevelsRange
kinteger1\([1, \infty)\)
algorithmcharacterkd_treekd_tree, cover_tree, brute-

References

Boltz, Sylvain, Debreuve, Eric, Barlaud, Michel (2007). “kNN-based high-dimensional Kullback-Leibler distance for tracking.” In Eighth International Workshop on Image Analysis for Multimedia Interactive Services (WIAMIS'07), 16–16. IEEE.

See also

Author

be-marc

Super classes

mlr3::Learner -> mlr3::LearnerRegr -> LearnerRegrFNN

Methods

Inherited methods


Method new()

Creates a new instance of this R6 class.

Usage


Method clone()

The objects of this class are cloneable with this method.

Usage

LearnerRegrFNN$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# Define the Learner
learner = lrn("regr.fnn")
print(learner)
#> 
#> ── <LearnerRegrFNN> (regr.fnn): Fast Nearest Neighbour ─────────────────────────
#> • Model: -
#> • Parameters: list()
#> • Packages: mlr3, mlr3extralearners, and FNN
#> • Predict Types: [response]
#> • Feature Types: integer and numeric
#> • Encapsulation: none (fallback: -)
#> • Properties:
#> • Other settings: use_weights = 'error'

# 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)
#> $train
#>        am  carb   cyl  disp  drat  gear    hp  qsec    vs    wt
#>     <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#>  1:     1     4     6 160.0  3.90     4   110 16.46     0 2.620
#>  2:     1     4     6 160.0  3.90     4   110 17.02     0 2.875
#>  3:     0     1     6 258.0  3.08     3   110 19.44     1 3.215
#>  4:     0     2     8 360.0  3.15     3   175 17.02     0 3.440
#>  5:     0     1     6 225.0  2.76     3   105 20.22     1 3.460
#>  6:     0     4     8 360.0  3.21     3   245 15.84     0 3.570
#>  7:     0     2     4 146.7  3.69     4    62 20.00     1 3.190
#>  8:     0     2     4 140.8  3.92     4    95 22.90     1 3.150
#>  9:     0     4     6 167.6  3.92     4   123 18.30     1 3.440
#> 10:     0     3     8 275.8  3.07     3   180 17.60     0 3.730
#> 11:     0     3     8 275.8  3.07     3   180 18.00     0 3.780
#> 12:     0     4     8 460.0  3.00     3   215 17.82     0 5.424
#> 13:     0     4     8 440.0  3.23     3   230 17.42     0 5.345
#> 14:     1     1     4  78.7  4.08     4    66 19.47     1 2.200
#> 15:     1     2     4  75.7  4.93     4    52 18.52     1 1.615
#> 16:     1     1     4  71.1  4.22     4    65 19.90     1 1.835
#> 17:     0     2     8 318.0  2.76     3   150 16.87     0 3.520
#> 18:     0     4     8 350.0  3.73     3   245 15.41     0 3.840
#> 19:     1     2     4  95.1  3.77     5   113 16.90     1 1.513
#> 20:     1     6     6 145.0  3.62     5   175 15.50     0 2.770
#> 21:     1     2     4 121.0  4.11     4   109 18.60     1 2.780
#>        am  carb   cyl  disp  drat  gear    hp  qsec    vs    wt
#> 
#> $y
#>  [1] 21.0 21.0 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.3 15.2 10.4 14.7 32.4 30.4
#> [16] 33.9 15.5 13.3 30.4 19.7 21.4
#> 


# Make predictions for the test rows
predictions = learner$predict(task, row_ids = ids$test)

# Score the predictions
predictions$score()
#> regr.mse 
#> 7.974848