SQL R Code The tutorial problem , Predict From Model wont run. Unserialize Error

2

I ve created a model In R server , the tutorial example on the microsoft site. I have read simila texts /problems and the resolution was to wrap the model in as.raw befpore unserialize ..this does not help!!.

Note I am new to this and have not seen a resolution. I refer to the script on the page "Quickstart: Predict from model using R in SQL Server" on the Microsoft site ie

DECLARE @glmmodel varbinary(max) = (SELECT model FROM dbo.GLM_models WHERE model_name = 'default model');

EXEC sp_execute_external_script
    @language = N'R'
    , @script = N'
            current_model <- unserialize(as.raw(glmmodel));                                           
            new <- data.frame(NewMTCars);
            predicted.am <- predict(current_model, new, type = "response");
            str(predicted.am);
            OutputDataSet <- cbind(new, predicted.am);
            '
    , @input_data_1 = N'SELECT hp, wt FROM dbo.NewMTCars'
    , @input_data_1_name = N'NewMTCars'
    , @params = N'@glmmodel varbinary(max)'
    , @glmmodel = @glmmodel
WITH RESULT SETS ((new_hp INT, new_wt DECIMAL(10,3), predicted_am DECIMAL(10,3)));

I get the following error :

DECLARE @glmmodel varbinary(max) = 
    (SELECT model FROM dbo.GLM_models WHERE model_name = 'default model');

EXEC sp_execute_external_script
    @language = N'R'
    , @script = N'
            current_model <- unserialize(as.raw(glmmodel));                                           
            new <- data.frame(NewMTCars);
            predicted.am <- predict(current_model, new, type = "response");
            str(predicted.am);
            OutputDataSet <- cbind(new, predicted.am);
            '
    , @input_data_1 = N'SELECT hp, wt FROM dbo.NewMTCars'
    , @input_data_1_name = N'NewMTCars'
    , @params = N'@glmmodel varbinary(max)'
    , @glmmodel = @glmmodel
WITH RESULT SETS ((new_hp INT, new_wt DECIMAL(10,3), predicted_am DECIMAL(10,3)));

I get the following error :

"Msg 39004, Level 16, State 20, Line 44 A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 2, Line 44 An external script error occurred: During startup - Warning message: In setJsonDatabasePath(system.file("extdata/capabilities.json", : bytecode version mismatch; using eval Error in unserialize(as.raw(glmmodel)) : read error Calls: source -> withVisible -> eval -> eval -> unserialize

Error in execution. Check the output for more information. Error in eval(expr, envir, enclos) : Error in execution. Check the output for more information. Calls: source -> withVisible -> eval -> eval -> .Call Execution halted " Is the error related to unserialize or is it related to"

During startup - Warning message: In setJsonDatabasePath(system.file("extdata/capabilities.json", : bytecode version mismatch; using eval

sql
r
model
predict
asked on Stack Overflow Aug 11, 2019 by Graham Bortz

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0