Learn R Programming

PortfolioTesteR (version 0.1.4)

ml_make_model: Model factory for tabular cross-sectional learners

Description

Returns a pair of closures fit(X,y) / predict(model, X) implementing a chosen learner. Implementations are NA-aware and conservative: glmnet ridge drops rows with any non-finite input; ranger and xgboost keep NA in X as missing; the linear baseline uses lm.fit.

Usage

ml_make_model(
  type = c("ridge", "rf", "xgboost", "linear"),
  params = list(),
  nrounds = 200L,
  ...
)

Value

A list with functions fit and predict.

Arguments

type

One of "ridge", "rf", "xgboost", "linear".

params

List of model parameters (passed to backend; used by xgboost).

nrounds

Integer boosting rounds (xgboost).

...

Additional arguments forwarded to the backend.

Details

Optional dependencies: glmnet (ridge), ranger (rf), xgboost (xgboost). If a backend is not available, use "linear" or install the package.

Examples

Run this code
if (FALSE) {
ridge <- ml_make_model("ridge")
m <- ridge$fit(X_is, y_is)
s <- ridge$predict(m, X_oos)
}

Run the code above in your browser using DataLab