# knnreg.tune: Tuning of the k-NN regression with Euclidean or... In Directional: A Collection of Functions for Directional Data Analysis

## Description

Tuning of the k-NN regression with Euclidean or (hyper-)spherical response and or predictor variables. It estimates the percentage of correct classification via an m-fold cross valdiation. The bias is estimated as well using the algorithm suggested by Tibshirani and Tibshirani (2009) and is subtracted.

## Usage

 1 2 knnreg.tune(y, x, nfolds = 10, A = 10, ncores = 1, res = "eucl", estim = "arithmetic", folds = NULL, seed = FALSE, graph = FALSE) 

## Arguments

 y The currently available data, the response variables values. A matrix with either euclidean (univariate or multivariate) or (hyper-)spherical data. If you have a circular response, say u, transform it to a unit vector via (cos(u), sin(u)). x The currently available data, the predictor variables values. A matrix with either euclidean (univariate or multivariate) or (hyper-)spherical data. If you have a circular response, say u, transform it to a unit vector via (cos(u), sin(u)). nfolds How many folds to create? A The maximum number of nearest neighbours, set to 5 by default, starting from the 1 nearest neighbor. ncores How many cores to use. This is taken into account only when the predictor variables are spherical. res The type of the response variable. If it is Euclidean, set this argument equal to "res". If it is a unit vector set it to res="spher". estim Once the k observations whith the smallest distance are discovered, what should the prediction be? The arithmetic average of the corresponding y values be used estim="arithmetic" or their harmonic average estim="harmonic". folds Do you already have a list with the folds? If not, leave this NULL. seed If seed is TRUE, the results will always be the same. graph If this is TRUE a graph with the results will appear.

## Details

Tuning of the k-NN regression with Euclidean or (hyper-)spherical response and or predictor variables. It estimates the percentage of correct classification via an m-fold cross valdiation. The bias is estimated as well using the algorithm suggested by Tibshirani and Tibshirani (2009) and is subtracted. The sum of squares of prediction is used in the case of Euclidean responses. In the case of spherical responses the ∑_{\hat{y}_i^T}y_i is calculated.

## Value

A list including:

 crit The value of the criterion to minimise/maximise for all values of the nearest neighbours. best_k The best value of the nearest neighbours. performance The bias corrected optimal value of the criterion, along wit the estimated bias. For the case of Euclidean reponse this will be higher than the crit and for the case or spherical responses it will be lower than crit. runtime The run time of the algorithm. A numeric vector. The first element is the user time, the second element is the system time and the third element is the elapsed time.

## Author(s)

Michail Tsagris R implementation and documentation: Michail Tsagris mtsagris@uoc.gr and Giorgos Athineou <gioathineou@gmail.com>

knn.reg, spher.reg, dirknn.tune 

## Examples

 1 2 3 4 5 6 7 8 9 y <- iris[, 1] x <- iris[, 2:4] x <- x/ sqrt( rowSums(x^2) ) ## Euclidean response and spherical predictors knnreg.tune(y, x, A = 5, res = "eucl", estim = "arithmetic") y <- iris[, 1:3] y <- y/ sqrt( rowSums(y^2) ) ## Spherical response and Euclidean predictor x <- iris[, 2] knnreg.tune(y, x, A = 5, res = "spher", estim = "arithmetic") 

### Example output

sh: 1: wc: Permission denied
Warning messages:
1: In rgl.init(initValue, onlyNULL) : RGL: unable to open X11 display
2: 'rgl.init' failed, running with 'rgl.useNULL = TRUE'.
$crit [1] 0.5111333 0.4377833 0.3721111 0.3405458 0.3333013$best_k
[1] 6

$performance [1] 0.3333013$runtime
user  system elapsed
0.004   0.001   0.065

$crit [1] 0.6735008 0.6722058 0.6721420 0.6721629 0.6716724$best_k
[1] 6

$performance [1] 0.6716724$runtime
user  system elapsed
0.027   0.000   0.256


Directional documentation built on Nov. 8, 2021, 1:07 a.m.