Created
September 27, 2016 21:39
-
-
Save ramnov/4fbf69b7b0cd21dcc2257afb150976b6 to your computer and use it in GitHub Desktop.
Stored Procedure to score test data using RandomForest Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE PROCEDURE [dbo].[ScoreLoans] | |
AS | |
BEGIN | |
DECLARE @inquery nvarchar(max) = N'SELECT * FROM [dbo].[LoanStatsTest]' | |
DECLARE @model varbinary(max) = (SELECT TOP 1 model FROM models) | |
DROP TABLE IF EXISTS [dbo].[LoanStatsPredictions] | |
CREATE TABLE [dbo].[LoanStatsPredictions]([is_bad_Pred] [float] NULL, [id] [int] NULL) | |
INSERT INTO [dbo].[LoanStatsPredictions] | |
EXEC sp_execute_external_script | |
@language = N'R', | |
@script = N' | |
rfModel <- unserialize(as.raw(model)); | |
OutputDataSet<-rxPredict(rfModel, data = InputDataSet, extraVarsToWrite = c("id")) | |
', | |
@input_data_1 = @inquery, | |
@params = N'@model varbinary(max)', | |
@model = @model | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment