Integrating the R model for fast batch prediction
Before continuing to the next steps, please follow the Prerequisite - Prepare the data section.
Step 1 – Train and save a real-time scoring model using T-SQL
In this step, you can create a predictive model for real-time scoring and native scoring, and optionally for the AUC, into a table via a stored procedure. The goal is to build a model that is reusable. You can skip this step if there is an existing compatible model that was created and stored in a table in SQL Server already.
The following stored procedure uses rxSerializeModel
, which lets you serialize an R model in raw format. This then allows you to save the model in the VARBINARY
format, which can be loaded into SQL Server for real-time scoring. To reverse the serialization for use in R, you could use rxUnserializeModel
:
CREATE PROCEDURE [dbo].[uspTrainTipPredictionModelWithRealTimeScoring]
AS
BEGIN
DECLARE @auc FLOAT;
DECLARE @model VARBINARY(MAX);
-- The data to be...