logRegMulti: Multinomial Regression

Description Usage Arguments Details Value Examples

View source: R/logRegMulti.R

Description

Runs a multinomial regression model, evaluates it on training and testing set, and tunes hyperparameters.

Usage

1
2
3
4
5
6
7
8
9
logRegMulti(
  recipe = rec,
  folds = cvFolds,
  train = train_df,
  test = test_df,
  response = response,
  gridNum = 15,
  evalMetric = "bal_accuracy"
)

Arguments

recipe

A recipe object.

folds

A rsample::vfolds_cv object.

train

Data frame/tibble. The training data set.

test

Data frame/tibble. The testing data set.

response

Character. The variable that is the response for analysis.

gridNum

Numeric. The number of levels you want the grid to search on. Default is 15.

evalMetric

Character. The classification metric you want to evaluate the model's accuracy on. Default is bal_accuracy. List of metrics available to choose from:

  • bal_accuracy

  • mn_log_loss

  • roc_auc

  • mcc

  • kap

  • sens

  • spec

  • precision

  • recall

Details

What the model tunes:

Value

A list with the following outputs:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
library(easytidymodels)
library(dplyr)
library(recipes)
utils::data(penguins, package = "modeldata")
#Define your response variable and formula object here
resp <- "sex"
formula <- stats::as.formula(paste(resp, ".", sep="~"))
#Split data into training and testing sets
split <- trainTestSplit(penguins, stratifyOnResponse = TRUE,
responseVar = resp)
#Create recipe for feature engineering for dataset, varies based on data working with
rec <- recipe(formula, data = split$train) %>% step_knnimpute(!!resp) %>%
step_dummy(all_nominal(), -all_outcomes()) %>%
step_medianimpute(all_predictors()) %>% step_normalize(all_predictors()) %>%
step_dummy(all_nominal(), -all_outcomes()) %>% step_nzv(all_predictors()) %>%
step_corr(all_numeric(), -all_outcomes(), threshold = .8) %>% prep()
train_df <- bake(rec, split$train)
test_df <- bake(rec, split$test)
folds <- cvFolds(train_df)
#mr <- logRegMulti(recipe = rec, response = resp, folds = folds,
#train = train_df, test = test_df)

#Confusion Matrix
#mr$trainConfMat

#Plot of confusion matrix
#mr$trainConfMatPlot

#Test Confusion Matrix
#mr$testConfMat

#Test Confusion Matrix Plot
#mr$testConfMatPlot

amanda-park/easytidymodels documentation built on Dec. 13, 2021, 11:28 a.m.