In [5]:
suppressMessages(library(bnlearn))
set.seed(201703)
load("../transformed data/paper29.rda")
k = c(5,10,20,30,50,70,90)
# kmeans method
km_50 = empty.graph(c("class", colnames(data.frame(train_kmeans))))
#km_set = cbind( from = colnames(data.frame(golub_train_p_trans[,kmeans_id])), to = rep("class", k[5]))
arcs(km_50) = matrix(c(rep("class", k[5]),
colnames(data.frame(train_kmeans))),
ncol = 2, byrow = F, dimnames = list(c(), c("from", "to")))
#plot(km)
km_fitted_50 = bn.fit(km_50, train_kmeans_50)
km_predict_train_50 = predict(km_fitted_50, node = "class", method="bayes-lw", train_kmeans_50)
km_predict_test_50 = predict(km_fitted_50, node = "class", method="bayes-lw", test_kmeans_50)
table(Predict_train = km_predict_train_50, True = train_kmeans_50$class)
table(Predict_test = km_predict_test_50, True = golub_test_r)