How to run code examples in ipython notebook

Python AI and Machine Learning for Production and Development How to use the virtual machine for development
26 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
This is a free item
$0.00
د.إ0.00
Kz0.00
ARS$0.00
A$0.00
৳0.00
Лв0.00
Bs0.00
B$0.00
P0.00
CA$0.00
CHF 0.00
CLP$0.00
CN¥0.00
COP$0.00
₡0.00
Kč0.00
DKK kr0.00
RD$0.00
DA0.00
E£0.00
ብር0.00
€0.00
FJ$0.00
£0.00
Q0.00
GY$0.00
HK$0.00
L0.00
Ft0.00
₪0.00
₹0.00
ISK kr0.00
¥0.00
KSh0.00
₩0.00
DH0.00
L0.00
ден0.00
MOP$0.00
MX$0.00
RM0.00
N$0.00
₦0.00
C$0.00
NOK kr0.00
रु0.00
NZ$0.00
S/0.00
K0.00
₱0.00
₨0.00
zł0.00
₲0.00
L0.00
QR0.00
SAR0.00
SEK kr0.00
S$0.00
฿0.00
₺0.00
$U0.00
R0.00
ZK0.00
Already have an account? Log In

Transcript

Hello, welcome back to or near next video. So so far, you might have gone through our previous videos in which we, I gave you the overview of what this product is Python AI and machine learning, production and development kit from Tech laters dotnet. And then I also explained you how to provision this the virtual machine environment for this course, on a zoo, Google Cloud and AWS, I also gave you an overview of how this product is developed. It's basically a combination of a virtual machine on this cloud environment plus sample demos which comes along with this book over here, which is a really famous book in Baton AI and machine learning. And then I gave you the overview about how to access the virtual machine, so on and so forth. In this video What we are going to cover is we are going to cover how to use the Jupiter, Jupiter or ipython environment to run the demos as well as create your own new demos.

Okay, so already, if you follow the videos, previous videos, you know how to get a VM and access the Jupiter environment or ipython environment. So I am already logged in over here using the Ubuntu user. That's very important you need to log in using Ubuntu. You can create other users as well and provision Jupiter IPython notebook for them. That is covered in a separate video if you want to have multiple users, okay, so once you log in, you will get this folder you get into this folder. And in the overview video I also talked about the readme files at the top level, the readme file within the code at the bottom you can see okay, The README file in each of these demos for each of the respective chapters 16 chapters 16 demos right?

In this video, I'm going to tell you how you can execute the code. Now executing the code is the same as executing any code in ipython. So if you are not familiar with ipython, notebooks or Jupiter notebooks, I highly recommend you Google it or you look for the Getting Started videos on YouTube. There are plenty of videos you can choose any video which suits you and get a basic understanding of what an IPython notebook or Jupiter notebook is all about. Okay, here. For example, in our chapter 01, we have two notebook one is the readme file itself.

You can click on that and it will give you the instruction on how to use it. Chapter One, you can skip it Because chapter one talks about setups and those things. So this VM already has that setup done for you, so you can skip that. So let's go to chapter two, and I will explain you how to execute the sample demos. So in the chapter two, you have this README file. So this README file has all the instruction on how to use this sample in the second chapter.

But let's go through it. So here this chapter outline is, you know, what are artificial neurons how to implement a perception perceptron learning algorithm, adapt to linear neurons and so on. Okay, so you can refer to the book for more details, but if you already have some understanding about it, then you're not we can simply run the code Okay, so this README file is an overview of that chapter what is covered in that chapter. And then let's open the notebook itself. So, ch 02 This is the actual notebook. And also there is an, you know, the vanilla.py file.

So this py file has the similar code. And then there are other files which are used in the demo. So for example, I this data and this IDs name dot txt, these files are used in this notebook file or in the Python file, okay. If If so, so This video covers using the what you say the ipython environment, the notebook environment, if you are, you know, more comfortable with running the code in the command prompt then for that we have the remote desktop environment. So you can log into the VM using Remote Desktop, go to the command prompt. And then from that navigate to this folder, c 02 you can activate the final environment which I talked about in the overview, and then you can run this these files over there, okay, but ipython is more flexible, it gives you a lot of other options.

So, let's stick to ipython. So, to run this one I will open c 02 it will take some time to load. So, you need to have some patience over here Okay, so the notebook is loaded now. Now, this notebook will go through that code sample, it has the instruction for the code sample as well. Okay. And then what this notebook consists of, is something called as sales.

Okay, so you see, all these are sales The rectangles right as soon as I click on this, these are the cells okay? Now, these cells, some of them are plain text, some of them are code okay. So, the one the cells which are having the Python code can be executed okay. So, for example, you know these are some of the instructions here we are running that one So, you know I can just select that set, click on Run okay. So, it will go and execute the code within the sale. Now, here you see it is giving me an error.

Okay. Module not found it says some module is not fun. No model never watermark, okay? Why it is giving this error is because watermark is not installed. And this watermark module is optional. Okay.

So that's why you don't even if you get this error code, no model name watermark You need not panic Okay, you can just ignore this this error Okay. The next one is the actual code okay. So here you know, it is talking about what is this neuron and all that stuff, which is basically the technical technical details about it, okay. So artificial neuron a brief glimpse into the early history of machine learning. So, you know, if you're familiar or have some understanding of the various AI and ml related jargon, then the neurons are basically one way of creating or mimicking the brain neurons right. So here you know, they are explaining about it to explain that they are importing this image fine.

So if you go back over here, there is this images folder in that there is this video. In default, so, if I go back to this code for sorry, the home folder there is this images folder and over here not this one. So, my bad code zero to images he has you know you will have that fun So, all they are doing is importing this file, but before that I need to we need to import the image module itself right. So, what you will do is you will click on this cell click on Run it will import that module It is important and then you will select the next one it and then here you will see if if the command is getting executed. How will you know that you know whether this scammer What do you say that script of that statement is executed or not, is when you click on Run.

Notice this icon over here, okay? If I hover over it, it says kernel idle. So, this is the Python kernel, currently it is idle, when I click on run you will see that this icon changes okay. So, let me do that again. So, I am in this pecan run and here you will see right so, now it is in Colonel busy. And now again Colonel is back to idle state, okay.

So, this is this is a sort of, you know, the LED lights through which you can figure it out whether the command is getting executed or not, or it is complete or not, right. So, what we have done is we imported this image file over here, this is for the demonstration purpose how the neuron looks like in a human brain. Okay, and then, you know, this is the artificial neuron, which is mimicking the human neuron. Again, you know, you can click on this one and another email is important and displayed okay what is the perception learning rule? So, again they are trying to show you that in learning you have linear separation wherein you know you have some sample data and then you can segregate that with a linear line in some cases might not be linear but they are separable. So, here you know we can draw some curved lines and separate them.

In some cases they are not linear at all okay, whether through a line or you know some car we can't say great data. So, this is the, you know, this is what they're trying to demonstrate over here. So, I can click on that it will import that. Next thing here they are demonstrating through an email that how the neural networks work right. So, it is again mimicking the human neuron. So, for example, in the human neuron or here, you know, you have this cell nucleus dendrites input signal.

So, what happens is you receive an input signal and then there is something happening over here and then you receive some output signal. So, this in between is where the magic happens right. And our brain consists of you know, billions of such network of such neurons, where one neuron takes an input converted into some other output and so on and so forth, right. So, similar thing is happening in the neural networks, okay. So, what neural network is doing is it is having these multiple layers of input, having some function in between and getting some output based on some threshold. So, this is what this image is trying to explain.

Okay, again, importing the image. So, how are you going to implement this perception learning algorithm okay wherein you have a sort of neural network which can consist of one or more layers of this neurons which will receive some input convert it into some output that output might be input to the next layer in your neural network. So, in the next step they are talking about how the Python based various frameworks has this what you say provides you the mechanism through which you can implement this perceptron Okay, what are those API's So, here you are you can go through it, how these are implemented. So, this is the actual code, okay. So, all we are going to do is we are just going to select this okay and I'm going to run that one Okay. So, what it has done is it executed this cell in this cell all we have is you know one class called perceptron okay extending the object class and then it has the initialization then there is this fitting algorithm okay.

So, here is that logic for that one how are you going to get the input for this one, calculate the net input and then you can do the prediction. So, you know prediction is one one kind of NML mechanism wherein, you know you train your model and then you basically use that model for prediction purpose okay. So, one good example classical example you can say the Hello World of AI ml is prediction for spam spam mails right? So, you can have a perceptron you can train it based on your existing data which is classified as spam or not spam. And then once that model is trained properly, then you can use that model to predict a new message whether it is a spam or not okay. So, this is this is at a high level what this code is trying to do Okay, then there is this NumPy array we can run that one, this is the output.

Now, we are going to train the perceptron model, how are we going to train that we have this training data available? The training data is available over here. Okay, so, pandas is a very famous framework from Python which is used to work on csvs and Another kind of data, it gives you a lot of flexibility in how to handle that data. And here we are creating a data frame by reading a CSV file that CSV file is available online, okay. So, this read CSV will hit this URL get this data by the way this data is also available, if you go back to our C 02 you will see this Iris data and so, this this is the CSV file it is trying to read it from the internet you can change it to your local file as well okay. So, this is the data this is four, this is the training set again for the iris flower okay.

And again this is a very classical example for machine learning. So what it is trying to do is it is trying to if you want to get the background of of this exercise, I will suggest you do the readme file okay and this will explain what this is. This exercise is all about okay over here so we'll run this okay now it is what it is doing is reading the file from there and then showing you some last end piece like the tail of the CSV file. So here we had that CSV file okay at the tail, you know it is showing you these last four or five records you can see 145 to 149 All right. So this one okay, all these records are shown. Okay.

So, this training set, this is a training set which has all the data to classify some what you see some flower whether it is this one The other one okay. So there are like 233 sets of flowers Okay, three sets of Iris flowers in the data and the classification happens based on these coordinates okay. So, this is the attributes or properties for the first class then you know for the second class and for the third class so, we will use this training data and using this training data we are going to train our perceptron model okay. Using this data we are training the perceptron model. So, we imported the data. Now we are going to read this again over here.

Now plotting the iris data, okay, so, for that they are using the matplotlib another famous library for machine learning. What they're doing is They are plotting based on these coordinates we have this coordinates and this plot is giving us a very good understanding of all the coordinates or all the what you say the sample data which falls over here is this class okay and the all the other one this class, so, here you have a very clear segregation of these two classes right. So, if you feed this data into our model, then our model can understand that if the coordinates are around this range at the top, then it will fall under this class okay. If they are under this range, the x and y coordinates then they will fall under this class right. So, it will learn based on this training data and then later on when we execute the predict function then based on the coordinates we give in the predict function if the fall under this area, it will predict it as the blue class of the petal.

If it falls under this region it will predict it as the red class of the flower okay. So, so, this matplotlib is there to just understand how that data is visually looking like. So, if I run this one again you know here it is showing busy and it is plotting the plot over here next thing is training the perceptron model. So, here we are creating an instance of our perceptron class and then we are calling the training model and then we are plotting it okay. So, bye for now. It then it will understand what is the what you say the threshold on which you know it will trigger the output okay.

So, here again I will run it and our function will then come up with the what you say the decisions okay the decision regions and so here this is what I was talking about okay. So, you know it came up with this decision region which says that if the coordinates are so, this is the classification line okay. So, if the coordinates fall below this one then this is the class if it falls about this one then this is the class, so, these are the threshold okay so minus one and one okay. This is how it will get to end Okay, so this is the depiction I have a perceptron right and these are the layers. So, we will provide the input and then it will go through the weight function and whatnot which it came up with after running this code okay and this is the gradient descent and so on right.

So, we can run all this over here. This is like an image by like let's keep running this okay. So, this is how we implement the perceptron the other the other classification function is the adapter linear neuron. Again similar to perceptron there is a class there is an initialization there is the training function, model function and so on. Okay. So these are the different ways you can come up with your model, okay?

And then use that model to do the classification. Okay. All right. So so this is an overview of how you can use the sample codes and the readme files to understand those concepts. Okay? Now again, as I mentioned in my overview video, this the AI Machine Learning Kit, it's it's a middle path between the self learning and trained instructions, instructor based learning.

Okay, so what you need to do is you need to have that book with you. Okay, the PDF or the hardcopy, and then you can utilize that book, these README files in our environment, the setup environment and learn the machine learning Using the Python frameworks, okay. So this was about executing the data, sorry, the samples, which are already there in the ipython. notebook, which comes with a virtual environment. What if you want to create your own? Okay, how do you do that?

So for that, if you want to create your own IPython notebook and run some code, again, it's very simple. You can go over here, let's say you want to create your own folder first. Okay. And then within that folder, we, you know, have our own. What do you say? The ipython book, or IPython notebook?

Okay, so how do you do that? So for that you can click on this new you can create a folder on So let's let's say I'm creating this folder. Oops. Oops, whatever. Yeah, this it says untitled folder. So you can click on that untitled folder.

And within that untitled folder, you can create your own Python book okay? The economy and this time around, you can see notebook by country notebooks. So I will say Python three notebook. Again, it will be an untitled notebook. So I will just rename this untitled. Hello.

Yeah. Okay. And then here you have your own notebook. So you can see import pandas as PD, but on this, it got important. All right. And if you go back to this Refresh you will see Hello mm IPython notebook is created.

So, you can this way create your own folders create your own Python notebook run your own code, okay. So, this is the overview how you can use this for a machine learning the diabetic environment. So, I have given you the overview how to execute the code. So, what we are going to do is, as I said, you know, we are having this middle path, you can have the book, then you can go through this code and then you know you can go through these chapters one by one. Okay, like chapter two we have gone through chapter three, you can go and open the readme file, open the notebook file. The README file has the details about the topic Then you can run this one one by one and understand what's going on over there.

And this way you can cover all the 16 chapters from the book with out of the box, set up the sample course and everything. And then if you want to create your own code, you can go you can create a folder or you know, wherever you want to save it, create your own notebook and execute all the code. Okay, so this is how you are going to make use of this setup to get you jump started on learning Python based AI and machine learning, using our book from sebastia. Thanks a lot for watching.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.