| LESSClassifier {less} | R Documentation |
LESSClassifier
Description
Classifier for Learning with Subset Stacking (LESS)
Value
R6 class of LESSClassifier
Super classes
less::BaseEstimator -> less::SklearnEstimator -> less::LESSBase -> LESSClassifier
Methods
Public methods
Inherited methods
less::BaseEstimator$get_all_fields()less::BaseEstimator$get_attributes()less::SklearnEstimator$get_type()less::LESSBase$get_d_normalize()less::LESSBase$get_frac()less::LESSBase$get_isFitted()less::LESSBase$get_n_neighbors()less::LESSBase$get_n_replications()less::LESSBase$get_n_subsets()less::LESSBase$get_random_state()less::LESSBase$get_replications()less::LESSBase$get_scaling()less::LESSBase$get_val_size()
Method new()
Creates a new instance of R6 Class of LESSClassifier
Usage
LESSClassifier$new( frac = NULL, n_neighbors = NULL, n_subsets = NULL, n_replications = 20, d_normalize = TRUE, val_size = NULL, random_state = NULL, tree_method = function(X) KDTree$new(X), cluster_method = NULL, local_estimator = LinearRegression$new(), global_estimator = DecisionTreeClassifier$new(), distance_function = NULL, scaling = TRUE, warnings = TRUE, multiclass = "ovr" )
Arguments
fracfraction of total samples used for the number of neighbors (default is 0.05)
n_neighborsnumber of neighbors (default is NULL)
n_subsetsnumber of subsets (default is NULL)
n_replicationsnumber of replications (default is 20)
d_normalizedistance normalization (default is TRUE)
val_sizepercentage of samples used for validation (default is NULL - no validation)
random_stateinitialization of the random seed (default is NULL)
tree_methodmethod used for constructing the nearest neighbor tree, e.g., less::KDTree (default)
cluster_methodmethod used for clustering the subsets, e.g., less::KMeans (default is NULL)
local_estimatorestimator for the local models (default is less::LinearRegression)
global_estimatorestimator for the global model (default is less::DecisionTreeRegressor)
distance_functiondistance function evaluating the distance from a subset to a sample, e.g., df(subset, sample) which returns a vector of distances (default is RBF(subset, sample, 1.0/n_subsets^2))
scalingflag to normalize the input data (default is TRUE)
warningsflag to turn on (TRUE) or off (FALSE) the warnings (default is TRUE)
multiclassavailable strategies are 'ovr' (one-vs-rest, default), 'ovo' (one-vs-one), 'occ' (output-code-classifier) (default is 'ovr')
Examples
lessclassifier <- LESSClassifier$new() lessclassifier <- LESSClassifier$new(multiclass = "ovo")
Method fit()
Dummy fit function that calls the fit method of the multiclass strategy
Usage
LESSClassifier$fit(X, y)
Arguments
X2D matrix or dataframe that includes predictors
y1D vector or (n,1) dimensional matrix/dataframe that includes response variables
Returns
Fitted R6 Class of LESSClassifier
Examples
data(iris) set.seed(2022) shuffled_iris <- iris[sample(1:nrow(iris)),] split_list <- train_test_split(shuffled_iris[1:10,], test_size = 0.3, random_state = 1) X_train <- split_list[[1]] X_test <- split_list[[2]] y_train <- split_list[[3]] y_test <- split_list[[4]] lessclassifier <- LESSClassifier$new() lessclassifier$fit(X_train, y_train)
Method predict()
Dummy predict function that calls the predict method of the multiclass strategy
Usage
LESSClassifier$predict(X0)
Arguments
X02D matrix or dataframe that includes predictors
Returns
Predicted values of the given predictors
Examples
preds <- lessclassifier$predict(X_test) print(caret::confusionMatrix(data=factor(preds), reference = factor(y_test)))
Method get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
Usage
LESSClassifier$get_estimator_type()
Examples
lessclassifier$get_estimator_type()
Method set_random_state()
Auxiliary function that sets random state attribute of the self class
Usage
LESSClassifier$set_random_state(random_state)
Arguments
random_stateseed number to be set as random state
Returns
self
Examples
lessclassifier$set_random_state(2022)
Method clone()
The objects of this class are cloneable with this method.
Usage
LESSClassifier$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
Examples
## ------------------------------------------------
## Method `LESSClassifier$new`
## ------------------------------------------------
lessclassifier <- LESSClassifier$new()
lessclassifier <- LESSClassifier$new(multiclass = "ovo")
## ------------------------------------------------
## Method `LESSClassifier$fit`
## ------------------------------------------------
data(iris)
set.seed(2022)
shuffled_iris <- iris[sample(1:nrow(iris)),]
split_list <- train_test_split(shuffled_iris[1:10,], test_size = 0.3, random_state = 1)
X_train <- split_list[[1]]
X_test <- split_list[[2]]
y_train <- split_list[[3]]
y_test <- split_list[[4]]
lessclassifier <- LESSClassifier$new()
lessclassifier$fit(X_train, y_train)
## ------------------------------------------------
## Method `LESSClassifier$predict`
## ------------------------------------------------
preds <- lessclassifier$predict(X_test)
print(caret::confusionMatrix(data=factor(preds), reference = factor(y_test)))
## ------------------------------------------------
## Method `LESSClassifier$get_estimator_type`
## ------------------------------------------------
lessclassifier$get_estimator_type()
## ------------------------------------------------
## Method `LESSClassifier$set_random_state`
## ------------------------------------------------
lessclassifier$set_random_state(2022)