plot_train_valid_error: plot train/validation errors vs. parameter values

Description Usage Arguments Value Examples

View source: R/plot_train_valid_error.R

Description

Takes in a model name, train/validation data sets, a parameter name and a vector of parameter values to try and then plots train/validation errors vs. parameter values.

Usage

1
2
3
4
5
6
7
8
9
plot_train_valid_error(
  model_name,
  X_train,
  y_train,
  X_valid,
  y_valid,
  param_name,
  param_vec
)

Arguments

model_name

a string of the machine learning model name. Only 'knn', 'decision tree', 'svm', and 'random forests' are allowed.

X_train

a numeric data frame of the training dataset without labels.

y_train

a numeric vector or factor of the training labels.

X_valid

a numeric data frame of the validation dataset without labels.

y_valid

a numeric vector or factor of the validation labels.

param_name

a string of the parameter name. Please choose this parameter based on the following information: 'knn': 'k', 'decision tree': 'maxdepth', 'svm': 'cost' or 'gamma', 'random forests': 'ntree'.

param_vec

a numeric vector of the parameter values.

Value

A plot

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Not run: 
library(RMLViz)
data(iris)
set.seed(123)

split <- caTools::sample.split(iris$Species, SplitRatio = 0.75)
training_set <- subset(iris, split == TRUE)
valid_set <- subset(iris, split == FALSE)

X_train <- training_set[, -5]
y_train <- training_set[, 5]
X_valid <- valid_set[, -5]
y_valid <- valid_set[, 5]

plot_train_valid_error('knn',
                       X_train, y_train,
                       X_valid, y_valid,
                       'k', seq(50))

## End(Not run)

UBC-MDS/RMLViz documentation built on April 1, 2020, 4:35 a.m.