---
title: "clustering"
output: html_document
vignette: >
  %\VignetteIndexEntry{clustering}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
  digits = 3,
  collapse = TRUE,
  comment = "#>"
)
options(digits = 3)
```

## R Markdown

We load de data:

```{r eval=TRUE,  results="hide", warning=FALSE,message=FALSE}

library(tidyverse)
library(caret)
library(SSLR)
library(tidymodels)
```

```{r data, results="hide"}
data(wine)

data <- iris

set.seed(1)
#% LABELED
cls <- which(colnames(iris) == "Species")

labeled.index <- createDataPartition(data$Species, p = .2, list = FALSE)
data[-labeled.index,cls] <- NA

```

For example, we can train with Constrained Kmeans:

```{r fit, results="hide"}
m <- constrained_kmeans() %>% fit(Species ~ ., data)

```

Labels:

```{r labels}
m %>% cluster_labels()

```

Centers:

```{r centers}
m %>% get_centers()

```


We can plot clusters with factoextra:

```{r clusters, warning=FALSE,message=FALSE}
library(factoextra)
fviz_cluster(m$model, as.matrix(data[,-cls]))

```

