Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure that prefix argument is passed through extraction functions #145

Merged
merged 1 commit into from
Aug 11, 2023

Conversation

EmilHvitfeldt
Copy link
Member

These functions now follow the documented behavior.

library(tidyclust)

spec <- k_means(num_clusters = 4) |>
  fit(~., data = mtcars)

extract_centroids(spec)
#> # A tibble: 4 × 12
#>   .cluster    mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>   <fct>     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Cluster_1  15.1     8 353.  209.   3.23  4.00  16.8 0     0.143  3.29  3.5 
#> 2 Cluster_2  19.7     6 183.  122.   3.59  3.12  18.0 0.571 0.429  3.86  3.43
#> 3 Cluster_3  24.2     4 122.   94.3  3.92  2.51  19.1 0.857 0.571  4.14  1.71
#> 4 Cluster_4  31       4  76.1  62.2  4.33  1.90  19.2 1     1      4     1.25

extract_centroids(spec, prefix = "c_")
#> # A tibble: 4 × 12
#>   .cluster   mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>   <fct>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 c_1       15.1     8 353.  209.   3.23  4.00  16.8 0     0.143  3.29  3.5 
#> 2 c_2       19.7     6 183.  122.   3.59  3.12  18.0 0.571 0.429  3.86  3.43
#> 3 c_3       24.2     4 122.   94.3  3.92  2.51  19.1 0.857 0.571  4.14  1.71
#> 4 c_4       31       4  76.1  62.2  4.33  1.90  19.2 1     1      4     1.25

extract_cluster_assignment(spec)
#> # A tibble: 32 × 1
#>    .cluster 
#>    <fct>    
#>  1 Cluster_1
#>  2 Cluster_1
#>  3 Cluster_2
#>  4 Cluster_1
#>  5 Cluster_3
#>  6 Cluster_1
#>  7 Cluster_3
#>  8 Cluster_2
#>  9 Cluster_2
#> 10 Cluster_1
#> # ℹ 22 more rows

extract_cluster_assignment(spec, prefix = "c_")
#> # A tibble: 32 × 1
#>    .cluster
#>    <fct>   
#>  1 c_1     
#>  2 c_1     
#>  3 c_2     
#>  4 c_1     
#>  5 c_3     
#>  6 c_1     
#>  7 c_3     
#>  8 c_2     
#>  9 c_2     
#> 10 c_1     
#> # ℹ 22 more rows

predict(spec, mtcars)
#> # A tibble: 32 × 1
#>    .pred_cluster
#>    <fct>        
#>  1 Cluster_1    
#>  2 Cluster_1    
#>  3 Cluster_2    
#>  4 Cluster_1    
#>  5 Cluster_3    
#>  6 Cluster_1    
#>  7 Cluster_3    
#>  8 Cluster_2    
#>  9 Cluster_2    
#> 10 Cluster_1    
#> # ℹ 22 more rows

predict(spec, mtcars, prefix = "c_")
#> # A tibble: 32 × 1
#>    .pred_cluster
#>    <fct>        
#>  1 c_1          
#>  2 c_1          
#>  3 c_2          
#>  4 c_1          
#>  5 c_3          
#>  6 c_1          
#>  7 c_3          
#>  8 c_2          
#>  9 c_2          
#> 10 c_1          
#> # ℹ 22 more rows

Created on 2023-08-11 with reprex v2.0.2

@EmilHvitfeldt EmilHvitfeldt merged commit 59c6f4b into main Aug 11, 2023
10 checks passed
@EmilHvitfeldt EmilHvitfeldt deleted the pass-prefix branch August 11, 2023 22:57
@github-actions
Copy link

This pull request has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant