Create cluster-specific supervised models for heterogeneous data
Usage
tl_stratified_models(
data,
formula,
cluster_method = "kmeans",
k = 3,
supervised_method = "tree",
...,
cluster_args = list()
)Arguments
- data
A data frame
- formula
Model formula
- cluster_method
Clustering method:
"kmeans"(default),"pam","clara"or"hclust", whose tree is cut atk. Only k-means can assign new rows, so the others predict their training data alone.- k
Number of clusters
- supervised_method
Supervised learning method (default:
"tree", which handles both regression and classification)."linear"needs a numeric response and refuses a factor.- ...
Additional arguments for the supervised models
- cluster_args
A named list of arguments for the clustering step, such as
list(nstart = 5)for k-means. Pass k ask.
Value
A list with class "tidylearn_stratified" containing:
- cluster_model
The fitted clustering model.
- clusters
The training rows' cluster assignments.
- supervised_models
Named list of tidylearn models, one per cluster that holds more than one class.
- single_class_clusters
Named character vector giving, for each cluster whose rows all hold one class, that class.
- formula
The model formula.
- data
The original training data.
