In the continuation to the last session on machine learning we will now further study in this session. In today’s tutorial on machine learning we will witness a practical introduction to Keras.
So here we will see how you can work with Keras.
First of all you must know that we have to import this library.So import the library, so for importing you can simply write import Keras and by doing import Keras this library will be imported , so let us complete this with a small example. So the first example that we have is that we will load a dataset and we will work upon that.
So dataset I will load from here and this time we are taking the data pima (peema) indians diabetes data , so this dataset I am loading just see, this data set I have loaded and I will copy it’s path from here and this window I will hide , OK, so first we will load , so let me take text area here where I can write and explain , so first of all what we will do is load data and after loading,( 3 second pause ;typing) load data and second step will be define keras models and after defining the third thing that we will do is, that third thing is , OK we will come here, and then the way we give training either fit or we will train , and after training, before training also I will just add a step that we should first compile because we make the layers ourselves here , so we will have to compile and after compiling we can then train and after training, after training then we can evaluate , so these steps we will see, E V A L U A T E to evaluate, OK, so let us move further and first of all start with data load, OK.
So here we have, taken our data the pima indians . and here we will import the other libraries , so import numpy (num -pie) as np, this is one library and after this from keras so you can use from keras also and we can use tensorflow dot keras also, both ways we can do, so keras dot models and here import sequential (2 second pause typing) ,this sequential is a kind of model in keras, there is sequential, there is functional and you can study about this in detail the deep learning course , for now you just understand the models , means like for machine learning we make a model of the algorithm so here you can make a sequential model , you can make one functional model and you can make a model of model type also , so there are different types of model ,and as the name suggests in sequential there is one layer, then second layer, the third layer means the layers will be sequentially arranged in this and after this, form K E R A S dot layers , keras dot layers meaning what will you now put in the sequence , so you will put the layers only , so from keras dot layers import, what type of layer so here I specify dense layer , so we will apply a dense layer, dense layer meaning filled, filled meaning if I have a cell meaning if I have ten cells on my hand here then what I will do here I will create ten layers within this also and then I will make the next layer and in that also I will put ten cells , so dense means that ten cells from here, ten cells from here, five cells from the front and all cells here are linked together, connected to each other OK, so what happens in dense layer is that cells at the front and back of the layer are connected with each other , so this way I have imported a dense layer also here. So now let us load our data, OK, so to load , here we have taken numpy and so with the help of numpy we will load it , so np dot, here we have an option of load txt , so with load txt we will load it , so loadtxt is this option OK, so here D A TA dataset equal to np dot loadtxt and let’s see in the bracket that here it is asking for file name so we will put the filename here, so this is our filename OK and with filename what else does it require, here if we can mention that what is the file type, so file type like it’s delimiter so we will mention that , so delimiter L I M I T E R delimiter is equal to so here we are telling that this comma is our delimiter , OK ,it’s a csv file so comma is our delimiter , so this way we have loaded the dataset , now you will see that this is the dataset , so here is our dataset , OK, so here we have X also and Y also, there is input also and output also, isn’t it , so the last column here is what, it’s output and all before that are inputs. Here there are total nine columns, so what we will do here is , we will take out X and separate it , so X is equal to dataset and dataset of , what we will do here is take all rows and column from zero, starting from zero to seven so by putting eight it will take it till seven OK, and what we will do in Y is, Y is equal to dataset and in dataset we will take all rows but only eighth column , so this is how we have divided data into X and Y , so just see here is X in which only this column one is there OK, it is till fifty and here it is till fifty and Y if you see then it has only 0,1,0,1 data , this way, so we have separated our input and output.
So now we will move to the next step where we will define the models of Keras ok. So how we define the models of Kears that we will see once, so here first of all we will make the model M O D E L model, so model is equal to the sequential library we had taken here , so we will make a model of that , so sequential, so we have made a model, so here the model has been made , so now in this model we have to add layers , so how we will add, in this way, model dot add, like this and in the bracket here we have to add layers OK, so I had taken the dense layer , I had imported it so here I can do D E N S E dense and start making layers , I can create layers, see here I have formed dense , and in dense layer also there are some properties OK, the first property is that how many units , or how many cells do you require, so twelve, twelve means that I require twelve cells OK, and after that I will have to write how much is the input dimension, input dimension, so here X is , what is my X, in X there are eight , total was nine so here input dim meaning dimension will become eight here, ok. Now input dimension will have to be given for the first time, second time it’s not required to be given because the other layer will know that this layer is going to give it the output as input, OK, and now we have to give an activation function here , activation function so activation function you can implement using activation only , so there is a function called relu( ray-lu) , now these things are in a lot of depth, so for now you just understand that activation will activate this particular layer meaning the message will start passing ahead from here ,how it will pass will depend upon the function, if you use relu then relu will pass according to it , if you use sigmoid than sigmoid will pass according to it , so for activation there are different functions and the function will you will use the output will be passed accordingly OK, rest of the things I am keeping as default for now , so one layer I have added and doing this model dot add I can add the second layer also , so I am adding all layers of dense type, so dense and here I can take only eight nodes , so node you can increase or decrease according to your wish and here I am not giving the shape , I am not giving any input dimension because the upper one will send it’s dimension downwards and there will be no change in that OK, so this will get to know that the upper one had dimension eight and that only it is going to send me , in this way, so I have just added it OK. Now let us add one more, as I had told you that you can change the activation , so we can keep some other activation, we just add here and after adding I have put dense here and after putting dense I will just keep one single node and activation function I will change and keep Sigmoid, S I G M O I D , sigmoid , so activation function I have put as sigmoid , so in this way how many layers have I added , three layers I have added , there was the first input layer, then second, then third , so I have added three layers OK, so now after adding three layers I have to compile this model , so model dot compile , now we are performing the next step , model dot compile and now within compile if you want to give something it’s OK otherwise you can see that the optimizer here is rmsprop, loss none , so here you can mention , like here loss is none , so loss I will mention as binary cross entropy which will help me in classification , so loss is equal to B I N A R Y binary underscore C R O S S cross , E N T R O P Y , so here lot of terms are new for you , so do not worry about that , this you will understand further in the next level of course OK, now if you want to mention something else also, like you want to mention metrics or mention optimizer, but for now I am keeping it like this, so I am keeping it as it is and not making many changes , so in this way we can compile the model and after compiling the next step is OK, so before next step model dot what we have compiled I will just show you so model dot summary here will tell you that how the model has been formed , so here you can see that this is one layer, we had given twelve, this is second layer eight we had given , for the third layer we had given one, so whatever units we had given it is showing us here that how many in the first layer, how many in the second, this way OK, so this model has been compiled and this is the summary it is telling us in this way. Now like we do model dot fit in the model of any machine learning in the same way we will do model dot fit here and after fitting you will put X and Y here meaning you will put input and output and additionally you will put epochs( epo-cs) that how many time it is to be run, so E P O C H S epochs and here you will specify how many times it has to run so one hundred fifty times it has to run and here you will specify a batch size also meaning that how much data is to be passed in one go , so batch size I am giving is of ten meaning ten, ten records will be passed in one go, so like this you can pass, and in this way you can guide , so see that epochs, epochs I had given one fifty so it will run it one fifty times , just see here , it is passing the data every time and here it's is telling me the loss, as to how much , how much it is , it is calculating and telling, in this way after executing it fully OK, so this it will do one fifty times, here I have given it less, you can give more also, so this basically we adjust here that how many times do we need to run epochs, this also we do and see this loss has decreased very minutely from starting till now , see here it was sixty three percent and it has decreased meaning that if I run it more then chances of loss are even less right, so this I am telling for demonstration OK, here you can specify number of times to thousand instead of one fifty and then observe that how much does the loss decrease and again if you have any doubts then you must go to the comments box below in discussions and there you will start getting reply from learners like you, you will start receiving replies OK, and now here let us once evaluate also and for evaluating, model dot evaluate , so yes model dot evaluate , this we will use and here I will pass both X and Y and let us see how much accuracy is there , so here you can see that the accuracy is very less zero point four nine percent , so this was just an introduction as to how you can use Keras to write a machine learning program , so let me give you a quick recap , so we have to import and import keras, and from keras if you want to import something then from keras dot model import sequential , from keras dot model import dense OK, data I loaded from numpy only , you can load from pandas also OK, numpy is avery basic and nice library so you can load it from there and after that I have converted data to X Y meaning I have divided it into input and output and then I used this data directly, where, by making a model , so sequential model I made so type of model is sequential and I kept on adding layers to it, I added three layers and after that I compile the model and then in the summary I could see three layers , that three layers have been formed and now I wanted to train the model so with model dot training we gave it training, and with training it kept on telling me the loss and then finally I once evaluated it also and in the evaluation finally we still got a loss of forty nine percent so means,means accuracy is very less , so this was a short introduction on keras , so I believe this will make you enthusiastic about keras and deep learning and we will further learn deep learning. And very excitingly I am announcing that now we will do a project and after this project we will do something more exciting, so keep watching, remain motivated , thank you very much.
With Keras, you can create deep learning applications to solve a variety of problems.
Some of the most common use cases for Keras are:
- Developing custom machine learning models
- Training models on large datasets
- Creating convolutional neural networks
- Building text classifiers
The Python-based high-level neural network package Keras can be used with either TensorFlow or Theano as a foundation. It was created with an emphasis on supporting quick experimentation. The secret to conducting effective research is being able to move quickly from conception to conclusion.
Keras has two main focuses: ease of use and speed. We want both novices and experts to be able to create powerful, complex models with minimal fuss. To achieve this goal, we make use of two main techniques: abstraction and modularity.
Abstractions are provided in the form of high-level building blocks that can be combined in different ways (layers). These abstractions are simple enough that they can be understood in a few lines of code but powerful enough to be useful. A layer is a "module" that can be used as a building block in your application. These modules typically define abstractions for performing common tasks such as interfacing with the DOM, managing state, and executing code.
Keras is a deep learning framework that is written in Python. It has been designed to be user-friendly, modular, extensible and fast. Keras has the capability of running on top of either TensorFlow or Theano.
Some of the benefits of Keras are as follows:
- It is user-friendly which makes it easier for programmers to learn and use it.
- It can be used in a variety of fields including computer vision, natural language processing and speech recognition.
- It has been designed in such a way that it can be extended with other models and libraries which makes it more versatile than other frameworks out there.
- Its speed makes it more efficient for large datasets where data loading time is an issue.
The importance of practical demonstration in Keras is that it allows users to make a prediction or estimate the output of a model. It also provides an opportunity to see how the model will behave in different conditions.
Practical demonstration is important because it allows one to make a prediction or estimate the output of a model and see how it behaves in different conditions.
Keras is an open-source neural network library for Theano and TensorFlow. Keras can be used in a project in many different ways, such as:
- Creating deep learning models
- Compiling Theano code to TensorFlow
- Running pre-trained models on new data
Input data is the data that goes into a neural network. It is typically given to the network as a matrix of numbers.
Keras is a Python library for deep learning and neural networks. Keras provides high-level building blocks that make it easy to construct deep learning models without having to implement the low-level details.
You can use input data in Keras by loading it from an external source, such as CSV, or by generating it randomly with arrays of numbers in Python code.
good learning but the content titles are jumbled up, like first title of this module is decision tree dichotomiser which is practical part ahead of theory part. Same with the SVM practical 1 title has
Isakki Alias Devi P
yes, i am happy to learning for machine learning in LearnVern.it i s easily understanding for Beginners.
Superb and amazing 😍🤩 enjoyable experience.
Muhammad Nazam Maqbool
Absolutely good course... will suggest it to everyone. has superb content that is covered in a fantastic way.
super course and easily understanding and Good explaned
Ruturaj Nivas Patil
Very well explained in entire course. Great course for everyone as it takes from scratch to advance level.