Create cluster-specific supervised models for heterogeneous data
Usage
tl_stratified_models(
data,
formula,
cluster_method = "kmeans",
k = 3,
supervised_method = "tree",
...
)Arguments
- data
A data frame
- formula
Model formula
- cluster_method
Clustering method
- k
Number of clusters
- supervised_method
Supervised learning method (default:
"tree", which handles both regression and classification)."linear"silently fitslm()to a factor response rather than refusing it, so it is not a safe default here.- ...
Additional arguments
Value
A list with class "tidylearn_stratified" containing:
- cluster_model
The fitted clustering model.
- supervised_models
Named list of tidylearn models, one per cluster.
- formula
The model formula.
- data
The original training data.
Examples
# \donttest{
models <- tl_stratified_models(mtcars, mpg ~ ., cluster_method = "kmeans",
k = 3, supervised_method = "linear")
#> Note: Response 'mpg' has 6 unique numeric values. Treating as regression. Convert to factor for classification.
#> Note: Response 'mpg' has 8 unique numeric values. Treating as regression. Convert to factor for classification.
# }
