context("model-training")
data(pedis)
X_y <- prepare_X_y(data = pedis, outcome = "minor_amputation", vars = c("p", "d"))
k = sample(3:6, size = 1)
times = 5
folds <- create_folds(y = X_y$y, k = k, times = times)
fit <- train_pedis(X = X_y$X, y = X_y$y, folds = folds)
test_predicted_df <- test_predict(fit = fit)
train_predicted_df <- train_predict(folds = folds, X_y = X_y)
testthat::test_that("Model fitting works", {
testthat::expect_equal(length(folds), k * times)
testthat::expect_true(is.list(folds))
testthat::expect_lte(max(test_predicted_df$yes), expected = 1)
testthat::expect_gte(min(test_predicted_df$yes), expected = 0)
testthat::expect_true(is.data.frame(train_predicted_df))
})
# data preprocessing
# create output vector and matrix of predictors
X_y <- prepare_X_y(data = pedis, outcome = "minor_amputation", vars = c("p", "d", "i", "s"))
folds <- create_folds(y = X_y$y)
# Model training
fit <- train_pedis(X = X_y$X, y = X_y$y, folds = folds)
# Prediction
# prediction for the first fold in the list
train_predicted <- train_predict(folds = folds[[1]], X_y = X_y)
# Test Set
test_predict(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.