Learn R Programming

tidylearn (version 0.1.0)

tl_add_cluster_features: Cluster-Based Features

Description

Add cluster assignments as features for supervised learning. This semi-supervised approach can capture non-linear patterns.

Usage

tl_add_cluster_features(data, response = NULL, method = "kmeans", ...)

Value

Original data with cluster assignment column(s) added

Arguments

data

A data frame

response

Response variable name (will be excluded from clustering)

method

Clustering method: "kmeans", "pam", "hclust", "dbscan"

...

Additional arguments for clustering

Examples

Run this code
# \donttest{
# Add cluster features before supervised learning
data_with_clusters <- tl_add_cluster_features(iris, response = "Species",
                                                method = "kmeans", k = 3)
model <- tl_model(data_with_clusters, Species ~ ., method = "forest")
# }

Run the code above in your browser using DataLab