booster2sql | R Documentation |
This function generates SQL query for in-database scoring of XGBoost models,
providing a robust and efficient way of model deployment. It takes in the trained XGBoost model xgbModel
,
name of the input database table input_table_name
,
and name of a unique identifier within that table unique_id
as input,
writes the SQL query to a file specified by output_file_name
.
Note that the input database table should be generated from the raw table using the one-hot encoding query output by onehot2sql()
,
or to provide the one-hot encoding query as input input_onehot_query
to this function, working as sub-query inside the final model scoring query.
booster2sql(xgbModel, print_progress = FALSE, unique_id = NULL, output_file_name = NULL, input_table_name = NULL, input_onehot_query = NULL)
xgbModel |
The trained model object of class
|
print_progress |
Boolean indicator controls whether the SQL generating progress should be printed to console. |
unique_id |
A row unique identifier is crucial for in-database scoring of XGBoost model. If not given, SQL query will be generated with id name "ROW_KEY". |
output_file_name |
File name that the SQL syntax will write to. It must not be empty in order for this function to run. |
input_table_name |
Name of raw data table in the database, that the SQL query will select from. If not given, SQL query will be generated with table name "MODREADY_TABLE". |
input_onehot_query |
SQL query of one-hot encoding generated by |
The SQL query will write to the file specified by output_file_name
.
library(xgboost) # load data df = data.frame(ggplot2::diamonds) head(df) # data processing out <- onehot2sql(df) x <- out$model.matrix[,colnames(out$model.matrix)!='price'] y <- out$model.matrix[,colnames(out$model.matrix)=='price'] # model training bst <- xgboost(data = x, label = y, max.depth = 3, eta = .3, nround = 5, nthread = 1, objective = 'reg:linear') # generate model scoring SQL script with ROW_KEY and MODREADY_TABLE booster2sql(bst, output_file_name='xgb.txt')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.