Description Usage Arguments Details Value Author(s) References See Also Examples

This function allows to obtain the nearest neighbours of each example in a data set using a distance function selected by the user.

1 | ```
neighbours(tgt, dat, dist, p=2, k)
``` |

`tgt` |
The column of the problem target variable. |

`dat` |
A data frame containing the problem data. |

`dist` |
A character string specifying the distance function to use in the nearest neighbours evaluation. |

`p` |
An optional parameter that is only required if the distance function selected in parameter |

`k` |
The number of nearest neighbours to return for each example. |

Several distance function are implemented in UBL package. The goal of having such a diversity of distance functions is to provide the users more flexibility regarding the distance used and also to provide distance fucntions that are able to deal with nominal and numeric features. The options available for the distance functions are as follows:

- data with only numeric features:
"Manhattan", "Euclidean", "Canberra", "Chebyshev", "p-norm";

- data with only nominal features:
"Overlap";

- data with both nominal and numeric features:
"HEOM", "HVDM".

When the "p-norm" is selected for the `dist`

parameter, it is also necessary to define the value of parameter `p`

. The value of parameter `p`

sets which "p-norm" will be used. For instance, if `p`

is set to 1, the "1-norm" (or Manhattan distance) is used, and if `p`

is set to 2, the "2-norm" (or Euclidean distance) is applied.
For more details regarding the distance functions implemented in UBL package please see the package vignettes.

The function returns a matrix with the indexes of the k nearest neighbours for each example in the data set.

Paula Branco [email protected], Rita Ribeiro [email protected] and Luis Torgo [email protected]

Wilson, D.R. and Martinez, T.R. (1997). *Improved heterogeneous distance functions.* Journal of artificial intelligence research, pp.1-34.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | ```
## Not run:
data(ImbC)
# determine the 2 nearest neighbours of each example in ImbC data set
# using the "HVDM" distance function.
neig1 <- neighbours(3, ImbC, "HVDM", k=2)
# now using the "HEOM" distance function
neig2 <- neighbours(3, ImbC, "HEOM", k=2)
# check the differences
head(neig1)
head(neig2)
## End(Not run)
``` |

```
Loading required package: MBA
Loading required package: gstat
Loading required package: automap
Loading required package: sp
Loading required package: randomForest
randomForest 4.6-12
Type rfNews() to see new features/changes/bug fixes.
[,1] [,2]
[1,] 716 670
[2,] 148 473
[3,] 327 774
[4,] 348 351
[5,] 519 593
[6,] 149 498
[,1] [,2]
[1,] 716 670
[2,] 985 447
[3,] 327 774
[4,] 348 680
[5,] 216 484
[6,] 498 862
```

UBL documentation built on July 13, 2017, 5:02 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.