Skip to content

Bug when trying to tune hier_clust #206

@davidrsch

Description

@davidrsch

While trying to run a workflow in which in tune a hier_clust model I am receiving:

Error in check_grid() at tidyclust/R/tune_cluster.R:165:3:
! The provided grid has parameter column 'activation' that has not been marked for tuning by tune().

Which as the error states it's due to the fact that a parameter with identifier "activation" it's showing up in the grid, as you can see in the output of print(param_grid) of the following reprex:

install.packages(c("tidyclust", "dials", "parsnip"))
#> Installing packages into 'x/renv/library/windows/R-4.5/x86_64-w64-mingw32'
#> (as 'lib' is unspecified)
#> package 'tidyclust' successfully unpacked and MD5 sums checked
#> package 'dials' successfully unpacked and MD5 sums checked
#> package 'parsnip' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\x\AppData\Local\Temp\Rtmp2PKsV8\downloaded_packages

library(tidyclust)
library(dials)
#> Loading required package: scales
library(parsnip)
#> 
#> Attaching package: 'parsnip'
#> The following objects are masked from 'package:tidyclust':
#> 
#>     knit_engine_docs, list_md_problems

# Define the model with all tunable parameters
model <- hier_clust(
  num_clusters = tune(),
  linkage_method = tune()
) |>
  set_engine("stats") |>
  set_mode("partition")

# Define the parameter grid
param_grid <- dials::parameters(
  num_clusters(range = c(2, 3)),
  linkage_method(values = values_linkage_method)
)

# Show model and parameters
print(model)
#> Hierarchical Clustering Specification (partition)
#> 
#> Main Arguments:
#>   num_clusters = tune()
#>   linkage_method = tune()
#> 
#> Computational engine: stats
print(param_grid)
#> Collection of 2 parameters for tuning
#> 
#>    identifier         type    object
#>  num_clusters num_clusters nparam[+]
#>    activation   activation dparam[+]
#> 

I think this issue it's related to linkage_method due to that when I remove linkage_method tuning it works:

install.packages(c("tidyclust", "dials", "parsnip"))
#> Installing packages into 'x/renv/library/windows/R-4.5/x86_64-w64-mingw32'
#> (as 'lib' is unspecified)
#> package 'tidyclust' successfully unpacked and MD5 sums checked
#> package 'dials' successfully unpacked and MD5 sums checked
#> package 'parsnip' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\x\AppData\Local\Temp\Rtmp2PKsV8\downloaded_packages

library(tidyclust)
library(dials)
#> Loading required package: scales
library(parsnip)
#> 
#> Attaching package: 'parsnip'
#> The following objects are masked from 'package:tidyclust':
#> 
#>     knit_engine_docs, list_md_problems

# Define the model with all tunable parameters
model <- hier_clust(
  num_clusters = tune() # ,
  # linkage_method = tune()
) |>
  set_engine("stats") |>
  set_mode("partition")

# Define the parameter grid
param_grid <- dials::parameters(
  num_clusters(range = c(2, 3)) # ,
  # linkage_method(values = values_linkage_method)
)

# Show model and parameters
print(model)
#> Hierarchical Clustering Specification (partition)
#> 
#> Main Arguments:
#>   num_clusters = tune()
#>   linkage_method = complete
#> 
#> Computational engine: stats
print(param_grid)
#> Collection of 1 parameters for tuning
#> 
#>    identifier         type    object
#>  num_clusters num_clusters nparam[+]
#> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions