Skip to content

have step_isomap() error if neighbors equal or larger than the data #1522

@EmilHvitfeldt

Description

@EmilHvitfeldt

This should happen in prep.step_isomap(). As we can check x$neighbors against nrow(training) but should properly happen inside the if (x$num_terms > 0 && length(col_names) > 0L) { chunk to avoid this error from triggering if nothing is selected.

library(recipes)

recipe(mpg ~ ., data = mtcars) |>
  step_isomap(all_numeric_predictors(), neighbors = 31) |>
  prep()
#> ── Recipe ──────────────────────────────────────────────────────────────────────
#> 
#> ── Inputs
#> Number of variables by role
#> outcome:    1
#> predictor: 10
#> 
#> ── Training information
#> Training data contained 32 data points and no incomplete rows.
#> 
#> ── Operations
#> • Isomap approximation with: cyl, disp, hp, drat, wt, qsec, ... | Trained


recipe(mpg ~ ., data = mtcars) |>
  step_isomap(all_numeric_predictors(), neighbors = 32) |>
  prep()
#> Error in `step_isomap()`:
#> Caused by error in `prep()`:
#> ! Failed to compute:
#> Caused by error in `RANN::nn2()`:
#> ! Cannot find more nearest neighbours than there are points

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancementtidy-dev-day 🤓Tidyverse Developer Day rstd.io/tidy-dev-day

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions