n <- 1000
x1 <- runif(n, 1, 10)
x2 <- runif(n, 1, 10)
x <- cbind(x1, x2)
y <- as.factor(ifelse(3 < x1 & x1 < 7 & 3 < x2 & x2 < 7, "A", "B"))
m_pcccd <- pcccd_classifier(x = x, y = y)
# dataset
plot(x, col = y, asp = 1)
# dominant samples of first class
x_center <- m_pcccd$x_dominant_list[[1]]
# radii of balls for first class
radii <- m_pcccd$radii_dominant_list[[1]]
# balls
for (i in 1:nrow(x_center)) {
xx <- x_center[i, 1]
yy <- x_center[i, 2]
r <- radii[i]
theta <- seq(0, 2*pi, length.out = 100)
xx <- xx + r*cos(theta)
yy <- yy + r*sin(theta)
lines(xx, yy, type = "l", col = "green")
}
# testing the performance
i_train <- sample(1:n, round(n*0.8))
x_train <- x[i_train,]
y_train <- y[i_train]
x_test <- x[-i_train,]
y_test <- y[-i_train]
m_pcccd <- pcccd_classifier(x = x_train, y = y_train)
pred <- predict(object = m_pcccd, newdata = x_test)
# confusion matrix
table(y_test, pred)
# test accuracy
sum(y_test == pred)/nrow(x_test)
Run the code above in your browser using DataLab