EVOLUTION-MANAGER
Edit File: crossv_mc.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Generate test-training pairs for cross-validation</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for crossv_mc {modelr}"><tr><td>crossv_mc {modelr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Generate test-training pairs for cross-validation</h2> <h3>Description</h3> <p><code>crossv_kfold</code> splits the data into <code>k</code> exclusive partitions, and uses each partition for a test-training split. <code>crossv_mc</code> generates <code>n</code> random partitions, holding out <code>test</code> of the data for training. <code>crossv_loo</code> performs leave-one-out cross-validation, i.e., <code>n = nrow(data)</code> training partitions containing <code>n - 1</code> rows each. </p> <h3>Usage</h3> <pre> crossv_mc(data, n, test = 0.2, id = ".id") crossv_kfold(data, k = 5, id = ".id") crossv_loo(data, id = ".id") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>data</code></td> <td> <p>A data frame</p> </td></tr> <tr valign="top"><td><code>n</code></td> <td> <p>Number of test-training pairs to generate (an integer).</p> </td></tr> <tr valign="top"><td><code>test</code></td> <td> <p>Proportion of observations that should be held out for testing (a double).</p> </td></tr> <tr valign="top"><td><code>id</code></td> <td> <p>Name of variable that gives each model a unique integer id.</p> </td></tr> <tr valign="top"><td><code>k</code></td> <td> <p>Number of folds (an integer).</p> </td></tr> </table> <h3>Value</h3> <p>A data frame with columns <code>test</code>, <code>train</code>, and <code>.id</code>. <code>test</code> and <code>train</code> are list-columns containing <code><a href="resample.html">resample()</a></code> objects. The number of rows is <code>n</code> for <code>crossv_mc()</code>, <code>k</code> for <code>crossv_kfold()</code> and <code>nrow(data)</code> for <code>crossv_loo()</code>. </p> <h3>Examples</h3> <pre> cv1 <- crossv_kfold(mtcars, 5) cv1 library(purrr) cv2 <- crossv_mc(mtcars, 100) models <- map(cv2$train, ~ lm(mpg ~ wt, data = .)) errs <- map2_dbl(models, cv2$test, rmse) hist(errs) </pre> <hr /><div style="text-align: center;">[Package <em>modelr</em> version 0.1.8 <a href="00Index.html">Index</a>]</div> </body></html>