Description
This function is used to score data in Vantage with a model that has been created outside Vantage and exported to vantage using PMML format.
Usage
td_pmml_predict_sqle (
modeldata = NULL,
newdata = NULL,
accumulate = NULL,
model.output.fields = NULL,
overwrite.cached.models = NULL,
newdata.partition.column = "ANY",
newdata.order.column = NULL,
modeldata.order.column = NULL
)
Arguments
modeldata |
Required Argument. |
modeldata.order.column |
Optional Argument. |
newdata |
Required Argument. |
newdata.partition.column |
Optional Argument. |
newdata.order.column |
Optional Argument. |
accumulate |
Required Argument. |
model.output.fields |
Optional Argument. |
overwrite.cached.models |
Optional Argument. |
Value
Function returns an object of class "td_pmml_predict_sqle" which is a
named list containing object of class "tbl_teradata".
Named list member can be referenced directly with the "$" operator
using the name: result.
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Create following table on vantage.
crt_tbl <- "CREATE SET TABLE pmml_models(model_id VARCHAR(40), model BLOB)
PRIMARY INDEX (model_id);"
DBI::dbExecute(con, sql(crt_tbl))
# Run the following query through BTEQ or Teradata Studio to load the
# models. 'load_pmml_model.txt' and pmml files can be found under
# 'inst/scripts' in tdplyr installation directory. This file and the pmml
# models to be loaded should be in the same directory.
# .import vartext file load_pmml_model.txt
# .repeat *
# USING (c1 VARCHAR(40), c2 BLOB AS DEFERRED BY NAME) INSERT INTO pmml_models(:c1, :c2);
# Load example data.
loadExampleData("pmmlpredict_example", "iris_train", "iris_test")
# Create object(s) of class "tbl_teradata".
iris_train <- tbl(con, "iris_train")
iris_test <- tbl(con, "iris_test")
# Example 1 -
# This example runs a query with XGBoost model with no prediction values.
# It also uses "overwrite.cached.models" argument.
modeldata <- tbl(con, "pmml_models")
ml_name <- "iris_db_xgb_model"
pmml_predict_out <- td_pmml_predict(modeldata = modeldata,
newdata = iris_test,
accumulate = "id",
overwrite.cached.models = ml_name)
# Example 2 -
# This example runs a query with RandomForest model with prediction values.
# It also used "model.output.fields" argument.
modeldata <- tbl(con, "pmml_models")
ml_op_field <- c('probability_0', 'probability_1', 'probability_2')
pmml_predict_out <- td_pmml_predict(modeldata = modeldata,
newdata = iris_test,
accumulate = "id",
model.output.fields = ml_op_field)
# Example 3 -
# This example runs a query with XGBoost model and
# "overwrite.cached.models". This will erase entire cache.
modeldata <- tbl(con, "pmml_models")
pmml_predict_out <- td_pmml_predict(modeldata = modeldata,
newdata = iris_test,
accumulate = "id",
overwrite.cached.models = "*")
# Example 4 -
# This example assumes that the user is connected to another database where
# byom is not installed and runs a query with XGBoost model with no prediction
# values. It also uses "overwrite.cached.models" argument.
# Set the global option in order to point to the database (mldb in this case)
# where byom is installed.
options(byom.install.location="mldb")
modeldata <- tbl(con, "pmml_models")
ml_name <- "iris_db_xgb_model"
pmml_predict_out <- td_pmml_predict(modeldata = modeldata,
newdata = iris_test,
accumulate = "id",
overwrite.cached.models = ml_name)