Performing predictions with R Services in the SQL Server database
Calling stored procedures is the easiest way to organize your code and start predicting right away.
Again, only a sample will be shown here of how to create a stored procedure to predict new datasets:
CREATE OR ALTER PROCEDURE [dbo].[Predicting_rentalCount]
(
@model VARCHAR(30)
,@query NVARCHAR(MAX)
)
AS
BEGIN
DECLARE @nar_model VARBINARY(MAX) = (SELECT model FROM [dbo].[Rental_data_models] WHERE model_name = @model);
EXEC sp_execute_external_script
@language = N'R'
,@script = N'
#input from query
new_data <- InputDataSet
#model from query
model <- unserialize(nar_model)
#prediction
prediction...