R Tools for Visual Studio – Predictive Analytics for C# applications



hi in this video we will be looking at the newly announced our tools for visual studio you may or may be familiar with the r programming language or the our environment it's an open source product that is used for statistical analysis and predictive learning predictive modeling it's been around for a long time and does have a lot of features that are compatible to say SAS or SPSS Microsoft recently added support for our within the visual studio ecosystem so this is the website where you can obtain our tools for visual studio it's really easy to download and get started you can install it as an extension and then once it's all configured the steps are all clearly documented here it's point and click install and then you have are available within the visual studio environment so one of the things that is particularly of interest to sync fusion and the same Fusion essential studio environment is that for quite some time now we have supported our in the modeling of predictive applications so we have supported this environment which allows you to build a predictive model within R or other environments that are compatible and then to export that model into predictive model markup language and then to be able to completely independent of R or any other modeling environment that was used to embed the predictive model 6 equation within your dotnet C sharp or vb.net application so I'm just gonna showcase that really quickly today so before you follow along you have to ensure that the our tools for visual studio is downloaded and installed so this is the WPF sample browser the support itself is not limited to WPF we have it's it's just a non UI library we showcase that under WPA under web and JavaScript and so forth but I'm just going to pick the WPF to kind of walk through it so you can launch the WPF predictive analytics sample browsing environment and you see that we have support for different models here basically so I'm just going to pick the simplest one regression so if I click on that I'm just going to pick the first sample the car something which takes a bunch of features and then predicts the price of the car based on the features basically so it uses a training set which is used to train the model and then once we have the model trained then we can persist it as a PMML file and then use it to predict the actual values so let's take a look at the steps that are involved the our code is here and the PMML code is also available here it makes it very easy to look at the sample within this WPF environment or other things but I'm not going to look at this and we're going to open the individual cars regression sample on disk and then open that sample independently as a console application and then work with it that way so I'm gonna go to the Explorer sample option here to get to the right folder you have to click on the version of essential studio that you have installed and then go to common analytics and then click on a regression under that and click on cars basically and then once you have that you can open it in Visual Studio is a cars SLM solution file that's provided so open that and once that comes up so you can see that the sample has not only the c-sharp code but also a PMML file and then also the actual R code that was that was used to model the regression so once you click the double click the our file car start to open it you see that Visual Studio loaded our interactive console at the bottom because I have articles already installed and configured so now I can actually simply run the script by saying source a script I can just do ctrl R control s and that will run the script before you do that make sure that these packages are installed on your system and the way you do that is if you simply type install doc packages and then for instance if I want to install the PMML package then that's what I would do and hit enter and the environment will configure itself so we depend on three packages in this case the PMML package the g models package in the carrot backage and this is once this is installed you're good to go the data set cars is actually included with the with the our environment once these packages are installed so we do a little bit of pre-processing to remove some omitted values missing values and so forth and then as is the case with all predictive modeling usually we split it into training data and test the data test data and then we build a regression in this case we are modeling the price on everything else the dart stands for everything else in the data set and then once this is done then we persist this to a PMML file and and we load the PMML file in the program basically to to run it now in this case by default are you if you're running this you can get the working directory and I'm actually set to this is the working directory so if you want to overwrite the existing PMML file then you will have to use set WD to set the working directory and overwrite the file I'm not going to do that I'm just going to run this in the console just to show you the output and I'm just going to source our script it's going to run and take a few seconds to build the model in this case I already have the PMML file persisted so you can see that this is what the regression linear regression model it's a question of computing weights for each of these factors and then the weights I used to actually do the prediction of the price here if you look at the C sharp code we import this same Fusion PMML namespace and then load the PMML file to actually do the processing the csv data is used to bring in the data that we used to do the predictions you also have please save the permission of the predictions from the our environment itself to compare it basically and that's what this console application will do to run the predictions with our engine with the sync fusion PMML engine and then to compare the predictions that were issued by are sure everything should match basically so if you run this you will simply get a note that everything matches and you could to go now if you were to include the support into your own environment all you would have to do is to include this in Fusion PMML library and then ship just the PMML model itself you would have no dependence on the our environment that was used for modeling basically you can also use if you're using the same Fusion Big Data environment you can use park and the ml ml Lib framework in spark to train and export a PMML file on a cluster and then we support that environment also basically so you can bring that PMML file and then execute and deploy the model so there's a lot of other models that are supported this is just a quick start so if you are doing predictive modeling now with an alternate environment such as SAS or SPSS and you have licenses for visual studio please to give this look this may help you to do predictive modeling within the visual studio environment and also to easily integrate this within the C sharp stack that you already have if you haven't looked at predictive modeling in the past please to take a look at it seeing fusion publishes a book on are called are succinctly that is available from our website you can download it it's a free book it will help you get started with our and now with first-class support for our within the visual studio environment it's very easy to get started with predictive modeling to do the modeling and also to deploy it with your dotnet applications as usual if you have any questions let us know through our support system good luck with your predictive modeling efforts thank you

2 Comments

  1. Rafael Díaz Bonilla said:

    When I make a new project with R,
    I got a massage like

    R evaluation failed: setwd("~")
    Error in setwd("~"): cannot change working directory

    and visual studio is closed..

    June 27, 2019
    Reply
  2. Shawn S. said:

    With R, I have created some predictive models and visualizations. Is there any way I can display this onto an MVC/ASPNET web application?

    June 27, 2019
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *