We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

General Architecture Understanding

Hi, 

I'm testing the Predictive Analytics for introducing it in a project I'm developing for UN. 
Their data-scientists use mainly R and SPSS and I'm trying to understand how effectively Predictive Analytics works.
In particular if the R script or PMML are executed everytime I request the results. 

Looking at the demo "Imports" The architecture can be summarized in the following way:
CSV data is processed by an R script that produce the pmml file ("imports.pmml")

Then, we make an ajax call to 'api/PredictiveAnalytics/PostAnalyticsAction' giving as parameter the pmml filename and the data (where do you define window.imports??)
The API execute the method public string LoadImportsNeuralNetworks(string jsonData, string pmmlFile) in PredictiveAnalyticsController.cs where I suppose it execute the pmml with the following code:

PMMLEvaluator evaluator = new PMMLEvaluatorFactory().GetPMMLEvaluatorInstance(pmmlFile);
...
PredictedResult predictedResult = evaluator.GetResult(importsObject, null);


So from my understanding if I change the data (adding rows i.e.), I don't have to run again the R script to generate a new pmml, because the new data will be processed from the engine following the model in the PMML, inluding it in the results, is it right?

But if I want to make a change in the model I need to manually run again the R script to produce a new model pmml, is it right?




By the way I've tried to run the R script in your example folder
/Common/Analytics/Neural Networks/Imports/Model/Imports.R

 setwd("D:/Users/Marco/AppData/Local/Syncfusion/EssentialStudio/14.3.0.49/Common/Analytics/Neural Networks/Imports/Model")
 imports<- read.csv("Imports.csv")
# Randomizing data
imports<-imports[sample(nrow(imports)),]
# Divide dataset for training and test
trainData<-imports[1:136,]
testData<-imports[137:155,]
# Applying Neural network model Function with 15 hidden layers
imports_NN<-nnet(price~.,data=trainData,size=15,decay = 1e-3, maxit = 1000, linout = TRUE)
imports_NN
# Predict "Price" column for test data set
importsTestPrediction<-predict(imports_NN,testData)
# Display predicted values
importsTestPrediction
# PMML generation
pmmlFile<-pmml(imports_NN,data=trainData)
write(toString(pmmlFile),file="Imports.pmml")
saveXML(pmmlFile,file="Imports.pmml")

but I get an error on the nnet() funtion:
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  contrasts can be applied only to factors with 2 or more levels





4 Replies

RR Ramkumar R Syncfusion Team November 16, 2016 01:10 PM UTC

Hi Marco, 
 
Thank you for your interest in Syncfusion product. 
 
Please find our comments from below. 
 
Then, we make an ajax call to 'api/PredictiveAnalytics/PostAnalyticsAction' giving as parameter the pmml filename and the data (where do you define window.imports??) 
“window.imports” is the input data in JSON format, which will be invoked from the ‘jsondata.min.js’ file. This file can be located from, 
 
%LocalAppData%\Syncfusion\EssentialStudio\14.3.0.49\JavaScript\samples\web\scripts 
So from my understanding if I change the data (adding rows i.e.), I don't have to run again the R script to generate a new pmml, because the new data will be processed from the engine following the model in the PMML, inluding it in the results, is it right? 
Yes, you don’t have to run the R script to generate PMML each time (unless if you want to create a new model) and you can make use of the existing PMML generated and pass the input data to get the predicted results. 
But if I want to make a change in the model I need to manually run again the R script to produce a new model pmml, is it right? 
Yes, if you want to make change/create a new model, you can run again the R script to produce a new PMML. 
R script error: 
 
but I get an error on the nnet() funtion: 
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :  
  contrasts can be applied only to factors with 2 or more levels 
We have checked our R script and we could reproduce the same error when we use the “Imports.csv” data shipped in the build.  
 
Cause: This appears since the variable (it can be any – here it is “engineLocation”) in the data contain only one level and it is must that for any categorical variable there should be 2 or more levels.  
 
 
 
R command:str(data)” – will list the observation details and the variables presented in the data. 
 
Fixes: 
1. If you use the data “import85” (contains 2 levels in “engineLocation”) which was shipped with R package – “randomForest”, this error can be overcome. 
 
 
 
2. Or, if you feel that field/variable (“engineLocation”) is not required for building the model, then it can be omitted from your data. 
 
 
Please let us know if you have any concern. 
 
Regards, 
Ramkumar R 



MG Marco Giorgi November 16, 2016 01:49 PM UTC

Many thanks Ramkumar, I'm delighted that Syncfusion has also an excellent support!


MG Marco Giorgi November 17, 2016 10:43 AM UTC

Dear Ramkumar,

What PMML version is currently supported by the Syncfusion Predictive Analytics?

Syncfusion Predictive Analytics support all the operation I define in the R script (and translated into the pmml model) or there is some limitation?
I.e., if I insert some operations in the R script to aggregate data, this will be translated into PMML and the executed by the Syncfusion Predictive Analytics?
Many thanks.

Best regards,
Marco


RR Ramkumar R Syncfusion Team November 17, 2016 01:59 PM UTC

Hi Marco, 

Thank you for your update. 

Please find our comments from below. 

What PMML version is currently supported by the Syncfusion Predictive Analytics? 
Syncfusion’ s PMML execution engine currently supports PMML version – 4.1, 4.2 and 4.2.1. 
 
To know more about our supported features and compatibilities, please refer to the below documentation links, 
 
 
 
Syncfusion Predictive Analytics support all the operation I define in the R script (and translated into the pmml model) or there is some limitation? 
I.e., if I insert some operations in the R script to aggregate data, this will be translated into PMML and the executed by the Syncfusion Predictive Analytics? 
We have built our execution engine based on the PMML standard of Data Mining Group (please refer dmg.org). This standard includes the PMML schema of existing machine learning models. So, you can use any statistical tools (like R, SAS, SPSS etc.) to generate your PMML and that can be evaluated using our PMML Execution Engine. 
 


Please let us know if you have any questions. 

Regards, 
Ramkumar 


Loader.
Live Chat Icon For mobile
Up arrow icon