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 = mlr3::lrn("regr.fnn")
print(learner)
#> <LearnerRegrFNN:regr.fnn>: Fast Nearest Neighbour
#> * Model: -
#> * Parameters: list()
#> * Packages: mlr3, mlr3extralearners, FNN
#> * Predict Types:  [response]
#> * Feature Types: integer, numeric
#> * Properties: -

# Define a Task
task = mlr3::tsk("mtcars")

# Create train and test set
ids = mlr3::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:     1     1     4 108.0  3.85     4    93 18.61     1 2.320
#>  4:     0     1     6 225.0  2.76     3   105 20.22     1 3.460
#>  5:     0     4     8 360.0  3.21     3   245 15.84     0 3.570
#>  6:     0     2     4 140.8  3.92     4    95 22.90     1 3.150
#>  7:     0     4     6 167.6  3.92     4   123 18.30     1 3.440
#>  8:     0     4     6 167.6  3.92     4   123 18.90     1 3.440
#>  9:     0     3     8 275.8  3.07     3   180 18.00     0 3.780
#> 10:     0     4     8 472.0  2.93     3   205 17.98     0 5.250
#> 11:     0     4     8 440.0  3.23     3   230 17.42     0 5.345
#> 12:     1     1     4  78.7  4.08     4    66 19.47     1 2.200
#> 13:     1     2     4  75.7  4.93     4    52 18.52     1 1.615
#> 14:     1     1     4  71.1  4.22     4    65 19.90     1 1.835
#> 15:     0     2     8 318.0  2.76     3   150 16.87     0 3.520
#> 16:     0     2     8 304.0  3.15     3   150 17.30     0 3.435
#> 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     4     8 351.0  4.22     5   264 14.50     0 3.170
#> 21:     1     6     6 145.0  3.62     5   175 15.50     0 2.770
#>        am  carb   cyl  disp  drat  gear    hp  qsec    vs    wt
#> 
#> $y
#>  [1] 21.0 21.0 22.8 18.1 14.3 22.8 19.2 17.8 15.2 10.4 14.7 32.4 30.4 33.9 15.5
#> [16] 15.2 19.2 26.0 30.4 15.8 19.7
#> 


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

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