Skip to contents

Multioutput classification by k-NN vote (Geron Ch 3, morie.fn hmmto)

Usage

morie_geron_multioutput(X, Y, k = 1, X_new = NULL)

Arguments

X

Features.

Y

Categorical targets (m,t).

k

Neighbours voting.

X_new

Optional rows to predict.

Value

List with predictions, predict, accuracy_per_output, accuracy, n_outputs, estimate, n, method.

Examples

V <- c(1, 2, 3, 4, 5, 6, 7, 8)
morie_geron_multioutput(V, V)
#> $predictions
#>      [,1]
#> [1,]    2
#> [2,]    1
#> [3,]    2
#> [4,]    3
#> [5,]    4
#> [6,]    5
#> [7,]    6
#> [8,]    7
#> 
#> $predict
#> function (Xnew) 
#> {
#>     B <- if (is.null(dim(Xnew))) 
#>         matrix(as.numeric(Xnew), nrow = 1)
#>     else as.matrix(Xnew)
#>     D <- matrix(0, nrow(B), nrow(A))
#>     for (i in seq_len(nrow(B))) D[i, ] <- sqrt(rowSums((A - matrix(B[i, 
#>         ], nrow(A), ncol(A), byrow = TRUE))^2))
#>     vote(D, exclude_self = FALSE)
#> }
#> <environment: 0x56217bb954d0>
#> 
#> $accuracy_per_output
#> [1] 0
#> 
#> $accuracy
#> [1] 0
#> 
#> $exact_match
#> [1] 0
#> 
#> $n_outputs
#> [1] 1
#> 
#> $estimate
#>      [,1]
#> [1,]    2
#> [2,]    1
#> [3,]    2
#> [4,]    3
#> [5,]    4
#> [6,]    5
#> [7,]    6
#> [8,]    7
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "1-NN multioutput vote (leave-one-out when no new rows are given)"
#>