## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(clusta)

## ----toy----------------------------------------------------------------------
data(smpdp_toy)
res <- spectral_mpdp(smpdp_toy[, 1:2], h = 2,
                     k_neighbors = 2, mutual = FALSE)
table(true = smpdp_toy$class,
      predicted = res$cluster_results$cluster)

## ----clusta-interface---------------------------------------------------------
fit <- clusta(smpdp_toy[, 1:2], k = 2,
              method = "spectral", k_neighbors = 2)
fit$distr
fit$cluster

## ----ceramic------------------------------------------------------------------
data(ceramic)
X <- ceramic[, setdiff(names(ceramic), "class")]
set.seed(12345)
pred <- spectral_mpdp(X, h = 2, k_neighbors = 41)$cluster_results$cluster
cluster_metrics(X, ceramic$class, pred)

## ----object-------------------------------------------------------------------
res <- spectral_mpdp(X, h = 2, k_neighbors = 41)
res
names(attributes(res))
head(res$cluster_results[, c("score", "cluster", "confidence")], 3)

## ----figs, eval = FALSE-------------------------------------------------------
# plot(res, "clusters")
# plot(res, "signal")
# plot(res, "confidence")
# plot(res, "eigengap")
# plot(res, "similarity")
# plot(res, "profile")
# 
# ggplot2::autoplot(res, "clusters")

## ----suggestk-----------------------------------------------------------------
suggest_k(X, k_neighbors = 41, k_max = 8)

## ----stability----------------------------------------------------------------
cluster_stability(X, h = 2, k_neighbors = 41, B = 10, seed = 12345)

## ----sens, eval = FALSE-------------------------------------------------------
# d <- gen_two_moons(300)
# s <- smpdp_sensitivity(d[, c("x", "y")], d$class,
#                        k_grid = c(5, 10, 15, 20, 30),
#                        h_grid = 2:3)
# s
# plot(s)

## ----bench, eval = FALSE------------------------------------------------------
# preds <- run_clustering_benchmarks(
#   iris[, 1:4], L = 3, k_neb = 50,
#   methods = c("S-MPDP", "K-Means", "Spectral", "Agglomerative")
# )
# metrics <- t(sapply(preds, function(p) {
#   cluster_metrics(iris[, 1:4], iris$Species, p,
#                   metrics = c("ARI", "NMI", "Silhouette"))
# }))
# round(metrics, 3)

## ----ranks, eval = FALSE------------------------------------------------------
# friedman_ranks(ari_table)

