LESSRegressor {less}R Documentation

LESSRegressor

Description

Regressor for Learning with Subset Stacking (LESS)

Value

R6 class of LESSRegressor

Super classes

less::BaseEstimator -> less::SklearnEstimator -> less::LESSBase -> LESSRegressor

Methods

Public methods

Inherited methods

Method new()

Creates a new instance of R6 Class of LESSRegressor

Usage
LESSRegressor$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 = DecisionTreeRegressor$new(),
  distance_function = NULL,
  scaling = TRUE,
  warnings = TRUE
)
Arguments
frac

fraction of total samples used for the number of neighbors (default is 0.05)

n_neighbors

number of neighbors (default is NULL)

n_subsets

number of subsets (default is NULL)

n_replications

number of replications (default is 20)

d_normalize

distance normalization (default is TRUE)

val_size

percentage of samples used for validation (default is NULL - no validation)

random_state

initialization of the random seed (default is NULL)

tree_method

method used for constructing the nearest neighbor tree, e.g., less::KDTree (default)

cluster_method

method used for clustering the subsets, e.g., less::KMeans (default is NULL)

local_estimator

estimator for the local models (default is less::LinearRegression)

global_estimator

estimator for the global model (default is less::DecisionTreeRegressor)

distance_function

distance 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))

scaling

flag to normalize the input data (default is TRUE)

warnings

flag to turn on (TRUE) or off (FALSE) the warnings (default is TRUE)

Examples
lessRegressor <- LESSRegressor$new()
lessRegressor <- LESSRegressor$new(val_size = 0.3)
lessRegressor <- LESSRegressor$new(cluster_method = less::KMeans$new())
lessRegressor <- LESSRegressor$new(val_size = 0.3, cluster_method = less::KMeans$new())

Method fit()

Dummy fit function that calls the proper method according to validation and clustering parameters Options are:

Usage
LESSRegressor$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 LESSRegressor

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]]

lessRegressor <- LESSRegressor$new()
lessRegressor$fit(X_train, y_train)

Method predict()

Predictions are evaluated for the test samples in X0

Usage
LESSRegressor$predict(X0)
Arguments
X0

2D matrix or dataframe that includes predictors

Returns

Predicted values of the given predictors

Examples
preds <- lessRegressor$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
LESSRegressor$get_estimator_type()
Examples
lessRegressor$get_estimator_type()

Method clone()

The objects of this class are cloneable with this method.

Usage
LESSRegressor$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

LESSBase

Examples


## ------------------------------------------------
## Method `LESSRegressor$new`
## ------------------------------------------------

lessRegressor <- LESSRegressor$new()
lessRegressor <- LESSRegressor$new(val_size = 0.3)
lessRegressor <- LESSRegressor$new(cluster_method = less::KMeans$new())
lessRegressor <- LESSRegressor$new(val_size = 0.3, cluster_method = less::KMeans$new())

## ------------------------------------------------
## Method `LESSRegressor$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]]

lessRegressor <- LESSRegressor$new()
lessRegressor$fit(X_train, y_train)

## ------------------------------------------------
## Method `LESSRegressor$predict`
## ------------------------------------------------

preds <- lessRegressor$predict(X_test)
print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))

## ------------------------------------------------
## Method `LESSRegressor$get_estimator_type`
## ------------------------------------------------

lessRegressor$get_estimator_type()

[Package less version 0.1.0 Index]