Models

The package manages machine learning models using objects of class ml_model. These objects are constructed using the ml_model constructor. As a minimal example, consider a linear regression trained on the synthetic dataset.

lm_x1 <- lm(y ~ x1, data=data_train)
m_lm_x1 <- ml_model(lm_x1)

The first object, lm_x1, is a standard R model. The second line defined an ml_model object that contains the R model. They behave similarly in terms of making predictions. For example,

data_test <- data.frame(x1 = c(1, 2, 3, 4),
                     x2 = c(1, 2, 3, 4))
predict(lm_x1, data_test)
predict(m_lm_x1, data_test)

A very brief description of the ml_model object is available via print.

m_lm_x1                   ## equivalent to print(m_lm_x1)

The above displays the 'name' of the model, which in this case is 'lm_x1' because it was inferred from the constructor. It is possible to set the name to another string within the constructor, for example,

ml_model(lm_x1, name="my_model")

The model name is important when several models are joined into an ensemble.



tkonopka/mlensemble documentation built on March 19, 2022, 7:28 a.m.