has_multi_predict: Tools for models that predict on sub-models

Description Usage Arguments Value Examples

View source: R/aaa_multi_predict.R

Description

has_multi_predict() tests to see if an object can make multiple predictions on submodels from the same object. multi_predict_args() returns the names of the arguments to multi_predict() for this model (if any).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
has_multi_predict(object, ...)

## Default S3 method:
has_multi_predict(object, ...)

## S3 method for class 'model_fit'
has_multi_predict(object, ...)

## S3 method for class 'workflow'
has_multi_predict(object, ...)

multi_predict_args(object, ...)

## Default S3 method:
multi_predict_args(object, ...)

## S3 method for class 'model_fit'
multi_predict_args(object, ...)

## S3 method for class 'workflow'
multi_predict_args(object, ...)

Arguments

object

An object to test.

...

Not currently used.

Value

has_multi_predict() returns single logical value while multi_predict() returns a character vector of argument names (or NA if none exist).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
lm_model_idea <- linear_reg() %>% set_engine("lm")
has_multi_predict(lm_model_idea)
lm_model_fit <- fit(lm_model_idea, mpg ~ ., data = mtcars)
has_multi_predict(lm_model_fit)

multi_predict_args(lm_model_fit)

library(kknn)

knn_fit <-
  nearest_neighbor(mode = "regression", neighbors = 5) %>%
  set_engine("kknn") %>%
  fit(mpg ~ ., mtcars)

multi_predict_args(knn_fit)

multi_predict(knn_fit, mtcars[1, -1], neighbors = 1:4)$.pred

parsnip documentation built on July 8, 2020, 7:22 p.m.