cancel
Showing results for 
Search instead for 
Did you mean: 

R-Component Save Option

Former Member
0 Kudos

Hello Everyone,

I am trying to generate some new R-Components for PA Expert Mode. If I try to use the feature of saving the model, I get always the error MODEL_PARAMS_CHECK_WARNING.

I have tried some SAP examples and get the same error message for the following code

SLR<-function(InputDataFrame,IndepenentColumn,DependentColumn)

               {

               finalString<-paste(paste(DependentColumn,"~" ), IndepenentColumn);

               slr_model<-lm(finalString); # calling the "lm" function and storing the output model in "slr_model"

               result<-predict(slr_model, InputDataFrame);

               output<- cbind(InputDataFrame, result); # combining "InputDataFrame" and "result" to get the final table.

               plot(slr_model);

               # returnvalue - function must always return a list that contains results("out"), and model variable variable ("slrmodel"), if present.

               return (list(slrmodel = slr_model,out=output))

               }

SLRModelScoring<-function (MInputDataFrame, MIndependentColumn, Model)

               {

               predicted <-predict (Model, data.frame(MInputDataFrame [, MIndependentColumn]), level=0.95);

              

               return(list(modelresult=predicted))

               }

and also for this example:

cnrFunction <- function(dataFrame, IndependentColumns, dep)

               {

               library(rpart)

               formattedString <- paste(IndependentColumns, collapse = '+');

               finalString <- paste(paste(dep, "~" ), formattedString)

               cnr_model <- rpart(finalString, method="class");

               output <- predict(cnr_model, dataFrame, type=c("class"));

               out <- cbind(dataFrame, output);

               return(list(result = out, modelcnr=cnr_model));

               }

              

cnrFunctionmodel<-function(dataFrame, ind, modelcnr, type)

               {

               output <- predict(modelcnr,data.frame(dataFrame[,ind]),type=type);

               out <- cbind(dataFrame, output);

               return(list(result = out));

               }

Regarding this example I saw that a community member had a similar problem (http://scn.sap.com/thread/3881996). I made the suggested changes in the code as the following

cnrFunctionmodel<-function(dataFrame,modelcnr,type)

{

output<-predict(modelcnr,dataFrame,type=type);

out<- cbind(dataFrame, output); return (list(result=out));

}

But I still get the same error message. I don’t know what I am doing wrong or where the mistake might be.  For any help or suggestions I would be very thankful.

Best regards,

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

In addition to the comments in the earlier thread (http://scn.sap.com/thread/3881996). , I think in your case the model scoring function details have not be configured properly. I have attached a screen shot for your reference, hopefully this will help.


See the code below:


SLR<-function(InputDataFrame,IndepenentColumn,DependentColumn)

               {

               finalString<-paste(paste(DependentColumn,"~" ), IndepenentColumn);

               slr_model<-lm(finalString); # calling the "lm" function and storing the output model in "slr_model"

               result<-predict(slr_model, InputDataFrame);

               output<- cbind(InputDataFrame, result); # combining "InputDataFrame" and "result" to get the final table.

               plot(slr_model);

               # returnvalue - function must always return a list that contains results("out"), and model variable variable ("slrmodel"), if present.

               return (list(slrmodel = slr_model,out=output))

               }

SLRModelScoring<-function (InputDataFrame,Model)

               {

               predicted <-predict (Model, InputDataFrame, level=0.95);

              

               return(list(modelresult=predicted))

               }

Former Member
0 Kudos

Hello Paul,

Thank you very much for your help. I tried your code and it worked fine. And I think I know now what went wrong. In the example code the name of the Main Input data variable and the data input variable of the scoring function differ (InputDataFrame & MInputDataFrame). I did not know that they have to have the same name. If I use your code with different data input variable names the same error message occurs.

So I tired the second example from the Expert Guide with the following code and same variable names, but I still get the error message:


cnrFunction <- function(dataFrame, IndependentColumns, dep)

               {

               library(rpart)

               formattedString <- paste(IndependentColumns, collapse = '+');

               finalString <- paste(paste(dep, "~" ), formattedString)

               cnr_model <- rpart(finalString, method="class");

               output <- predict(cnr_model, dataFrame, type=c("class"));

               out <- cbind(dataFrame, output);

               return(list(result = out, modelcnr=cnr_model));

               }

              

cnrFunctionmodel<-function(dataFrame,modelcnr,type)

     {

output<-predict(modelcnr,dataFrame,type=type);

out<- cbind(dataFrame, output); return (list(result=out));

     }

Thank you very much for your help.

Best regards,

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Viktor, are you asking for more help (re: your second scenario)?

Thanks & regards

Antoine

Former Member
0 Kudos

Hello Antoine,

yes, additional help for the second example would be great. I dont know where my error is and I am not able to replicate the example from the Expert Guide.

Best regards,

Viktor

Former Member
0 Kudos

cnrFunction <- function(dataFrame, IndependentColumns, dep,type)

               {

               library(rpart)

               formattedString <- paste(IndependentColumns, collapse = '+');

               finalString <- paste(paste(dep, "~" ), formattedString)

               cnr_model <- rpart(finalString, method="class");

               output <- predict(cnr_model, dataFrame, type=type); # set default value of type as class

               out <- cbind(dataFrame, output);

               return(list(result = out, modelcnr=cnr_model));

               }

             

cnrFunctionmodel<-function(dataFrame, modelcnr,type)

               {

               output <- predict(modelcnr,dataFrame,type=type);

               out <- cbind(dataFrame, output);

               return(list(result = out));

               }

Any parameters that you need in the scoring function should be also used in the function signature of the training ( primary ) function.

Answers (0)