Skip to contents

Minimum distance to mean (MDM) assigns a new observation to its closest trained class mean. The k-nearest-neighbor classifier instead uses the most frequent class among the nearest labeled training observations. Both retain the geometry used for fitting.

Usage

riem.mdm(riemobj, y, geometry = NULL, ...)

riem.knnclass(riemobj, y, k = 1L, geometry = NULL)

# S3 method for class 'riem_classifier'
predict(object, newdata, type = "class", ...)

# S3 method for class 'riem_classifier'
print(x, ...)

Arguments

riemobj

Wrapped training observations.

y

A factor, character, logical or finite numeric vector of class labels, one per training observation. At least two observed classes and complete labels are required. Factor level order is preserved and unused levels are dropped. Other inputs use the levels of factor(y).

geometry

Geometry name or saved specification accepted by riem.geometry. MDM requires compatible mean and distance operations. Nearest-neighbor classification only requires distances.

...

For riem.mdm, controls passed to riem.mean for each class. The prediction method accepts no extra arguments.

k

Number of training observations that vote, between one and the training sample size.

object

A fitted manifold classifier.

newdata

Compatible wrapped observations in training feature order.

type

"class" returns a factor in the fitted level order. For MDM, "distance" returns a new-observation by class matrix of distances. For nearest neighbors, "votes" returns a matrix of class vote fractions. These fractions describe the neighborhood vote.

x

A fitted manifold classifier.

Value

A riem_classifier fitted object. MDM stores one prototype per observed class in support$data and class mean diagnostics. Nearest-neighbor fits retain the labeled training observations. The fitted class level order is recorded in levels.

Details

Each MDM prototype is an equally weighted class mean. Iterative class mean fits must converge under the selected geometry. Nonconvex geometries can have multiple stationary estimates. Neighbor votes have equal weight. At the boundary of the neighbor set, distance ties are resolved by training row order. Tied class votes and ties between prototypes are resolved by fitted class level order. A training observation supplied as new data is eligible to be its own neighbor. Split the data before fitting for a held-out evaluation.

Examples

train <- wrap.euclidean(as.list(c(-2, -1, 1, 2)))
y <- factor(c("left", "left", "right", "right"))
test <- wrap.euclidean(as.list(c(-1.5, 1.5)))
predict(riem.mdm(train, y), test)
#> [1] left  right
#> Levels: left right
predict(riem.knnclass(train, y, k = 3), test, type = "votes")
#>           left     right
#> [1,] 0.6666667 0.3333333
#> [2,] 0.3333333 0.6666667