Last active
September 29, 2016 06:14
-
-
Save ramnov/9accccbb886bf756a2572a6b1ccf4d56 to your computer and use it in GitHub Desktop.
Build a Random Forest Model and store it in a sql table
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].[BuildModel] | |
AS | |
BEGIN | |
DECLARE @inquery nvarchar(max) = N'SELECT * FROM [dbo].[LoanStatsTrain]' | |
DROP TABLE IF EXISTS [dbo].[models] | |
CREATE TABLE [dbo].[models]([model] [varbinary](max) NOT NULL) | |
INSERT INTO [dbo].[models] | |
EXEC sp_execute_external_script | |
@language = N'R', | |
@script = N' | |
randomForestObj <- rxDForest(is_bad ~ revol_util + int_rate + mths_since_last_record + annual_inc_joint + dti_joint + total_rec_prncp + all_util, InputDataSet) | |
model <- data.frame(payload = as.raw(serialize(randomForestObj, connection=NULL))) | |
', | |
@input_data_1 = @inquery, | |
@output_data_1_name = N'model' | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment