Integrating an existing R model
This section takes an existing R code that generates the R model and runs against the SQL Server dataset into a workflow, where the model can be refreshed and evaluated on a regular basis, then used for predictive analysis. The following figure shows a typical predictive modeling workflow in an R script:

Figure 7.1: Typical predictive modeling workflow
To integrate this script in SQL Server, you'll need to organize the workflow into three steps:
- Prepare the data for training
- Train and save the model using T-SQL
- Operationalize the model
In this section, the last two steps will use sp_execute_external_script
, which invokes an R process. These steps are using the SQL Server extensibility framework, described later on.
Prerequisite – prepare the data
We will use the NYC Taxi sample data from the R: In-Database Analytics for SQL Developers tutorial, as referred to at https://github.com/Microsoft/sql-server-samples/blob/master/samples/features/r-services/predictive-analytics...