Netherlands: Software

Introductie van Micorosoft SQL Server 2016

Issue link:

Contents of this Issue


Page 134 of 212

122 C H A P T E R 6 | More analytics only two of many different types of performance metrics that the performance function returns. You can store the performance results in a variable that you can then plot, as shown in Figure 6-21. Figure 6-21: Viewing the plot of the prediction model performance. Note You can see the other performance metrics accessible with the performance function at Using an R Model in SQL Server After creating an R model, you can deploy it to SQL Server for use in applications and other tools. You can then invoke the model by calling the sp_execute_external_script stored procedure. You can call a model to score data in batch mode or to score data for an individual case. The sample database includes two stored procedures that allow you to perform each of these tasks. Model deployment This process requires you to serialize your model as a hexadecimal string that you send to the server and store in a varbinary(max) column in a database, as shown in Example 6-11. The serialize function produces the string, and the paste function ensures that the result is a single string. Then the RODBC package is installed to use the odbcDriverConnect function to open a connection to SQL Server. Next, the paste function concatenates the serialized string with a call to the PersistModel stored procedure to produce a query string that is passed into the sqlQuery function and executed. The PersistModel stored procedure is a custom stored procedure in the sample database that inserts a record into the nyc_taxi_models table. Example 6-11: Deploying a model to SQL Server modelbin <- serialize(logitObj, NULL) modelbinstr=paste(modelbin, collapse="") if (!('RODBC' %in% rownames(installed.packages()))){ install.packages('RODBC') } library(RODBC) conn <- odbcDriverConnect(connStr ) q<-paste("EXEC PersistModel @m='", modelbinstr,"'", sep="") sqlQuery (conn, q)

Articles in this issue

Links on this page

Archives of this issue

view archives of Netherlands: Software - Introductie van Micorosoft SQL Server 2016