cplot2d: 2D Scatter Plot with Classification Labels

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

View source: R/cplot2d.R

Description

cplot2d produces two dimensional scatter plot with classification labels of binary classes.

Usage

1
2
cplot2d(x1, x2, ypred, yobs, colors = c("red", "blue"), symbols = c("circle", "o"), 
  size = 10, xlab = NULL, ylab = NULL, title = NULL)

Arguments

x1

the horizontal coordinate of points in the plot.

x2

the vertical coordinate of points in the plot.

ypred

a factor of the predicted binary response variable.

yobs

a factor of the observed binary response variable.

colors

a vector of two colors specifying the levels of the observed binary response variable.

symbols

a vector of two symbols specifying the levels of the predicted binary response variable.

size

the size of symbols.

xlab

a label for the x axis, defaults to a description of x1.

ylab

a label for the y axis, defaults to a description of x2.

title

a main title of the plot.

Details

Symbols indicate the observed classes of binary response. Colors show TRUE or FALSE classification of the observations.

Value

An object with class "plotly" and "htmlwidget".

Author(s)

Osman Dag

See Also

plot_ly

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
library(GMDH2)

library(mlbench)
data(BreastCancer)

data <- BreastCancer

# to obtain complete observations
completeObs <- complete.cases(data)
data <- data[completeObs,]

x <- data.matrix(data[,2:10])
y <- data[,11]

seed <- 12345
set.seed(seed)
nobs <- length(y)

# to split train, validation and test sets

indices <- sample(1:nobs)

ntrain <- round(nobs*0.6,0)
nvalid <- round(nobs*0.2,0)
ntest <- nobs-(ntrain+nvalid)

train.indices <- sort(indices[1:ntrain])
valid.indices <- sort(indices[(ntrain+1):(ntrain+nvalid)])
test.indices <- sort(indices[(ntrain+nvalid+1):nobs])


x.train <- x[train.indices,]
y.train <- y[train.indices]

x.valid <- x[valid.indices,]
y.valid <- y[valid.indices]

x.test <- x[test.indices,]
y.test <- y[test.indices]

set.seed(seed)
# to construct model via dce-GMDH algorithm
model <- dceGMDH(x.train, y.train, x.valid, y.valid)

# to obtain predicted classes for test set
y.test_pred <- predict(model, x.test, type = "class")

# to obtain confusion matrix and some statistics for test set
confMat(y.test_pred, y.test, positive = "malignant")

# to produce 2D scatter plot with classification labels for test set
cplot2d(x.test[,1], x.test[,6], y.test_pred, y.test, symbols = c("x", "o"))
cplot2d(x.test[,1], x.test[,6], y.test_pred, y.test, colors = c("red", "black"))

GMDH2 documentation built on June 26, 2018, 5:02 p.m.