cancel
Showing results for 
Search instead for 
Did you mean: 

Save Model is not working with Custom R Component

Former Member
0 Kudos

Hello,

When I try to create my own R-model with the option to save it, I always get the message "MODEL_PARAMS_CHECK_WARNING" in the script editor. Because of this I am not able to get to the options tab to save the component.

The same is the case when I use the code example in the Expert Analytics Guide. 

The error also occurs with the random forest component from Andreas http://scn.sap.com/docs/DOC-58824

But because I can import the .spar file - I don't have to save the component and can use the save option.

I would appreciate any advice on this issue. I am using Version 2.4.

PS: I posted the same question over here. I just thought it would get more attention here from people who face the same problem.

Best Regards,


Heiko

Accepted Solutions (1)

Accepted Solutions (1)

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Heiko,

As a first step, can you please upgrade to SAP Predictive Analytics 2.5 and check if the problem remains?

Thanks & regards

Antoine

Former Member
0 Kudos

Hi Antoine,

I updated to version 2.5, but got the same error and I was not able to save the component.

But I went back and installed version 2.2, and it works here...

I couldn't find version 2.3 to try it out as well.

Best regards,

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

I will have a detailed look to this.

Thanks & regards

Antoine

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

I used the sample script available in the user guide for 2.5 on pages 108 to 110 and it worked for me. Can you please give it an additional try so that we can understand what's happening for you? If you send me an email, I can share with you the SPAR file I just built.

Thanks & regards,

Antoine

#The following is a sample script for a simple linear regression component.

#You must write the script in a valid R function format.

#Note that the function name and variable name in R script can be userdefined,and are supported in R.

#The following is the argument description for the primary function SLR:

#InputDataFrame: Dataframe in R that contains the output of the parent component.

#The following two parameters are fetched from the user through the property view:

#IndependentColumn: Column name that you want to use as independent variable for the component.

#DependentColumn; Column name that you want to use as a dependent variable for the component.

SLR<-function(InputDataFrame, IndependentColumn, DependentColumn)

{

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

#Formatting the final string to

#pass to "lm" function

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

#To get the predicted values for the Training data set, call the "predict" function with this model and

#input dataframe, which is represented by "InputDataFrame".

result<-predict(slr_model, InputDataFrame); # Storing the predicted values in the "result" variable.

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

plot(slr_model); #Plotting model visualization.

#returnvalue: function must always return a list that contains results "out", and model variable

#"slrmodel", if present.

#The output variable stores the final result.

#The model variable is used for model scoring.

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

}

#The following is the argument description for the model scoring function "SLRModelScoring":

#InputDataFrame: Dataframe in R that contains the output of the parent component.

#IndependentColumn: Column name to be used as independent variables for the component.

#Model: Model variable that is used for scoring.

SLRModelScoring <- function (InputDataFrame, IndependentColumn, Model)

{

#Calling "predict" function to get the predictive value with "Model " and "InputDataFrame".

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

# Combining “InputDataFrame” and “predicted” to get the final table.

output <- cbind(InputDataFrame, predicted);

#returnvalue: function should always return a list that contains the result

("model result"),

#The output variable stores the final result

return(list(modelresult=output))

}

Former Member
0 Kudos

Hi Antoine,

this is really strange. This example works. But the example in the expert guide below does not work.

Could you please check the Random Forest Component? http://scn.sap.com/docs/DOC-58824

What I found out, when I changethe names of the parameters of this Component, I get no error message.

But that didn't work with this example from the Expert Guide.

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));

}

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Heiko, I do reproduce the problem with Expert Analytics 2.5 and your example above. I am looping in .

Thanks & regards

Antoine

Former Member
0 Kudos

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

{

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

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

}

Change the function to:

cnrFunctionmodel<-function(dataFrame,modelcnr,type)

{

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

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

}

The independent column is present in the scoring function, this was ok when working with versions before 2.3, but with the later versions the secondary function does not expect independent column ,.; and hence you are prompted the message "MODEL_PARAMS_CHECK_WARNING" .

Do the change and you should be good

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Paul and Antoine,

Thanks to both of you, for your help.

Your answer makes it very clear, Paul. Thank you!

Best regards,

Heiko

achab
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Heiko, can you please refer to Paul's answer, this should help...

Thanks & regards

Antoine