DecisionTreeRegressor {less} | R Documentation |
DecisionTreeRegressor
Description
Wrapper R6 Class of rpart::rpart function that can be used for LESSRegressor and LESSClassifier
Value
R6 Class of DecisionTreeRegressor
Super classes
less::BaseEstimator
-> less::SklearnEstimator
-> DecisionTreeRegressor
Methods
Public methods
Inherited methods
Method new()
Creates a new instance of R6 Class of DecisionTreeRegressor
Usage
DecisionTreeRegressor$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 <- DecisionTreeRegressor$new() dt <- DecisionTreeRegressor$new(min_samples_split = 10) dt <- DecisionTreeRegressor$new(min_samples_leaf = 6, cp = 0.01)
Method fit()
Builds a decision tree regressor from the training set (X, y).
Usage
DecisionTreeRegressor$fit(X, y)
Arguments
X
2D matrix or dataframe that includes predictors
y
1D vector or (n,1) dimensional matrix/dataframe that includes response variables
Returns
Fitted R6 Class of DecisionTreeRegressor
Examples
data(abalone) split_list <- train_test_split(abalone[1:100,], 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 <- DecisionTreeRegressor$new() dt$fit(X_train, y_train)
Method predict()
Predict regression value for X0.
Usage
DecisionTreeRegressor$predict(X0)
Arguments
X0
2D matrix or dataframe that includes predictors
Returns
The predict values.
Examples
dt <- DecisionTreeRegressor$new() dt$fit(X_train, y_train) preds <- dt$predict(X_test) dt <- DecisionTreeRegressor$new() preds <- dt$fit(X_train, y_train)$predict(X_test) preds <- DecisionTreeRegressor$new()$fit(X_train, y_train)$predict(X_test) print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))
Method get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
Usage
DecisionTreeRegressor$get_estimator_type()
Examples
dt$get_estimator_type()
Method clone()
The objects of this class are cloneable with this method.
Usage
DecisionTreeRegressor$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
See Also
Examples
## ------------------------------------------------
## Method `DecisionTreeRegressor$new`
## ------------------------------------------------
dt <- DecisionTreeRegressor$new()
dt <- DecisionTreeRegressor$new(min_samples_split = 10)
dt <- DecisionTreeRegressor$new(min_samples_leaf = 6, cp = 0.01)
## ------------------------------------------------
## Method `DecisionTreeRegressor$fit`
## ------------------------------------------------
data(abalone)
split_list <- train_test_split(abalone[1:100,], 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 <- DecisionTreeRegressor$new()
dt$fit(X_train, y_train)
## ------------------------------------------------
## Method `DecisionTreeRegressor$predict`
## ------------------------------------------------
dt <- DecisionTreeRegressor$new()
dt$fit(X_train, y_train)
preds <- dt$predict(X_test)
dt <- DecisionTreeRegressor$new()
preds <- dt$fit(X_train, y_train)$predict(X_test)
preds <- DecisionTreeRegressor$new()$fit(X_train, y_train)$predict(X_test)
print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))
## ------------------------------------------------
## Method `DecisionTreeRegressor$get_estimator_type`
## ------------------------------------------------
dt$get_estimator_type()