|
| 1 | +#' Extract elements of a tidyclust model object |
| 2 | +#' |
| 3 | +#' @description |
| 4 | +#' These functions extract various elements from a clustering object. If they do |
| 5 | +#' not exist yet, an error is thrown. |
| 6 | +#' |
| 7 | +#' - `extract_fit_engine()` returns the engine specific fit embedded within |
| 8 | +#' a tidyclust model fit. For example, when using [tidyclust::k_means()] |
| 9 | +#' with the `"lm"` engine, this returns the underlying `kmeans` object. |
| 10 | +#' |
| 11 | +#' - `extract_parameter_set_dials()` returns a set of dials parameter objects. |
| 12 | +#' |
| 13 | +#' @param x A `cluster_fit` object or a `cluster_spec` object. |
| 14 | +#' @param ... Not currently used. |
| 15 | +#' @details |
| 16 | +#' Extracting the underlying engine fit can be helpful for describing the |
| 17 | +#' model (via `print()`, `summary()`, `plot()`, etc.) or for variable |
| 18 | +#' importance/explainers. |
| 19 | +#' |
| 20 | +#' However, users should not invoke the `predict()` method on an extracted |
| 21 | +#' model. There may be preprocessing operations that `tidyclust` has executed |
| 22 | +#' on the data prior to giving it to the model. Bypassing these can lead to |
| 23 | +#' errors or silently generating incorrect predictions. |
| 24 | +#' |
| 25 | +#' **Good**: |
| 26 | +#' ```r |
| 27 | +#' tidyclust_fit %>% predict(new_data) |
| 28 | +#' ``` |
| 29 | +#' |
| 30 | +#' **Bad**: |
| 31 | +#' ```r |
| 32 | +#' tidyclust_fit %>% extract_fit_engine() %>% predict(new_data) |
| 33 | +#' ``` |
| 34 | +#' @return |
| 35 | +#' The extracted value from the tidyclust object, `x`, as described in the |
| 36 | +#' description section. |
| 37 | +#' |
| 38 | +#' @name extract-tidyclust |
| 39 | +#' @examples |
| 40 | +#' kmeans_spec <- k_means(num_clusters = 2) |
| 41 | +#' kmeans_fit <- fit(kmeans_spec, ~ ., data = mtcars) |
| 42 | +#' |
| 43 | +#' extract_fit_engine(kmeans_fit) |
| 44 | +NULL |
| 45 | + |
| 46 | + |
| 47 | +#' @rdname extract-tidyclust |
1 | 48 | #' @export |
2 | 49 | extract_fit_engine.cluster_fit <- function (x, ...) { |
3 | 50 | if (any(names(x) == "fit")) { |
|
0 commit comments