File: downSample.Rd

package info (click to toggle)
r-cran-caret 7.0-1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 210; sh: 10; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,397 bytes parent folder | download | duplicates (3)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sampling.R
\name{downSample}
\alias{downSample}
\alias{upSample}
\title{Down- and Up-Sampling Imbalanced Data}
\usage{
downSample(x, y, list = FALSE, yname = "Class")
}
\arguments{
\item{x}{a matrix or data frame of predictor variables}

\item{y}{a factor variable with the class memberships}

\item{list}{should the function return \code{list(x, y)} or bind \code{x}
and \code{y} together? If \code{FALSE}, the output will be coerced to a data
frame.}

\item{yname}{if \code{list = FALSE}, a label for the class column}
}
\value{
Either a data frame or a list with elements \code{x} and \code{y}.
}
\description{
\code{downSample} will randomly sample a data set so that all classes have
the same frequency as the minority class. \code{upSample} samples with
replacement to make the class distributions equal
}
\details{
Simple random sampling is used to down-sample for the majority class(es).
Note that the minority class data are left intact and that the samples will
be re-ordered in the down-sampled version.

For up-sampling, all the original data are left intact and additional
samples are added to the minority classes with replacement.
}
\examples{

## A ridiculous example...
data(oil)
table(oilType)
downSample(fattyAcids, oilType)

upSample(fattyAcids, oilType)


}
\author{
Max Kuhn
}
\keyword{utilities}