predict.cluster_fit | R Documentation |
Apply a model to create different types of predictions.
predict()
can be used for all types of models and uses the
"type" argument for more specificity.
## S3 method for class 'cluster_fit' predict(object, new_data, type = NULL, opts = list(), ...)
object |
An object of class |
new_data |
A rectangular data object, such as a data frame. |
type |
A single character value or |
opts |
A list of optional arguments to the underlying
predict function that will be used when |
... |
Arguments to the underlying model's prediction
function cannot be passed here (see |
If "type" is not supplied to predict()
, then a choice
is made:
type = "cluster"
for clustering models
predict()
is designed to provide a tidy result (see "Value"
section below) in a tibble output format.
With the exception of type = "raw"
, the results of
predict.cluster_fit()
will be a tibble as many rows in the output
as there are rows in new_data
and the column names will be
predictable.
For clustering results with a single outcome, the tibble will have
a .pred_cluster
.
Using type = "raw"
with predict.cluster_fit()
will return
the unadulterated results of the prediction function.
When the model fit failed and the error was captured, the
predict()
function will return the same structure as above but
filled with missing values. This does not currently work for
multivariate models.
kmeans_spec <- k_means(k = 5) %>% set_engine_celery("stats") kmeans_fit <- fit(kmeans_spec, ~., mtcars) kmeans_fit %>% predict(new_data = mtcars)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.