Revision 272ac623c984dbf5defce76b6495c05accafe79f authored by Patrick Schratz on 17 December 2019, 04:08:28 UTC, committed by Patrick Schratz on 17 December 2019, 04:08:28 UTC
Build URL: https://circleci.com/gh/mlr-org/mlr/1264
Commit:
1 parent 9de9c6e
Raw File
getTaskData.Rd
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/Task_operators.R
\name{getTaskData}
\alias{getTaskData}
\title{Extract data in task.}
\usage{
getTaskData(
  task,
  subset = NULL,
  features,
  target.extra = FALSE,
  recode.target = "no",
  functionals.as = "dfcols"
)
}
\arguments{
\item{task}{(\link{Task})\cr
The task.}

\item{subset}{(\link{integer} | \link{logical} | \code{NULL})\cr
Selected cases. Either a logical or an index vector.
By default \code{NULL} if all observations are used.}

\item{features}{(\link{character} | \link{integer} | \link{logical})\cr
Vector of selected inputs. You can either pass a character vector with the
feature names, a vector of indices, or a logical vector.\cr
In case of an index vector each element denotes the position of the feature
name returned by \link{getTaskFeatureNames}.\cr
Note that the target feature is always included in the
resulting task, you should not pass it here.
Default is to use all features.}

\item{target.extra}{(\code{logical(1)})\cr
Should target vector be returned separately?
If not, a single data.frame including the target columns is returned, otherwise a list
with the input data.frame and an extra vector or data.frame for the targets.
Default is \code{FALSE}.}

\item{recode.target}{(\code{character(1)})\cr
Should target classes be recoded? Supported are binary and multilabel classification and survival.
Possible values for binary classification are \dQuote{01}, \dQuote{-1+1} and \dQuote{drop.levels}.
In the two latter cases the target vector is converted into a numeric vector.
The positive class is coded as \dQuote{+1} and the negative class either as \dQuote{0} or \dQuote{-1}.
\dQuote{drop.levels} will remove empty factor levels in the target column.
In the multilabel case the logical targets can be converted to factors with \dQuote{multilabel.factor}.
For survival, you may choose to recode the survival times to \dQuote{left}, \dQuote{right} or \dQuote{interval2} censored times
using \dQuote{lcens}, \dQuote{rcens} or \dQuote{icens}, respectively.
See \link[survival:Surv]{survival::Surv} for the format specification.
Default for both binary classification and survival is \dQuote{no} (do nothing).}

\item{functionals.as}{(\code{character(1)})\cr
How to represents functional features?
Option \dQuote{matrix}: Keep them as matrix columns in the data.frame.
Option \dQuote{dfcols}: Convert them to individual numeric data.frame columns.
Default is \dQuote{dfcols}.}
}
\value{
Either a data.frame or a list with data.frame \code{data} and vector \code{target}.
}
\description{
Useful in \link{trainLearner} when you add a learning machine to the package.
}
\examples{
library("mlbench")
data(BreastCancer)

df = BreastCancer
df$Id = NULL
task = makeClassifTask(id = "BreastCancer", data = df, target = "Class", positive = "malignant")
head(getTaskData)
head(getTaskData(task, features = c("Cell.size", "Cell.shape"), recode.target = "-1+1"))
head(getTaskData(task, subset = 1:100, recode.target = "01"))
}
\seealso{
Other task: 
\code{\link{getTaskClassLevels}()},
\code{\link{getTaskCosts}()},
\code{\link{getTaskDesc}()},
\code{\link{getTaskFeatureNames}()},
\code{\link{getTaskFormula}()},
\code{\link{getTaskId}()},
\code{\link{getTaskNFeats}()},
\code{\link{getTaskSize}()},
\code{\link{getTaskTargetNames}()},
\code{\link{getTaskTargets}()},
\code{\link{getTaskType}()},
\code{\link{subsetTask}()}
}
\concept{task}
back to top