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     1     4 108.0  3.85     4    93 18.61     1 2.320
#>  2:     0     1     6 225.0  2.76     3   105 20.22     1 3.460
#>  3:     0     4     8 360.0  3.21     3   245 15.84     0 3.570
#>  4:     0     2     4 146.7  3.69     4    62 20.00     1 3.190
#>  5:     0     4     6 167.6  3.92     4   123 18.30     1 3.440
#>  6:     0     4     6 167.6  3.92     4   123 18.90     1 3.440
#>  7:     0     3     8 275.8  3.07     3   180 17.40     0 4.070
#>  8:     0     3     8 275.8  3.07     3   180 17.60     0 3.730
#>  9:     0     4     8 472.0  2.93     3   205 17.98     0 5.250
#> 10:     0     4     8 460.0  3.00     3   215 17.82     0 5.424
#> 11:     0     4     8 440.0  3.23     3   230 17.42     0 5.345
#> 12:     1     2     4  75.7  4.93     4    52 18.52     1 1.615
#> 13:     1     1     4  71.1  4.22     4    65 19.90     1 1.835
#> 14:     0     1     4 120.1  3.70     3    97 20.01     1 2.465
#> 15:     0     2     8 304.0  3.15     3   150 17.30     0 3.435
#> 16:     0     4     8 350.0  3.73     3   245 15.41     0 3.840
#> 17:     0     2     8 400.0  3.08     3   175 17.05     0 3.845
#> 18:     1     2     4 120.3  4.43     5    91 16.70     0 2.140
#> 19:     1     2     4  95.1  3.77     5   113 16.90     1 1.513
#> 20:     1     8     8 301.0  3.54     5   335 14.60     0 3.570
#> 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] 22.8 18.1 14.3 24.4 19.2 17.8 16.4 17.3 10.4 10.4 14.7 30.4 33.9 21.5 15.2
#> [16] 13.3 19.2 26.0 30.4 15.0 21.4
#> 


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

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