DecisionTreeClassifier {less}R Documentation

DecisionTreeClassifier

Description

Wrapper R6 Class of rpart::rpart function that can be used for LESSRegressor and LESSClassifier

Value

R6 Class of DecisionTreeClassifier

Super classes

less::BaseEstimator -> less::SklearnEstimator -> DecisionTreeClassifier

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of R6 Class of DecisionTreeClassifier

Usage
DecisionTreeClassifier$new(
  min_samples_split = 2,
  min_samples_leaf = 1,
  cp = 0.001,
  xval = 10,
  surrogate_style = 0,
  max_depth = 30
)
Arguments
min_samples_split

The minimum number of observations that must exist in a node in order for a split to be attempted (defaults to 2).

min_samples_leaf

The minimum number of observations in any terminal (leaf) node (defaults to 1).

cp

Complexity Parameter. Any split that does not decrease the overall lack of fit by a factor of cp is not attempted. This means that the overall R-squared must increase by cp at each step. The main role of this parameter is to save computing time by pruning off splits that are obviously not worthwhile. (defaults to 0.001)

xval

Number of cross-validations (defaults to 10)

surrogate_style

Controls the selection of a best surrogate. If set to 0 (default) the program uses the total number of correct classification for a potential surrogate variable, if set to 1 it uses the percent correct, calculated over the non-missing values of the surrogate. The first option more severely penalizes covariates with a large number of missing values.

max_depth

The maximum depth of any node of the final tree, with the root node counted as depth 0. Values greater than 30 will give nonsense results on 32-bit machines.

Examples
dt <- DecisionTreeClassifier$new()
dt <- DecisionTreeClassifier$new(min_samples_split = 10)
dt <- DecisionTreeClassifier$new(min_samples_leaf = 6, cp = 0.01)

Method fit()

Builds a decision tree regressor from the training set (X, y).

Usage
DecisionTreeClassifier$fit(X, y)
Arguments
X

2D matrix or dataframe that includes predictors

y

1D vector or (n,1) dimensional matrix/dataframe that includes labels

Returns

Fitted R6 Class of DecisionTreeClassifier

Examples
data(iris)
split_list <- train_test_split(iris, test_size =  0.3)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]

dt <- DecisionTreeClassifier$new()
dt$fit(X_train, y_train)

Method predict()

Predict regression value for X0.

Usage
DecisionTreeClassifier$predict(X0)
Arguments
X0

2D matrix or dataframe that includes predictors

Returns

Factor of the predict classes.

Examples
dt <- DecisionTreeClassifier$new()
dt$fit(X_train, y_train)
preds <- dt$predict(X_test)

dt <- DecisionTreeClassifier$new()
preds <- dt$fit(X_train, y_train)$predict(X_test)

preds <- DecisionTreeClassifier$new()$fit(X_train, y_train)$predict(X_test)
print(caret::confusionMatrix(data=preds, reference = factor(y_test)))

Method get_estimator_type()

Auxiliary function returning the estimator type e.g 'regressor', 'classifier'

Usage
DecisionTreeClassifier$get_estimator_type()
Examples
dt$get_estimator_type()

Method clone()

The objects of this class are cloneable with this method.

Usage
DecisionTreeClassifier$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

rpart::rpart()

Examples


## ------------------------------------------------
## Method `DecisionTreeClassifier$new`
## ------------------------------------------------

dt <- DecisionTreeClassifier$new()
dt <- DecisionTreeClassifier$new(min_samples_split = 10)
dt <- DecisionTreeClassifier$new(min_samples_leaf = 6, cp = 0.01)

## ------------------------------------------------
## Method `DecisionTreeClassifier$fit`
## ------------------------------------------------

data(iris)
split_list <- train_test_split(iris, test_size =  0.3)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]

dt <- DecisionTreeClassifier$new()
dt$fit(X_train, y_train)

## ------------------------------------------------
## Method `DecisionTreeClassifier$predict`
## ------------------------------------------------

dt <- DecisionTreeClassifier$new()
dt$fit(X_train, y_train)
preds <- dt$predict(X_test)

dt <- DecisionTreeClassifier$new()
preds <- dt$fit(X_train, y_train)$predict(X_test)

preds <- DecisionTreeClassifier$new()$fit(X_train, y_train)$predict(X_test)
print(caret::confusionMatrix(data=preds, reference = factor(y_test)))

## ------------------------------------------------
## Method `DecisionTreeClassifier$get_estimator_type`
## ------------------------------------------------

dt$get_estimator_type()

[Package less version 0.1.0 Index]