Author: Catherine B. Hurley
Date: 2022-09-14

# parsnip fits and condvis2

#### Catherine B. Hurley

#### 2022-09-14

`parsnip` is a R package that offers a unified interface to many machine learning models. By writing an interface between `condvis2` and `parsnip` a vast number of machine learning fits may be explored with `condvis`.

A list of models supported by parsnip is found on this link: https://www.tidymodels.org/find/parsnip/

## Regression

Fit the regression model with parsnip.

    library(parsnip)
    library(MASS)
    library(condvis2)
    Boston1 <- Boston[,9:14]

    fitlm <-
      linear_reg() %>%
      set_engine("lm") %>%
      fit(medv ~ ., data = Boston1)

    fitrf <- rand_forest(mode="regression") %>%
      set_engine("randomForest") %>%
      fit(medv ~ ., data = Boston1)

Use condvis to explore the models:

    condvis(Boston1, model=list(lm=fitlm,rf=fitrf), response="medv", sectionvars="lstat")

Choose tour “Diff fits” to explore differences between the fits

Some tasks, for example linear regression, support confidence intervals. Tell `condvis` to plot an interval using `pinterval="confidence` for that fit. The forest fit does not support confidence intervals so the predictArgs for that fit are NULL.

    condvis(Boston1, model=list(lm=fitlm,rf=fitrf), response="medv", sectionvars="lstat",
            predictArgs=list(list(pinterval="confidence"), NULL))

## Classification

Fit some classification models:

    clmodel <-
       svm_poly(mode="classification") %>%
      set_engine("kernlab") %>%
      fit(Species ~ ., data = iris )

Explore with `condvis`:

    condvis(iris, model=clmodel, response="Species", sectionvars=c("Petal.Length", "Petal.Width"), pointColor="Species")

Click on “Show probs” to see class probabilities.

## Survival

Fit a survival model and explore with condvis:

    library(survival) # for the data
    smodel <-
      surv_reg() %>%
      set_engine("survival") %>%
      fit(Surv(time, status) ~ inst+age+sex+ph.ecog, data=lung)

    condvis(na.omit(lung), smodel, response="time", sectionvars = c("inst","sex"), conditionvars=c("age","ph.ecog"))

## Clustering

Unlike `mlr`, `parsnip` does not yet offer support for clustering fits.