Distances: Distance matrix between all data set examples according to a...

distancesR Documentation

Distance matrix between all data set examples according to a selected distance metric.

Description

This function computes the distances between all examples in a data set using a selected distance metric. The metrics available are suitable for data sets with numeric and/or nominal features and include, among others: Euclidean, Manhattan, HEOM and HVDM.

Usage

distances(tgt, dat, dist, p=2)

Arguments

tgt

The index of 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 dist is "p-norm".

Details

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.

Value

The function returns a matrix with the distances computed between each pair of examples in the data set.

Author(s)

Paula Branco paobranco@gmail.com, Rita Ribeiro rpribeiro@dcc.fc.up.pt and Luis Torgo ltorgo@dcc.fc.up.pt

References

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

See Also

neighbours

Examples

## Not run: 
data(ImbC)
# determine the distances between each example in ImbC data set
# using the "HVDM" distance function.
dist1 <- distances(3, ImbC, "HVDM")

# now using the "HEOM" distance function
dist2 <- distances(3, ImbC, "HEOM")

# check the differences
head(dist1)
head(dist2)

## End(Not run)

UBL documentation built on Oct. 8, 2023, 1:07 a.m.