% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/TaskClassif.R
\name{TaskClassif}
\alias{TaskClassif}
\title{Classification Task}
\description{
This task specializes \link{Task} and \link{TaskSupervised} for classification problems.
The target column is assumed to be a factor or ordered factor.
The \code{task_type} is set to \code{"classif"}.

Additional task properties include:
\itemize{
\item \code{"twoclass"}: The task is a binary classification problem.
\item \code{"multiclass"}: The task is a multiclass classification problem.
}

It is recommended to use \code{\link[=as_task_classif]{as_task_classif()}} for construction.
Predefined tasks are stored in the \link[mlr3misc:Dictionary]{dictionary} \link{mlr_tasks}.
}
\examples{
data("Sonar", package = "mlbench")
task = as_task_classif(Sonar, target = "Class", positive = "M")

task$task_type
task$formula()
task$truth()
task$class_names
task$positive
task$data(rows = 1:3, cols = task$feature_names[1:2])
}
\seealso{
\itemize{
\item Chapter in the \href{https://mlr3book.mlr-org.com/}{mlr3book}:
\url{https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html}
\item Package \CRANpkg{mlr3data} for more toy tasks.
\item Package \CRANpkg{mlr3oml} for downloading tasks from \url{https://www.openml.org}.
\item Package \CRANpkg{mlr3viz} for some generic visualizations.
\item \link[mlr3misc:Dictionary]{Dictionary} of \link[=Task]{Tasks}: \link{mlr_tasks}
\item \code{as.data.table(mlr_tasks)} for a table of available \link[=Task]{Tasks} in the running session (depending on the loaded packages).
\item \CRANpkg{mlr3fselect} and \CRANpkg{mlr3filters} for feature selection and feature filtering.
\item Extension packages for additional task types:
\itemize{
\item Unsupervised clustering: \CRANpkg{mlr3cluster}
\item Probabilistic supervised regression and survival analysis: \url{https://mlr3proba.mlr-org.com/}.
}
}

Other Task:
\code{\link{Task}},
\code{\link{TaskRegr}},
\code{\link{TaskSupervised}},
\code{\link{TaskUnsupervised}},
\code{\link{california_housing}},
\code{\link{mlr_tasks}},
\code{\link{mlr_tasks_breast_cancer}},
\code{\link{mlr_tasks_german_credit}},
\code{\link{mlr_tasks_iris}},
\code{\link{mlr_tasks_mtcars}},
\code{\link{mlr_tasks_penguins}},
\code{\link{mlr_tasks_pima}},
\code{\link{mlr_tasks_sonar}},
\code{\link{mlr_tasks_spam}},
\code{\link{mlr_tasks_wine}},
\code{\link{mlr_tasks_zoo}}
}
\concept{Task}
\section{Super classes}{
\code{\link[mlr3:Task]{Task}} -> \code{\link[mlr3:TaskSupervised]{TaskSupervised}} -> \code{TaskClassif}
}
\section{Active bindings}{
  \if{html}{\out{<div class="r6-active-bindings">}}
  \describe{
    \item{\code{class_names}}{(\code{character()})\cr
Returns all class labels of the target column.}

    \item{\code{positive}}{(\code{character(1)})\cr
Stores the positive class for binary classification tasks, and \code{NA} for multiclass tasks.
To switch the positive class, assign a level to this field.}

    \item{\code{negative}}{(\code{character(1)})\cr
Stores the negative class for binary classification tasks, and \code{NA} for multiclass tasks.}
  }
  \if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
  \itemize{
    \item \href{#method-TaskClassif-initialize}{\code{TaskClassif$new()}}
    \item \href{#method-TaskClassif-print}{\code{TaskClassif$print()}}
    \item \href{#method-TaskClassif-truth}{\code{TaskClassif$truth()}}
    \item \href{#method-TaskClassif-droplevels}{\code{TaskClassif$droplevels()}}
    \item \href{#method-TaskClassif-clone}{\code{TaskClassif$clone()}}
  }
}
\if{html}{\out{<details><summary>Inherited methods</summary>
<ul>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="add_strata"><a href='../../mlr3/html/Task.html#method-Task-add_strata'><code>Task$add_strata()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="cbind"><a href='../../mlr3/html/Task.html#method-Task-cbind'><code>Task$cbind()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="data"><a href='../../mlr3/html/Task.html#method-Task-data'><code>Task$data()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="filter"><a href='../../mlr3/html/Task.html#method-Task-filter'><code>Task$filter()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="format"><a href='../../mlr3/html/Task.html#method-Task-format'><code>Task$format()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="formula"><a href='../../mlr3/html/Task.html#method-Task-formula'><code>Task$formula()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="head"><a href='../../mlr3/html/Task.html#method-Task-head'><code>Task$head()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="help"><a href='../../mlr3/html/Task.html#method-Task-help'><code>Task$help()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="levels"><a href='../../mlr3/html/Task.html#method-Task-levels'><code>Task$levels()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="materialize_view"><a href='../../mlr3/html/Task.html#method-Task-materialize_view'><code>Task$materialize_view()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="missings"><a href='../../mlr3/html/Task.html#method-Task-missings'><code>Task$missings()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="rbind"><a href='../../mlr3/html/Task.html#method-Task-rbind'><code>Task$rbind()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="rename"><a href='../../mlr3/html/Task.html#method-Task-rename'><code>Task$rename()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="select"><a href='../../mlr3/html/Task.html#method-Task-select'><code>Task$select()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="set_col_roles"><a href='../../mlr3/html/Task.html#method-Task-set_col_roles'><code>Task$set_col_roles()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="set_levels"><a href='../../mlr3/html/Task.html#method-Task-set_levels'><code>Task$set_levels()</code></a></span></li>
  <li><span class="pkg-link" data-pkg="mlr3" data-topic="Task" data-id="set_row_roles"><a href='../../mlr3/html/Task.html#method-Task-set_row_roles'><code>Task$set_row_roles()</code></a></span></li>
</ul>
</details>}}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-TaskClassif-initialize"></a>}}
\if{latex}{\out{\hypertarget{method-TaskClassif-initialize}{}}}
\subsection{\code{TaskClassif$new()}}{
  Creates a new instance of this \link[R6:R6Class]{R6} class.
The function \code{\link[=as_task_classif]{as_task_classif()}} provides an alternative way to construct classification tasks.
  \subsection{Usage}{
    \if{html}{\out{<div class="r">}}
    \preformatted{TaskClassif$new(
  id,
  backend,
  target,
  positive = NULL,
  label = NA_character_,
  extra_args = list()
)}
    \if{html}{\out{</div>}}
  }
  \subsection{Arguments}{
    \if{html}{\out{<div class="arguments">}}
    \describe{
      \item{\code{id}}{(\code{character(1)})\cr
Identifier for the new instance.}
      \item{\code{backend}}{(\link{DataBackend})\cr
Either a \link{DataBackend}, or any object which is convertible to a \link{DataBackend} with \code{as_data_backend()}.
E.g., a \code{data.frame()} will be converted to a \link{DataBackendDataTable}.}
      \item{\code{target}}{(\code{character(1)})\cr
Name of the target column.}
      \item{\code{positive}}{(\code{character(1)})\cr
Only for binary classification: Name of the positive class.
The levels of the target columns are reordered accordingly, so that the first element of \verb{$class_names} is the
positive class, and the second element is the negative class.}
      \item{\code{label}}{(\code{character(1)})\cr
Label for the new instance.}
      \item{\code{extra_args}}{(named \code{list()})\cr
Named list of constructor arguments, required for converting task types
via \code{\link[=convert_task]{convert_task()}}.}
    }
    \if{html}{\out{</div>}}
  }
}

\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-TaskClassif-print"></a>}}
\if{latex}{\out{\hypertarget{method-TaskClassif-print}{}}}
\subsection{\code{TaskClassif$print()}}{
  Printer.
  \subsection{Usage}{
    \if{html}{\out{<div class="r">}}
    \preformatted{TaskClassif$print(...)}
    \if{html}{\out{</div>}}
  }
  \subsection{Arguments}{
    \if{html}{\out{<div class="arguments">}}
    \describe{
      \item{\code{...}}{(ignored).}
    }
    \if{html}{\out{</div>}}
  }
}

\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-TaskClassif-truth"></a>}}
\if{latex}{\out{\hypertarget{method-TaskClassif-truth}{}}}
\subsection{\code{TaskClassif$truth()}}{
  True response for specified \code{row_ids}. Format depends on the task type.
Defaults to all rows with role \code{"use"}.
  \subsection{Usage}{
    \if{html}{\out{<div class="r">}}
    \preformatted{TaskClassif$truth(rows = NULL)}
    \if{html}{\out{</div>}}
  }
  \subsection{Arguments}{
    \if{html}{\out{<div class="arguments">}}
    \describe{
      \item{\code{rows}}{(positive \code{integer()} | \code{NULL})\cr
Vector or row indices.
Always refers to the complete data set, even after filtering.}
    }
    \if{html}{\out{</div>}}
  }
  \subsection{Returns}{
    \code{factor()}.
  }
}

\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-TaskClassif-droplevels"></a>}}
\if{latex}{\out{\hypertarget{method-TaskClassif-droplevels}{}}}
\subsection{\code{TaskClassif$droplevels()}}{
  Updates the cache of stored factor levels, removing all levels not present in the current set of active rows.
\code{cols} defaults to all columns with storage type "factor" or "ordered".
Also updates the task property \code{"twoclass"}/\code{"multiclass"}.
  \subsection{Usage}{
    \if{html}{\out{<div class="r">}}
    \preformatted{TaskClassif$droplevels(cols = NULL)}
    \if{html}{\out{</div>}}
  }
  \subsection{Arguments}{
    \if{html}{\out{<div class="arguments">}}
    \describe{
      \item{\code{cols}}{(\code{character()} | \code{NULL})\cr
Vector of column names.}
    }
    \if{html}{\out{</div>}}
  }
  \subsection{Returns}{
    Modified \code{self}.
  }
}

\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-TaskClassif-clone"></a>}}
\if{latex}{\out{\hypertarget{method-TaskClassif-clone}{}}}
\subsection{\code{TaskClassif$clone()}}{
  The objects of this class are cloneable with this method.
  \subsection{Usage}{
    \if{html}{\out{<div class="r">}}
    \preformatted{TaskClassif$clone(deep = FALSE)}
    \if{html}{\out{</div>}}
  }
  \subsection{Arguments}{
    \if{html}{\out{<div class="arguments">}}
    \describe{
      \item{\code{deep}}{Whether to make a deep clone.}
    }
    \if{html}{\out{</div>}}
  }
}

}
