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     1     4 108.0  3.85     4    93 18.61     1 2.320
#>  3:     0     1     6 258.0  3.08     3   110 19.44     1 3.215
#>  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     3     8 275.8  3.07     3   180 18.00     0 3.780
#>  7:     0     4     8 472.0  2.93     3   205 17.98     0 5.250
#>  8:     0     4     8 460.0  3.00     3   215 17.82     0 5.424
#>  9:     1     2     4  75.7  4.93     4    52 18.52     1 1.615
#> 10:     1     1     4  71.1  4.22     4    65 19.90     1 1.835
#> 11:     0     1     4 120.1  3.70     3    97 20.01     1 2.465
#> 12:     0     2     8 318.0  2.76     3   150 16.87     0 3.520
#> 13:     0     2     8 304.0  3.15     3   150 17.30     0 3.435
#> 14:     0     4     8 350.0  3.73     3   245 15.41     0 3.840
#> 15:     0     2     8 400.0  3.08     3   175 17.05     0 3.845
#> 16:     1     2     4 120.3  4.43     5    91 16.70     0 2.140
#> 17:     1     2     4  95.1  3.77     5   113 16.90     1 1.513
#> 18:     1     4     8 351.0  4.22     5   264 14.50     0 3.170
#> 19:     1     6     6 145.0  3.62     5   175 15.50     0 2.770
#> 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] 21.0 22.8 21.4 24.4 19.2 15.2 10.4 10.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2
#> [16] 26.0 30.4 15.8 19.7 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 
#> 3.869596