DecisionTreeClassifier | R Documentation |
Wrapper R6 Class of rpart::rpart function that can be used for LESSRegressor and LESSClassifier
R6 Class of DecisionTreeClassifier
less::BaseEstimator
-> less::SklearnEstimator
-> DecisionTreeClassifier
new()
Creates a new instance of R6 Class of DecisionTreeClassifier
DecisionTreeClassifier$new( min_samples_split = 2, min_samples_leaf = 1, cp = 0.001, xval = 10, surrogate_style = 0, max_depth = 30 )
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.
dt <- DecisionTreeClassifier$new() dt <- DecisionTreeClassifier$new(min_samples_split = 10) dt <- DecisionTreeClassifier$new(min_samples_leaf = 6, cp = 0.01)
fit()
Builds a decision tree regressor from the training set (X, y).
DecisionTreeClassifier$fit(X, y)
X
2D matrix or dataframe that includes predictors
y
1D vector or (n,1) dimensional matrix/dataframe that includes labels
Fitted R6 Class of DecisionTreeClassifier
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)
predict()
Predict regression value for X0.
DecisionTreeClassifier$predict(X0)
X0
2D matrix or dataframe that includes predictors
Factor of the predict classes.
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)))
get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
DecisionTreeClassifier$get_estimator_type()
dt$get_estimator_type()
clone()
The objects of this class are cloneable with this method.
DecisionTreeClassifier$clone(deep = FALSE)
deep
Whether to make a deep clone.
rpart::rpart()
## ------------------------------------------------ ## 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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.