LinearRegression | R Documentation |
Wrapper R6 Class of stats::lm function that can be used for LESSRegressor and LESSClassifier
R6 Class of LinearRegression
less::BaseEstimator
-> less::SklearnEstimator
-> LinearRegression
fit()
Fits a linear model (y ~ X)
LinearRegression$fit(X, y)
X
2D matrix or dataframe that includes predictors
y
1D vector or (n,1) dimensional matrix/dataframe that includes response variables
Fitted R6 Class of LinearRegression
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]] lr <- LinearRegression$new() lr$fit(X_train, y_train)
predict()
Predict regression value for X.
LinearRegression$predict(X0)
X0
2D matrix or dataframe that includes predictors
The predict values.
lr <- LinearRegression$new() lr$fit(X_train, y_train) preds <- lr$predict(X_test) lr <- LinearRegression$new() preds <- lr$fit(X_train, y_train)$predict(X_test) preds <- LinearRegression$new()$fit(X_train, y_train)$predict(X_test) print(head(matrix(c(y_test, preds), ncol = 2, dimnames = (list(NULL, c("True", "Prediction"))))))
get_estimator_type()
Auxiliary function returning the estimator type e.g 'regressor', 'classifier'
LinearRegression$get_estimator_type()
lr$get_estimator_type()
clone()
The objects of this class are cloneable with this method.
LinearRegression$clone(deep = FALSE)
deep
Whether to make a deep clone.
stats::lm()
## ------------------------------------------------ ## Method `LinearRegression$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]] lr <- LinearRegression$new() lr$fit(X_train, y_train) ## ------------------------------------------------ ## Method `LinearRegression$predict` ## ------------------------------------------------ lr <- LinearRegression$new() lr$fit(X_train, y_train) preds <- lr$predict(X_test) lr <- LinearRegression$new() preds <- lr$fit(X_train, y_train)$predict(X_test) preds <- LinearRegression$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 `LinearRegression$get_estimator_type` ## ------------------------------------------------ lr$get_estimator_type()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.