# Using R-UDF to make predictions on data based on a trained model

I am using Vertica to make statistical prediction based on machine learning models and I have a question concerning how to give the model to the UDF function as an argument.

Let's enter into detail:

I have the following functions (simplified):

predict <- function (TrainData) {

# Load model from disc with load()

# Make predictions

}

predictFactory <- function(){

list(name=predict,udxtype = c('scalar'),...)

}

As you see, I am using the function as a scalar UDF but I have to load the model every time the function is called and that is time-consuming. I wonder whether it is possible to load the model only once and to give to the predict function as an argument. Something like this:

predict <- function (TrainData,Model) {

# Make predictions

}

predictFactory <- function(){

Model <- load(model)

list(name=predict,udxtype = c('scalar'),parameters = Model)

}

Is there any way of giving arguments to the predict function from the predictFactory function?

Thank you very much.

Let's enter into detail:

I have the following functions (simplified):

predict <- function (TrainData) {

# Load model from disc with load()

# Make predictions

}

predictFactory <- function(){

list(name=predict,udxtype = c('scalar'),...)

}

As you see, I am using the function as a scalar UDF but I have to load the model every time the function is called and that is time-consuming. I wonder whether it is possible to load the model only once and to give to the predict function as an argument. Something like this:

predict <- function (TrainData,Model) {

# Make predictions

}

predictFactory <- function(){

Model <- load(model)

list(name=predict,udxtype = c('scalar'),parameters = Model)

}

Is there any way of giving arguments to the predict function from the predictFactory function?

Thank you very much.

0

## Comments

Within the predictFactory function, the Model must be loaded like this:

predictFactory <- function(){

# Model <- load(model)

Model <<- load(model)list(name=predict,udxtype = c('scalar'),parameters = Model)

}

When doing this, the variable Model is in the environment for the following functions and you can use it with the predict function. In fact, the parameter Model is not needed.

predict <- function (TrainData) {

# Make predictions

}

It seems to work, but if someone proposes a better solution I would be happy to discuss it