Build a Machine Learning Model in C#, ML.Net (Step by Step)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
if your I just joined in my lesson for the first time hit the subscribe button below subscribe to my channel and in that case you keep updated when the new lesson comes out and if you have any challenges also leave me a comment below in the comment box below so that I all I give you the necklace is friendly support you need to be able to do what you want to do I'm always here to support you I make this lesson for free I'm not paid for this lesson so feel free to leave me a comment also visit my website you can find it in the description box below kind to the genuses cone and you can see a link they buy me a coffee maybe I'll just go there turns so you can visit change and again use this come if you go there you can see a variety of topics you can learn for free anything you want to learn programming in Java or not the chair is spring booth everything and they can buy me a coffee you can see buy me a coffee click buy me a coffee and buy me a coffee if you want to support me alright let's get started no I've outlined these types to peel this model in a step-by-step way right here on this page so these are the steps we are going to follow we are going to follow these types we are not gonna skip any stripe you're going to list one string at a time until we build a machine or any model what kind of model are we going to view we are going to build a model to perform clustering we have a data site made up of different categories of data we are going to perform unsupervised learning to be able to determine what clauses they belongs the data cites the data sent belongs the same data's size can also be used to perform classification because is the iris data site which a collection of flowers belonging to different three different categories alright so let's get started we are going to do step by step Baraka sake you'll need to download Visual Studio Community Edition is free if you already have Visual Studio 2005 in 2000 oh 2013 not sure is going to work 2017 Community Edition is free download it and install it in your system if you're a newbie a beginner programmer you can follow this lesson because it's a step by step also hit the subscribe button below so that you don't miss an update because this is really easy to follow our like to recommend you subscribe and leave me a comment if you'd have any recommendation right now I'm gonna start Visual Studio 2017 that is what I have Visual Studio 2017 let's go down alright so we chose to do 2017 I'm going to click on it and we are going to start a brand new solution and while Visual Studio is opening I'd like to mention the data site that we normally use data set is called the iris data site it comes to this asset test file it also comes a safe dots data file I like to show you actually actually open it from my system here and actually show you how it is so if I go to my drive D I go to data I can just open up the iris data site right here I read the data I can see the fairly simple data site made up of five columns for features and want class all right so we are going to see more about this data side as we move so that so let's follow a step by step so I'm gonna restore this kind of so that it fits into the they is fixing the screen side-by-side with the procedure so let me just place it right here and I'm gonna drag this one down I didn't know my system trying to be misbehave in this time this is it is a very a fairly good system I have alright so the data sites I'm gonna ships to step one the data side is a collection of flowers called iris there are five columns and 150 rows you can download this data site if you are in this website thanks Indian users calm no data Matic says actually dilute the description box you find the link to this place you can download this data site by clicking on this link if you click on this link you have this data site download I save it somewhere your system may be you're dragging your documents for and having there and try to examine this data site open it in place that has best file in Notepad and try to see what is in there so the first you will want to do one thing I want you to pay attention to is errors that are going to a call because these errors are gonna call and we need to fix them so I'm not going to actually cut out in this video we're hours of contact it's a mouse now I'll let you see the arrows at a call and see how to fix them by yourself without skipping any state at all so we are going to be walking drop in real time with everything clearly explained all right so I'm going to just drop this alright so step one cell the second step says create a console application let me just okay perfect alright so let's go to create a console application go to file and just click on new and choose projects and it's gonna be a console application so leave it in the second one the second one is okay that night framework if we use of night call I've not tried it but I don't know I think it'll work after now maybe I'm going to do it or if you use those might call it works leave me a comment to let me know it work so I'm going to call it ml ml tutorial 2 real one because I told you how to make other tutorials so that's called tutorial 1 and these does make a console application right here I'm going to just save ok so now the next type says I've created this console application I think it's starting up as you can see I'm going to create a folder in the application called data actually you can create a folder give it a name but I want to give it a name daytime I recommend if you give it the same name I give that is going to be very fine so now our project is ready the solution that's right right here I'm going to just right-click right-click and create a folder called data so it's go to add folder new folder and college data this is where I'm going to place my data site because we downloaded this data set we are going to copy try it inside there very easily and the nice thing we want to do copy the aresty cos theta r is a data file into this folder I'm going to just right click on the folder and say add and choose existing item I'm going to browse to where I see the original iris a dataset I download a and I said this some way I have my documents no in my drive D on that data and actually I'm going to drop down here and choose all files because this is das data file so the name is iris the data as you can see right here and I'm going to just add it to my project and you can see is other day there's some change you need to make very important if you miss out making this change is not going to work that's right Lee click on the date I read the data file go down to copy to output directory and choose copy always or copy if newer any of them is ok perfect so now we've done this and that is fine I'm going to just close it because everything is fine there's something called reference management so these are simply similar to dependency management in Java so we have references to your project you have some external references your projection uses and this can be managed using package does config or package your friends so they recommended way to manage it these package references to use bucket doc don't think you may have errors Microsoft tries to first develop a suit to what they think is the right thing instead of doing what you are used to and that is something I find kind of restrictive sometimes so I'm just gonna right click on references this is now step 5 and sorry I'm going to right click on my solution and I'm going to choose ok so these actually have already migrated it to to party preference but if you have a menu here that says migrate from package.com feed to party preference click onyx and migrate your references to pocket reference no I think my visual today is from figures are ready to use pocket reference to monitor references here alright so add ml that makes no get package to your project so I'm going to just right click here and choose money rocket packages and other points it shows up here and I'm going to click on browse choose Microsoft of ml which is the first one Microsoft ml this is a package that contains the tools that you need to build machine learning models in the night so I'm going to click on it I'm gonna install the latest version which is 1.3.1 so just click on install you're going to bring up say ok money project with bucket refrains are not supported in Visual Studio 2015 or earlier so that is fine we are using 2017 so select the package manager so you're gonna see this hour so as you can see I'm going to use package reference is better than pocket that config okay Jesus comfy I'm going to say ok now at this point is going to bring up some licensing pop-up so that we cannot save and I just click on assent here and it's install so if you are looking at the output here successfully installed I can see everything was successfully installed perfectly alright so I'm going to just close the the no get packages console and I'm going to kind of build the application and build solution to just make sure everything is ok take a look at the are the output of the build and see that he succeeded succeeded correctly now we are going to create two classes one class represents and feature sites or the predictor variable the other class represents the variable they they're the classes of the target variable so what they are saying is that if you have a data set like this the the classes are the names of the flowers that each decide each feature belong so how 4.6 three point four one point four zero point three given this collection of features what what are costs or what level does it belong to they belong to say the Sun does it belong to host versicolor or does it belong to thank you so this is a decision that has to be made it during classification both what we are doing today is clustering I also check next I'm going to bring up another video a lesson for classification alright so we are going to create two classes one class to hold the feature sites and one class to hold them a day the prediction or the levels or the classes right as I say the classes are just the last column in the data set all right so I'm gonna close the each I'm going to right-click a solution and choose arts plus and I'm going to call it iris data and I'm going to call it iris data so this class is going to represent the feature sites that we are going to use to predict the class so just go to add and now the future sites you have to define it exactly the same as the features in the data side so we have four columns in the data set representing all the features so instead of to kind of find them out I'm going to just copy it and paste but for you I recommend you spike it out so that you kind of appreciate how this works so just paste it in here from trophy now yeah so I know that this arrow might occur so what I'm going to do I'm going to press save everything and the solve this problem remember I told you we are going to be solving problems at this point so just check whether you have namespace loads okay so the fix is here and using Microsoft email the data that is what we are going to click so it adds the namespace where we have the load column so micro IML with designs other there and we are going to add the other class which represents the levels or the classes and I'm going to right click and say add new class so I'm going to call it cluster prediction so the idea is if I give it a new data a new feature site you're going to predict the clone site belongs given trick lost us we're going to talk about this later we're gonna call this cluster prediction all right so the closer prediction is going to have instead of one column is going to have to the first column is a predicted posture because we are given three clusters and the second one is the distance that is an array of distances I think I should illustrate this but let me add this class first because I want you to understand it perfectly well so what a save okay again we are going to do the same thing is name other data so so permit me to just explain to you what this distance is me so I'm going to just use pains pains all right so now if you have a data sites we are performing k-means clustering let me just take a pain so here will you plot a data site in this way alright and you have three clusters cluster one closer to and cluster three okay so if you are given a new data site let's say a data set at this point we have X P given a new data site at this point you need to check the distances from each of the cluster you check the distance from this each of the cluster centroids and the one that how the shortest distance is the claw site belongs right so in this case if we have this to be if we have this to be closer one with how this goes + or - how this would be closer 3 then X B belongs to cluster 3 that is how classroom walks in machine learning so we are I going am NOT going to spend time this in this because this is not I'm not a material k-means clustering alright so the prediction is given and there the distances the squared Euclidean distance is quite astonished from each of the four sites also giving us a summary so you as the es machine learning of these scientists will also see the basis why the model predicted what is predicted so so this is it the nice thing we are going to be doing ok lazy astonishing of course I just told you right now we need to define the data model and the data model parts this is done in the program of CS file we add two static fields one of them representing the past to the data sites and the other one represent where the parts to where the model of the saves so he's also quite and I'm going to spend time explaining all this so I'm going to just copy this to paste it it becomes clearer so the other mind I'm gonna go here I'm just gonna come to right here just above the main metal and just paste it and I'm gonna just shift these obits okay so so maybe I'm gonna reduce the font of these so that everything facing gonna shift this alright so we can see we've created two parts one is data part and one is model part data path contains the data site we have model path contains that path we are the model is saved because we are training the model the data and the data on the module have to be in locations that is in the cross parts not in external locations I'm going to save everything I'm going to add the two namespaces system on some file because that is where in the path is defined suggest your potential fixings and say using system denial and yeah so it's added all right so the nice you want to do is to create a machine lighting context a machine learning context is just a an environment where the model be developed and trained is similar to tension flow if you've been following my lessons in pencil for similar to the types of flow environment we build it created in anaconda ml ml contest so the machine learning context provides features for logging for for for loading the data for training the data for prediction and a few other things is similar to dbcontext 90 different work so to do that you simply present new context is just one line and now we are going to be doing all of this inside the main method so we are going to do this inside the main method we've created a confess watch so actually protonate outside the braces so it's going to be actually inside the braces like this I'm going to maybe put a comment maybe not so the comment you can post it by yourself because you have all the explanations here in my website the next step step six of Tracy's means load the data sites into the workspace now we are going to load up the data set and we are going to loot use a function called load from text files it's a method available in the data context so data context you mention is helps you to load data when this function called moves from place file based file runs it returns and I detect you object which actually is a container for holding data that is ready for training so I'm going to just copy it and paste then we try to take some minute so these oh we have them all content we have arrow here using Microsoft email okay so you know how to solve programs at this point all right so let me just ship this maybe we can see everything at once and maybe reduce the font size and things okay so I have the codes to load the data on my clipboard and I actually based at this code so as I mentioned the an ID type you object is returned by load dead load from test files so what their eyes happens to load from test files it's loaded into the ID that you object all right so now is it possible to see what this data is no we can only see it in wrong time so it's the same as the data in the test file of this isn't a different format at this point right it could be used to training ready to be used for training now we need to create a random pipeline if you followed my previous tutorial really last year in 2018 you see that these types in christian pipeline was quite easier when you create a pipeline you simply specify the data from the test files nothing nothing I did a few is specify the parts to the data or in this case we are not specifying a part of the data we are specifying the idea that the the were specifying did column definitions or the teacher definition now I'm going to start by copying the tool and then I explain it a little more so the steps they are two steps one concatenate the four features into one and use k-means trainer to train the model at this point so if you want to read more about came in strainer you have a link here just go ahead to click so I'm going to just space so this is quite straightforward as well so we are we are creating the future columns object and feature columns name and their colonies features and now we have pipeline is equal to ml contains the transforms dot concatenate the future columns name that is a features and we concatenate before and then we obtained the ML conveys clustering the trainers as k-means now there are other trainers I recommend you try to check them out there are other other models that you can use for instance you put eight dots here CRP or how binary classifications are clustering Li how component catalog we have multi-class classification ranking regression there are all the things we are going to do so they are rich set of activities we are going to be engaging in in ml of nice you simply need to hit the subscribe button and let me know what you think and at this point we are only performing clustering after now we are going to try the deform classification so keep subscribed alright so as you know a number of clusters has to be specified in k-means clustering one thing you need to know is that if you are doing K means clustering instead of doing hierarchical clustering you need to specify the initial number of classes for the k-means clustering here we are specifying the additional Bob foster into the tree you want to keep it simple and having creates the pipeline the next thing is to train and save the module a pipeline is like a something that helps you train the model like a neural network you move from the impute lay out to the outfield so again maybe I'll just illustrate you know that in neural networks you have something like this and that is what we are talking about we have this with how hidden layer we have output layer you have some input layer and we have the impute may be X 1 X 1 X 2 it goes through the hidden layers and then it spits out and outputs let's say y1 and y2 so this is a pie line the landing point line moves the data from the impute all the way to the outputs on is what's called neural network interest are in interest or what we are talking about the theories of machine learning right so we need to know train the data sites so simply one line you already know that the training data set is very easy you simply use the pipeline it's so so these something you should know in a neighbor analysis you piss your data site using the model you created so in this case you are saying pipeline does piece in regression we say model does fit that is Python so I'm saying if you know ml does not say developer you're halfway done simply follow my lessons and you are doing and learning Python will be in your fingertips is gonna be very easy for you to do all right so we trained our model and now we are gonna save our model at this point the codes takes a while for the cute that is this piece of coding how as completion the model will be ready you can now save it to the directory with Kreger we say that in save the directory we'll save it in model parts so you can see model parts right here you know shoot this one downloaded downwards all your parts where the model is gonna be saved all right so I'm going to just copy this so we are now to saving the model and also saving the yeah we are saving the model at this point so let's see actually we are saving the model means also creating file in file in the file system so I'm gonna just shift this alright so when you are gonna create a model you want we are using using statement so that you find any error code because you are welcome any files the same an arrow might a call so that we are using using statement file stream is new files from this file stream is created but provided parts provided a rate the file mode provided a size three yeah well we also say share so that all my own visual studio we'll be able to write in the model into this file that we are going to create and after then we say ml Contessa's model go save give it a model give it a DW schema and the file stream so yeah so I'm not going to into the theories of this for now because I want you to run through these to see how easy it is to build a machine learning model in the plate is very very easy for everyone to do and so now we are going to maybe drill deep to see if we can understand little more now we are going to make prediction to make prediction using the model we use the prediction engine C type the soft ml have all of the things you'll need to learn but don't worry yourself at when you'll be talking about this will because a little later we use a prediction English prediction engine class prediction engine will require the source and the destination what does this mean you'll need to use it to take a limp use instance a single imputes that is a new data point at this time that is not in the original training data site and we need the destination where is going to try to give us the predicted output right so the first step is to create a prediction engine so I'm going to just create the prediction engine at this point from when the Baystate so it's predict all I call it iris prediction so iris prediction is not the real name the iris prediction is supposed to be iris clustering iris cloth trim does name I think the name of the class we created let's see iris prediction of cluster prediction here so remember originally we created a class that represents the output that contains the predicted labelled underscore okay all the distance is not is called predicted pasta and the distance from the all the process so cluster prediction all right so the next thing we are going to create now is to create our a test data we'll put it past data so we are going to create a new file now I'm being a little fast but all the procedure on the piece of codes you'll need to use they all there my website so feel free to pause the video feel free to open the website and follow a step-by-step the procedure there if you miss out anything let me know into the standard comment box below this video so I'm going to add a new class sorry I'm going to just click here so this new class I'm going out I'm going to call it test I always do that so we are going to give a test data nice iOS data ok so we are going to specify that Cyrus data you are going to be specifying a new impute the new impute is simply all the features based online but are we settling for a safari and find this can be confusing but please know that for these are the four columns that we need to be specified and our model is going to predict which clause site belongs and also all the distances from other clauses or in this case we are having three processors alright so the nice thing which is the final thing is to make a prediction and I'm going to copy the the main method we are going to others codes that takes this test or the test data or the test iris data and then makes a prediction for us so I'm going to save everything I'm going to go back to program the CAS this point I'm gonna just paste these right so I'm really just kind of ship this one a bit before it's okay ah so all right so I'm gonna ship this a bit downwards we are creating using a predictor say predictor that predict and we are predict providing diced iris data the seconds are and then we are going to okay we are going to make a big prediction given this okay so so we are going we are asking the model how likely it thinks that this belongs to this cluster so you can actually change it to anything you want he doesn't it doesn't really matter so closer is given play the traditional plaza the predicted cluster ID gives us a predicted class ID there are three of them and gives us three distances as an array so I'm going to save everything and I'm gonna run this by just clicking on maybe I'm gonna build it first just because it's good to build a solution to make sure the build what okay so this an error does our calls it says ml does may currently supposed X is 4 and x86 processor architectures so the solve this problem is go to right click on your project and go to properties so here we are going to change the thing we are going to change the settings build let me check thank you I can't remember okay so you can see at this point we have any CPU so we are going to change it to USA is professed that it would be that is not my sense because who uses 32 bits now my system is evolving and this program is a perfect program neurologists rightly and choose X 64 that is the architecture we are going to use and at this point I'm going to save everything and I'm going to rebuild everything I'm going the right way and rebuild solution and you'll see this problem is solved that is all to debug a problem like this all right I'm going to close perfectly okay I'm going to close these and I'm gonna run the program at this point I'm gonna click on starts and if everything is okay is going to tell us given these space data item no it takes some time so uh and see is showing up the outputs right here so it takes time to train the model after training the model it also takes time to other kids to make prediction using this model so let's give a couple of seconds hopefully everything is going to work all right so hopefully you can see this I didn't know how Oh like second kind of is okay so okay so actually I have I'm gonna welcome the run again now is gonna be pasta so the output here is given so at this point if you've gotten to this point in how this block screen while is coming with the output it says closer to let's say this impute belong to closer to and the distances is from plus r1 from plus r2 is very short distance and from process three therefore we belong to closer to so we have this paste data belongs to pasta too so I'm gonna give you take Congress to you if you come all the way to this point you've done noble this is the first point this is no brain is very easy for everyone to follow the nice types now we are going to now proceed to go into more details we are going to be doing sentiment analysis and believe me this is how it works is not going to be more difficult except that there are some theories I'm going to be explaining or in more details in subsequent tutorials and anyway talking about movie recommender systems that is something used by Netflix on YouTube object recognition they make is image transmission and a few other things you are going in talking about so he to subscribe button and make sure you always subscribe hit the bell icon beside the subscribe button there is a bell icon it a link to that you don't miss an update when a new lesson is made I'm going to stop here I like thank you for viewing and also say we see in the next lecture
Info
Channel: Kindson The Genius
Views: 28,306
Rating: undefined out of 5
Keywords: ML.Net, Machine Learning, Data Science, Clustering, Cluster Analysis, Iris Dataset, PipeLine, MLContext, LoadFromTextFile, KMeans, IDataView, Centroid
Id: oPckdACVhAI
Channel Id: undefined
Length: 35min 2sec (2102 seconds)
Published: Fri Oct 04 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.