msmpred: Predict Class Labels for Mixtures of Subspaces

Description Usage Arguments Value Examples

View source: R/msmpred.R

Description

Once the run from main function msm is done, msmpred predicts the class label for the given data. In this function, there is no need for an user to modify any output. It simply takes a returned object from msm function, which is a list of lists, and new data.

Usage

1
msmpred(X, msmoutput, print.progress = TRUE)

Arguments

X

an (n\times p) data matrix.

msmoutput

output of msm function.

print.progress

a logical; TRUE to show completion of iterations by 10, FALSE otherwise.

Value

a length-n vector of class labels.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## generate a toy example
set.seed(10)
alldat = gen.LP(n=500, K=2, iso.var=0.1)

## separate as train/test data
id.train = sample(1:1000, 800, replace=FALSE)
id.test  = setdiff(1:1000, id.train)

train.dat = alldat$data[id.train,]
train.lab = alldat$class[id.train]

test.dat = alldat$data[id.test,]
test.lab = alldat$class[id.test]

## run MSM algorithm with K=2
maxiter   = 10000
output2   = msm(train.dat, K=2, iter=maxiter)
test.pred = msmpred(test.dat, output2)

## visualize with axis Y and Z for the test data
tX = test.dat[,2]
tY = test.dat[,3]

opar <- par(mfrow=c(1,2))
plot(tX,tY,col=test.lab, pch=19,cex=0.5,main="true label")
plot(tX,tY,col=test.pred,pch=19,cex=0.5,main="predicted label")
par(opar)

kyoustat/mosub documentation built on Feb. 25, 2020, 3:52 a.m.