Uh very good afternoon to you all so I welcome you all to the session so this is the last session in this course so till now we had discussed in detail about different different algorithms for or say the different ways to process raster as well as Vector data so today we will talk about different Paradigm right so I will uh talk introduce you to the concepts of machine learning so today lecture will be I will try to Cover it maybe in two parts so in the first half I will introduce you to the fundamentals of
machine learning and artificial intelligence and in the second part I will show you a live demo how do we use the the techniques which we learn in the lecture uh to for uh geospacial data Pro I will specifically showing you how do we use machine learning for some geospacial data processing so we will be teaching two parts one we will try to identify water Bodies in a satellite image using machine learning and if time permits we'll even try to cover how do we create a land cover map using machine learning right so in the first
half I will just introduce quick try to quickly uh cover up what cover what uh what what is the machine learning and in the second half we will talk about implementing or see how we keep the these things to practice so in this uh lecture I will try to introduce with the basics of AI ML and deep learning then I will talk about what are different types of machine learning algorithms are available so basically I will focus on the two algorithms one is called decision tree algorithm and random Forest algorithm then you'll see where where
all machine learning can be applied in remote sensing area right and the second half we will see a live demonstration of how do we use these machine learning algorithms for geopal Data applications so we'll start with what is called intelligence right so intelligence can be Loosely defined as the capability to obtain Knowledge and Skills and apply those to various situations without supervision right so if a person has the ability to obtain ability or capability to obtain the Knowledge and Skills and apply those to different situations without have without any supervision right so that what we
call Intelligence so intelligence is basically connected to something called abstract thinking or to say selfawareness but properly it cannot like there cannot be there is no universally accepted definition of intelligence like people say that if a person possess these capabilities then only we can say that he's person or object is intelligent but there is as such there is no universally accepted definition so loosely we can say that Capability to obtain Knowledge and Skills and apply to those two different situations what we encounter in our real life so generally if we say intelligence is made of
made up of capability to reason like like how do we reason reason about something make reasoning from something then learning learning right learning from maybe our environment or from Reading somewhere right then the skills of problem solving making perception about something and Linguistic intelligence so if if you say that if an object machine or person contains these capability he has these capabilities to reason about something or even learn from something from its environment or maybe by training or he has the capability to solve the problem once he has learned something and if he's able to
solve some problems by applying these things which he has learned and he can make perception about something and linguistic intelligence is Also a part of intelligence so as we say human beings are innate intelligence like we can say that in human beings this intelligence comes naturally right so this is defined as intelligence that governs every activity in our body everything in our body is governed by our intelligence like our brain give signals or for everything for different parts of our body to act according to the situation right so what is down next Thing comes what
is artificial intelligence so if you can say the science and engineering of making intelligent machines especially intelligent computer programs like so till now whatever we have computer programs we write so the solution generally is written by a human being right we write the solution to certain problem problems so if we keep ahead keep aside the part of machine learning in general we can say that the computers Are just a dumb machines they just execute the instructions which a programmer or coder writes right but the capability of computers in terms of they can execute billion of
instructions per second and they have a huge memory size right that person human doesn't have so these things make computer very useful but they cannot think of themselves they cannot make sense of sense of something like if you say the speed speed I say 10 kilm per hour the Machine cannot make sense of this 10 km/ hour it for it it is just a number as a human being we can say that if I say 10 km per per hour I am moving at the speed then I can reason about it like whether it is
a safe speed or something like I can make sense of that speed but computers cannot make sense of that number so artificial intelligence is all about making a machine which can think of itself like if a problem is posed to that machine it must be able to derive The solution for that problem by itself till now if you leave the machine learning aside so we as a programmer we only were writing the instructions to solve that particular solve some problem right in a in a programming language so but machine was just executing those instructions and
as I said that machine has the capability to execute the billion of instruction per second so it can keep on repeating those instruction maybe any number of times right so Artificial intelligence is all about making a machine which need not to be instructed specifically like we can just we want to build a machine such that we just give it a problem and it must be able to solve that automatically so there are so people have tried different ways to make such intelligent machines right some people have tried to make the machines or actually they this
is the they thought that this may be the way in which they can make intelligent machines Like they wanted to build a machine which can think like people like they just wanted to build the machine which can think like people but there is not much advancement in this way of building machine so they could not succeed much and then some some people tried to make machine that can act like people so acting means they they just tried to mimic how a person uh behaves in certain situation So this is also one of the technique with
which technique for developing intelligent machines and some people Tred to make machines which can think rationally right so so that they can think depending on what kind of situation they are encountering so depending on that they just try to build a machine which could think rationally so so but there was no breakthroughs in these areas like people were not succeeded people did not Succeed much in making machines in these way so one of the most successful way of building artificial machine was like the machines which can act rationally like so this is one of the
most successful ways of ways till now for creating artificial int artificial intelligent machine like act rationally like we we can train the machine on a lot of previous data so once the machine has learned about the data then it can act based on its learning on a New situation like it can apply its knowledge whatever it had learned from the previous data to a new situation so this is the one of this this way people have succeeded in you can say that in this is the most successful way of creating we can say the artificial
or artificially intelligent machines so acting rationally so type if we broadly divide the types of artificial intelligence we can say that artificial intelligence Basically is of two part two types one we call weak Ai and another is one we call in strong AI so weak AI is also called narrow AI or artificial narrow intelligence so it is it is an AI that is trained on a trained and focused to perform some specific task so the machine will be just trained and focused on focused to perform some specific task right so vki is highly specialized and
does not possess humanik cognitive AB abilities or general problem solving in Capabilities Beyond its narrow domain so if a machine is just trained for solving some specific set domain of problem that we can say that that the AI is weak AI like these are some examples of these weak a like Apple Siri you must have heard about or Amazon Alexa IBM Watson and some you can say some autonomous vehicles so they are specifically trained for solving problems of certain domain only they cannot General solve any problem as a human being solved so There is an
other which is other kind of a that what we call strong AI strong AI or artificial general intelligence refers to AI systems with human level intelligence and understanding right so as the claimed by op AI this so they think I think within two or three years we are about to get to achieve this artificial general intelligence so artificial general intelligence is made of artificial so this strong AI is made up of artificial general intelligence And we can say artificial super intelligence AGI is a theoretical form of AI where a machine would have an intelligence equal
to humans we can say then artificial super intelligence is also known as super intelligence there we assume that the machine will surpass the intelligence and capability of a human brain right so I think AGI we are going to achieve maybe as per the statement of open AI or different communities so maybe two and three years We may be able to build a machine which has the intelligence level of a human being so now there are three things one some some at the top level one we something what we call artificial intelligence so artificial intelligence is
all about to make a machine an intelligent machines right so as we said that artificial intelligence is all about making a machine which has the capability which has the cognitive level of a human being Right so that the artificial intelligence is a broadest umbrella right so like you can say the ability of a machine to imitate intelligent or intelligent human behav that what is called artificial intelligence now there can be multiple ways of building and machine which there can be which can think right so so like if you can write a very complex program containing
so many Situation so many handling so many situation and all so that also will calling calling artificial intelligence like so artificial intelligence is all about making a machine which can mimic human capabilities right so now now there can be multiple ways of building an intellig intelligent machine so one of the most suc successful way of creating an in intelligence machine is machine learning so applications of AI that allows the System to automatically learn and improve from its past experience as I said that this is the area which has evolved most like where we can build
a machine which can act rationally like this is the most successful School of what you can say that intelligence so beinging artificial intelligence is a broader umbrella so writing any uh writing the program writing an intelligent program which can mimic human behavior in any complex way That everything will be a will be called artificial intelligence now there is a there is a specific way of making a machine intelligent that is the we call it what we call learning from the previous data so that is called machine learning so this is a technique of artificial intelligence
or we can say the subset of artificial intelligence where we make an intelligent Machine by training it on something called some past data right so once the machine Learns pastar learn something from the past data then it can act based on its experience right so that what we call machine learning so artificial intelligence is the broader umbrella so machine learning is subset of artificial intelligence for making intelligent machines that uses training on the past data so there is an now now training a machine also can we can train we can train a machine on the
past data also in multiple ways right so There is a specific subset of machine learning for training that what we call do deep learning so application of machine learning that uses complex algorithms and deep neural networks for for training a model that what we call Deep learning so artificial intelligence is a broader umbrella so machine learning is just a subset subset of artificial intelligence that uses previous data or history historical Data to learn in different ways from that data to make machine intelligence right so now learning from the so deep learning is again another subset
of machine learning that also that uses deep neural networks for learning from the past data right so artificial intelligence is the top level then machine learning is a subset of that and deep learning is again a subset of machine learning now if you say that this is the Entire landscape of AI and AIML and DL so artificial intelligence like we can say that we said that artificial intelligence is ability to sense reason engage and learn from something so these are the some Avenues of AR Ai and ml a computer vision natural language processing voice recognition
Robotics and motion planning and optimization knowledge capturing and all so machine learning is ability to learn from the past data one of the way subset of Artificial intelligence where we learn from the past data that what we call machine learning so machine learning has uh in its supervised learning un supervised learning reinforcement reinforcement learning or computational scientific discoveries right so then deep learning is ability to learn many layer neural networks from the vast amount of data so deep learning is again a subset of machine learning which which uses deep neural networks for learn or Train
a model so to our today's focus is basically on just on the machine learning so you can say if you briefly talk about machine learning machine learning has its origin in statistics and mathematical modeling of data so the fundamental idea of machine learning is to use data from the past observation to predict an unknown outcome or value as we said that our now our objective is to build an intelligent machine right so Then there can be multiple ways to build an artificial intelligent machine as we said that there are there were the four School of
thoughts which which people tried to make AI or intelligent Machin so machine learning is one of the subset of artificial intelligence where we try to use data from the past observations to learn and use that learning to predict something new in the Futures so like machine learning is the ability of computers machine learning is That machine learning uses ability of computers to learn from the past data or you can say past experience so the data now from where the data comes so data comes from a various sources such as sensor maybe the domain knowledge of
the people or some experimental runs on something right so now learning is to make intelligent predictions or decision based on the data by optimizing a model so machine learning is all about like we will be giving this all past data to our Machine and machine will try to associate or learn some patterns or something from that data and build a model once that model or machine say is trained on this data then given a new data it will just try to infer something new from the whatever we whatever it has learned now based on whatever
new data we might give so Bas on that new data it can predict like what what it is so then we will talk about how the prediction works and all So approximately we can say that machine learning we can say is machine learning is a universal function as we said that because machine learning is based on mathematics and statistics it is common to think about machine learning in mathematical terms fundamentally a machine learning model is a software application that encapsulate a function to calculate an output based on one or more input values right so like
we said as we said that machine learning is all About learning from the previous data so machine learning is you can say that these are the input features so machine learning tries to associate these input features to that output like what is a mathematical function mathematical function is such you can say that is it is a mapping from some input to an output so similar similar to this similar to the function machine learning is also like we will have we have a set of input features and we try to Associate or infer a function like
how how does these input lead to this particular output right so machine learning is all about finding the relation like how these X1 X2 and X3 are leading to some particular y right so machine learning is all about we can say that approximately machine learning is kind of function FX F that associate these X or input attributes to the output right so the process process of defining a function Is known as training so training is all about finding this function f that Maps these input feature X to some known y so we can say that
after the function so like this is this we have this we will be having this input data where we will have like these input features X1 X2 and X3 so X1 X2 X3 lead to make some value y1 so similar way other values of x's may lead to some other value of y now we try what is what our objective in machine learning is to identify a Function f that Maps these all X1 and X2 X1 X2 X3 to that corresponding y1 Y2 or Y3 right so the process of defining function is known as what
we call the pro is called training so after the function has been defined we can say that the machine model is has been trained and once the model is trained now for given any new set of X1 X2 and X3 the model can make a new prediction prediction whether what is the outcome of these X1 X2 NXT right so this is Called in infering inference or infering so ultimately what machine learning in summary we can say that given a machine learning problem so first we need to ident identify and create appropriate data sets on which
we can train our machine learning algorithms then we can perform different computations to learn from the the data which data set which we have then learning means uh finding the required rules and patterns That derive the relation between input and output once the machine learning algorithm has been machine learning algorithm has learned about those parameters then it can output the decision give for suppose for any given new data so this machine learning in summary like we first we need to identify the data set for training our model so then in the identify first we need
to identify the data set then on the data set we need to train our model So that will model will identify the relationship between input and output that as we said that as a function so once that function is established now the function is ready now given a new set of inputs it can infer at the value of output it can it might make a prediction of classification or it might be a regression thing so now if you talk about types of machine learning basically types there are basically broadly if you classify there are two
Kinds of machine learning what one we call supervised machine learning and another one we call unsupervised learning so the idea in supervised learning is that we have input data and it's Associated labels already right so like X1 X2 X3 and what is the outcome of that X1 x x maybe y y1 Y2 or Y3 right in case of supervis learning we have the data and its Associated label also like suppose if we have a set of images of say dogs and cats like then in the in Case of supervis learning we have like this is
this is an image of cat and Associated level of that image also like this is a cat or this is a dog or this is a mice or something like this then in case of supervised learning we try to associate these pictures or input features with their label say dog or cat and in the future given a new image so our machine learning algorithm must be able to predict whether this is an image of cat or dog so there's Another kind of learning what we call unsupervised learning in case in unsupervised learning we have just
the data set right so we don't have the associated label then we just try to identify the similarity between two objects and we just try to group the similar objects together right like here we can say that we have S such images then we just try to clustering so this is this is also called clustering we just try to group together similar items So the similarity may be in terms of maybe the color of that or maybe type of object so depending on our application we may cluster them or group them together so supervised machine
learning can be used for two two kinds of problem as we said it can be used for regression as well as well as classification so regression is when we just try to predict some continuous values like you are you want to predict like like what is the temp what will be The temperature tomorrow so that what we call regression so when we just try to predict continuous values from the input that what we call regression and the classification is when we try to predict some discrete values like suppose if you wish to say that whether
it is going to be tomorrow will be hot or cold so when we are trying to predict some discrete Valu that what we call classification so the classification can again be a binary classification where we just say that Zero or one so when we want to classify it in just two classes like say hot and cold right or it could be suppose it can be multiclass classification so suppose we have like three kinds of like whether these are birds scale or something something like this so classification also can be binary classification we where we are
just we just predict two classes maybe zero and one and it can be a multiclass classification also when there are more than one classes as You'll be seeing in our land cover classification where we talking multiple classification so what we can do with machine learning algorithms we can machine learning algorithm can be used to predict a Target category so either we can use a two class or binary classification say will this tire fail in the next th000 miles yes or no or we can say which brings his more referrals rupes 10 credit or for giving
a 10 15% discount right so Machine learning can be used to predict a Target category maybe we wish to uh do a binary classification or multiclass or multin multinomial classification in which months do the majority of Travelers purchase a airline ticket like suppose B we have a lot of airlines uh traveling ticket sales data so then then with from that if you can uh infer like in which months do the majority of Travelers purchase airline tickets what emotion is the person in the photo Displaying like the person can cannot we cannot say that just happy
or sad so person can have in multiple uh like so we can use it for predicting a Target category so ultimately all the problems whatever we are going to solve either fall into classification or regression problem on right so or even you can use these machine learning algorithms for finding unusual data data points also we can say you can use it for animal detection so Algorithm that identify data points that fall outside some defined par parameter for what what it is called normal like so whatever data that is outside something like what are the defective
Parts in this batch or which credit card purchase might be fraudulent like this is not following certain pattern so we can use it for predicting a Target category or you can use it for anomal detection right so then we can predict the values as well either regression or Classification so regression algorithms predict the value of a new data point based on some historical data so like how much will be the average two-bedroom house cost in city next year supp if you want to predict so that is going to be a continuous value so that we
call regression so how many patients will come to the clinic on say Tuesday right so and even it can be used for see see how values change over the time or even machine learning can be used for time Series analysis time series algorithm show how a given value changes over the time so basically we can say that all the problems which we solve using these machine learning fit into either of these criteria either it might be it might be a classification problem or it may be a uh regression problem in case of classification we just
try to predict some discrete labels and in case of regression we just try to predict the continuous values or even machine Learning algorithms can be used for doing time series analysis as well so as we said that there is a special class of machine learning that what we call supervised learning as I said that in case of supervised learning we have data plus their Associated labels as well right now this is take an example of this now suppose you have we have these sets of images right so we have these sets of images plus they
Associated labels as well like we can Say this image represents car this also is an car this also is a car is a bike sorry this is also a bike right so this is what we call calling samples so the samples or what we call features so the these featur features may be many different features right so this and we have their Associated data level so this combined we will be calling something called training data set right now in training our now in training our Objective is to associate these input features to their corresponding levels
right so we we we need to identify a function like so so in the training what our objective is in training our objective is to find identify the relation between this this image and its corresponding label right so how they are associated like our objective is to identify a function that given these this this input image it must be able to associate this image with the label Called car or this image also to the label called car right so training our our idea is to find a function f function f that associate these input features
to the label so on that we got what we call the training of the model so once the model is trained that means we can say that we have we are able to identify the function f that associate these input or Maps these inputs to these their corresponding levels now once the model Is trained to given a new set of so it will then finding the uh this function f and its Associated parameters once this is done then we can say that then we can give this function any new input say a new image so
it must be able to predict whether it is a car or say it is a bike so that is all of our supervised learning so in case of unsupervised learning we have just a set of images or say set of features but we don't have their Associated labels right so here we Have just the set of images then we don't know whether it is a car or bike so in unsupervised learing we just try to group similar objects together right now these two objects look look alike like they have some similarity to one another now
that similarity we can Define as we go so like then it groups these two things together and these two objects together later on we need to apply our domain knowledge to say that okay these two objects are car or these Two objects are bike so on supervised learning is all about finding similarity between the data like we just we can just need to it just just just cluster similar objects together or even it can use for finding the association between different objects like suppose if you have these car these IM like car and the air
purifier or bike and helmet so it may just may even try to find the association between objects like even if They are not uh similar to one another but it it can be used even to find the association between different object that are that are something then another kind of uh machine learning what you call is reinforcement learning so reinforcement learning is like it has an agent an agent takes an action and based on the action environment acts like it it might award it it might give it a positive award or a negative Award right
so this is like Suppose if you are if you give a child to uh learn how to play a video game right so we are giving a video game and the child like moves this to left or right like if the if this horse eats this this object then the environment or say video game assigns it a positive reward or suppose if it it moves and hits to that octopus then it it may give it a negative negative thing right so this way once uh like this you give a game and the child Slowly learns
from this right so from its mistake it keeps on learning like once he knows that's after some experimentation the child knows that if he's doing certain step like if it is eating this this particular object then the game is giving it a plus plus one right if it is hitting on this octopus it is deducting points from its score like this a child slowly learns how to play a video game so Similarly if we try if you try to train a machine like this so so we don't tell specifically the rules to the machine right
so then machine learns of it's environment if it does a right step then a positive reward is given and otherwise a negative award is given so slowly machine learns how to maximize the positive Awards so these are the parts of reinforcing on something what we call State action and reward and based on that so these are the specific Components of there will be agent so that will be taking an action right so based there will be agent that takes an action So based on the action environment will give it award or say punishment and change
the state then slowly this with this way the machine learns how to maximize its award like we say an example as we said in the case of supervis learning we have the images of cats and dogs and they are Associated label as well this is image of cat this is image of dog right then we just try to make a machine learning algorithm which tries which finds the relation between the image and its corresponding object and given a new image just to predict the output and then in the second case in case of unsup wise
learing we have just images of cats and dogs right and then our algorithm tries to group together similar objects like it just try to group together all Cats or all dogs then in case of unsupervised learning like we can say that we can just show an image to an agent and we don't know we don't tell him that is cat or dog so if he says if he says dog correctly then we give him give him positive reward if he says cat to the dog then we punish him so like this we give him several
hidden trials so like this machine learn this is what we call reinforcement learning right as we have SE seen that We re reward computer for right answer that what we call reinforcement learning now how the traditional development Paradigm and what we could use in machine learning how they are different from each other so in traditional development Paradigm as as I said that we ourself for Sol in a specific problem we ourself have some data right so we just write the rules for or steps for solving the problem so how do we read we just write
the algorithm or we can say That how do we reach from this input to that particular output right so we we just frame those rules like by these by Sol by applying these set of steps we can reach we can get solution to that problem so this is what our traditional uh de vment parad where we where a programmer or coder writes the set of steps to solve the problem right so but in case of machine learning we have a a lot of data and input data and their corresponding answers as well as we said
That in case of supervised learning right so we have a set of data and their corresponding answers as well so in case of machine learning so machine itself tries to find out the rules Like rules which lead need for this set of inputs that particular output right so in case of machine learning we are not writing the program for solving this like we are not writing the solution we are just giving the data and their data and the output then machine Itself is inferring the rules for reaching the reaching for getting the output for that
particular set of input this is what is this is how the machine learning Paradigm is different from the traditional error paradigm so in the case of supervising as we can say that we can use either statistical modeling or neural networks it is all about knowing the answers ahead of time right in case of machine learning suppose this this is this is Our images and we already knew that this the these pixels represent some some water these pixels represent a rock or these represents agriculture area and so on so we already know the anwers so we
just try to train the model on these input and outputs and once model is trained then we give a new set of inputs and it's just predicts the output so supervised machine learning is based on the following Core Concepts we can say that data model training evaluation or Inference so this all is all about supervised learning so supervised learning as we have discussed can be used for solving regression or classification problem so in case of regression we are just trying to predict some continuous Valu so regression can also be a linear regression or it can
be a polinomial regression so these are some examples of linear regression so in case of classification we just try to predict or say uh produce some discrete Labels like you are doing for image classification suppose an image you want to just classify into map of categorical classes like land like urban area water green area and so on or like whether this particular email is Spam or not so there is so in supervised learning there is a very popular algorithm for doing this learning from the data is called decision tree based algorithm so decision tree are
nonparametric supervised learning Algorithm that are used that can be used for classification and regression so I'll be teaching with an example so a Tre can be seen as a piecewise constant approximation the questions are usually called condition or a split or a test right suppose if you are doing based on that data suppose based on that we just we want to classify whether some uh species right so some so so we have some uh data about these spe species and maybe suppose if you have Already their levels attach attach as well so so in case
of decision tree based algorithm we just try we just try to ask different set of questions right so suppose we suppose these are some attributes we have these attributes of these levels like number of legs they have number of eyes they have right so based on that suppose if you used to classify then the first question suppose if you are asking number of legs if the Number of legs in this SP b or sample which we are seeing if greater than equal to three if there are the number of legs are less than three then
we if it is greater than three is no if they have less than number of three then we can say this is a penguin and we have reached a leaf node and if number of legs are greater than three then we are checking then then we are not able to directly derive something then we can then we are checking the second Condition if number of eyes are greater than three if yes then we can say this is a spider and this is otherwise this is a dog so when we are trying to solve a problem
like this this this is what we call decision tree based algorithm so decision tree is a model composed of a collection of questions organized hierarchical shape of a tree each Leaf node contains a condition and each non-leaf node sorry each non Leaf node contains a condition and each Lo Leaf Node contains something prediction based on that data like suppose this is we have a set of data like this in case as we said that in case of supervised learning what we are doing so this on I will be showing you as a demonstration as well
suppose this this we have a set of data like this if the this is the reflectance in different bands and whether that particular class represents this whether this is a water pixel or say nonwater pixel right so These are different values say 90 59 58 so if and if this in this range the values is 12 then you can say this is a water pixel if this is these are these Valu that then also it is a water pixel and these are this then these are nonwater pixel right so in the traditional programming what we
will be doing we need to derive the rules the whatever decision tree we have talk the decision tree we need to build ourself right if an like this is a sample of Sample for this we can say that if n IR is less than 52 right if that becomes true and then swi is less than 52 then we say that this is with high probability we can say this is a water pixel right so in the traditional Paradigm we will be framing these rules ourself right but in case of machine learning so on WE once
we train the machine learning algorithm on these set of data sets so the machine learning comes on its own Right so it derives a decision tree like this for us right so in case of traditional Paradigm we need to derive this tree ourself like these if and El's we need to derive ourself we need to analyze the data data like this and frame these rules like if an IR is less than 52 and s is less than 22 then we can say this is a water pixel if n is less than less than 22 and
S is s also is greater than 42 and again s is less than 52 then We can say this is a nonwater like this in traditional Paradigm we I need to build the tree ourself and then the write an algorithm but in case of machine learning we just give this set of data to our machine model and the model gets trained on this data and they just try to associate these uh uh input features to these corresponding levels and model itself tries to build this decision tree for ours for us right so this is the
advantage of machine Learning so now how do we build this how a machine builds such a tree so there are different algorithms for that so one of the most popular algorithm for that is what we call classification and regression tree or cart algorithm right so the cart algorithm first splits the training set into two subsets using a single feature and a threshold T right so first suppose these are some these are these all are called input features and this is an Associated level so the Algorithm first splits the training set into two subsets using it
it just first uses a filter sorry a feature and a threshold t such that this value is minimum for that right it searches then it sees for it searches for a pair of uh input feature and a threshold t that produces the purest subset weighted by their size like in that subset there should be only single class once it sucessfully split the training set into two it splits the subset using the same Logic then the subset and so on recursively right it stops recursing using once it reaches the maximum depth like whatever you have defined
maximum depth that end it just stops there so there is another algorithm called random Forest so the cart is for decision tree and random Forest random Forest algorithm is a supervised machine Al machine learning algorithm that is extremely popular and this also is used for classification as well as regression Problem so uh random Forest is a classifier that contains several several decision trees right so now our training data on our training data set we just instead of just training a single decision tree we train multiple decision trees right so now once multiple decision trees are
trained on this training set then we just use the uh voting problem like majority mvl majority voting logic like suppose if you are using it for prediction so Whatever class is predicted by most of these decision trees that only will be used at output so this is random forest in case of decision tree we just build a single decision tree and random Forest is when where we use a collection of decision tree then we we we will train different decision trees decision trees on the training data set and then finally we use the combination combined
output of all these decision trees for you predicting the Output so unvis learning models makes prediction by given given data that does not contain any correct answer so in case of unsup learning we don't have Associated levels and unsup and unsupervised learning models goal is to identify meaningful patterns or similarity between the objects like here you can say that if these were the features or input input picture then it has just tried to group together similar items maybe based On their shape or color or whatever it is a commonly used of UNS supervised model learning
algorithm employs a technique what that we call clustering so clustering algorithm divide the data into multiple groups by determining the level of similarity between them right in case of unsupervised learning now we don't have the associated levels we have just input data and we just try to identify the similarity between the objects once the similar objects are Identified then we apply our domain knowledge to say that like okay all these pixels belong are water pixels these are agriculture area and these are rocks like this right so like this much clustering is all about like un
supervised learning is all about finding patterns or similarity between the objects like here we can say that these are the different cluster but one thing is clustering might be subjective right so applications of machine Learning in remote sensing application in machine learning can be used for object detection it can be used for even for doing some kind of change detection right so detecting changes how the on how to extend centic analysis on Multi temporal data we can use machine learning for doing some change detections even it hyperspectral it can be used for classifying hyper spectral
data using CNN and deep learning can be used for SAR like specifically for Des Spackling the data or say making Cloud free images right so then even it can be used for classifying different deep learning algorithm can be used for classifying SAR data and you can use deep learnings for deep learning or machine learning algorithms for doing building damage assessment land cover mapping Glacier and map monitoring renewable energy mapping any kind of classification of regression problem so even these are Some some these are some areas where deep learning can be used specifically in remote sensing
so with that I come to the end of this particular now we will cover the Practical part of this now let us because now we don't have sufficient time so I'll just try to show you we'll just try basic binary classification or just I will just quickly go through even time permits I will quickly go through through uh I will not cover explain much In detail then even we can just try to cover the multiclass classification as well where we'll just try to do a what do we call a land cover classification right so for
this I'll be using a library called psyit learn so psyit learn is one of the most popular or versatile library for doing machine learning in Python so this introd int introductory notebook familiarizes us with how do we train a train a machine learning model For this work we will be using the data from listry instrument so the training data which I have used here is listry instrument from the resource satellite and we'll just try to train a decision learning algorithm for doing doing a binary classification we'll just try to a binary class we'll just try
to identify water and nonwater pixels actually already we have done this using some ndwi but what the what the dis disadvantage of was in ndwi was That we need to First choose a threshold right so choosing a threshold also is again a big problem so in case of machine learning we need not choose any threshold right so we have just a set of training data web where we have input features and their Associated label and the Machine learning algorithm or decision tree itself will try to build a decision tree right decision Tre based on the
cart algorithm so now as we that we have discussed so now I'll just Quickly go through this so anyway you need not get scared by seeing these many inputs so these are not so important so for time being we can say that SK learn is our package right so other things confusion Matrix and other thing we will not cover right now so once first you need to activate your environment and in that you can just cond install psychic learn you can do cond install K uh cond install minus CA 4 psyit lar and if you
are using Google cab py Lear is already installed there right so these are some packages which you need to in import from the uh psychic learn so basically we will be using a function called psychic learn. modal select train test split and psychic learn. tree import decision tree classifier because this we are be we'll be using for our algorithm today so from Psy SK learn. tree import decision tree classifier this is the uh Basic package then that we are calling it as DT right so and other things are other things are same as our other
UT so only thing you need to remember here is SK learn. tree import decision tree classifier as as we are calling it as DT then I'm changing my working directory to the directory where my data is available so first now as I said that now we will be using for decision tree a supervis learning algorithm so I have already prepared training data set right So if you are working on your case then you need to now how the training data looks like let us see so if I see this data DF do head so in
this I have four bands like these are these what we call these will be calling input features so band two band Three band four band five and their Associated label like here we are saying that if the input the pixels reflectance is Band 2 is 90 Band 3 it is 59 band 4 58 and band 12 it is 12 then we are saying that this is a water pixel like similar way these are different values like like had it been a single value for all these pixel pixels then we could have said that said that
okay the pixel has these values in the band then we can say that this is a water pixel otherwise it is not is a nonwater pixel but there are you can see that the range of values like even for 88 55 56 55 and 15 also it is a water pixel and for these values also it is a Water pixel and there are there may be some pixels for which it is a not non water so now in this in our training data set now we have both types of data pixels both classes pixels with
water pixel as well as not nonwater pixels right now so this water is our label and these all bands are our input features now we have four input features right so this x input features will be calling X and output features we will be calling y so I'm just popping or Removing the water column and assigning it to the variable called y DF do pop water and once this is removed so only X remains so now if I say x and y's so now I have just set aggregated the input features and their corresponding levels
right X these are all X and Y this is our label water or nonwater and now I'm creating a variable called random state so that it produces the program produces same output all the time so now first in any machine Learning algorithm what we do so suppose we have training training data set that contains say say 100 samples right so this is a standard practice that out of 100 samples we use 70 samples for for training our model and the remaining 30 samples we can use for testing our model right so once the model is
trained on the 70 samples 70% or 70% if you can say 70% sample then you can say that the model was able to associate these input features to the corresponding output Output featur like on the 70% will be training and the rest 30% we can use it for testing because right now now we can how do we test our model for for remaining 30% data sets we already know that okay these are the input features and this is the corresponding output as well right now for whatever samples we have in the training data sets we
can give those input features as an input to our model and our model produces some output right And we know the actual output already so now by comparing the actual output and what the model has produced right so with that we can assess the performance our model how how well our performance how how well our model is doing on test data right so for this I am using the function right so this uh Trainor test split function is basically used for training and testing right bring sorry what do you call for breaking the entire Training
data set into train and test so so then it returns four parameters one we call X train X test y train and Y X is input features in training data set input features for test data set labels in training and labels in testing right so for this we need to pass these arguments X our input features what which we want to break into two classes two sets you can say train and test and their corresponding labels and random State we can Pass any number so that always we if you train and so this will split
in the split like if you pass the random State uh same value what happens do we will be getting the same same values in this x train and X test otherwise if you don't pass this random State a number so what will happen you might get different xtrain and EXT X test at the different runs of your program so that your program will not be repeatable right so if you want to do a repeatable or same Xtrain and excess then you need to pass it r State a fixed variable then train size is point8 so
here we are seeing that 80% 80% of the samples we are using for training and remaining 20% we are using for testing right so now if we count these values X train y train value. count and extend. values. count so we can say that in our training data set there are 44 water pixels and 396 non water pixel so The classes are balanced and in the testing data set we have 104 water pixels and 96 nonwater pixels now supp if you wish to see the statistics about this data that you can say that in the
training data set band two has 800 sample as we have seen so mean value are this this is the standard deviation across that then minimum and these are the different percentiles similar way suppose if you wish to specify the white train or describe that doesn't make much Sense 800 samples are there and because almost equal equal samples are there in X and right it's a similar way you can check y TR and describe and white as described as well now our next Target is we need to build a model right so in this section we
will try to build our model and train it using our data set so the hyper parameters now before building a parameter we need to specify different hyper parameters for that model so when Once you uh instantiate the model itself so there it will take some default hyper parameters but suppose if you wish to change those parameters that also while creating an object or object OB that uh while creating the model itself you can pass those hyper parameters as well right so some of the useful parameters to know about decision tree as like number of estimators
you can say Max feature like number of estimators actually in The random Forest case but now right now we are using decision tree so this number of estimators is not applicable to the decision tree so in case of decision Tre maybe like Max features Max feature maximum number of feature considered for splitting then max depth like for the as we have seen that while in the decision tree we build a tree right so we we can specify how maximum what what should the maximum depth of the tree minimum samples at which to Split minimum samples
for a leaf node the number of data points that allowed in a leaf mode then method of sampling the data points right so based on these parameters you can specify like this is you can first build a a dictionary called hyper parameters to that you can specify by these different hyper parameters if you don't specify that so while getting started so the default parameters might be good enough so once you see the performance of your Model is not doing well then later on you can uh manipulate these hyper parameters right so how do we build
a decision tree so as we have said decision tree we have imported as DT right DT then hyper parameters so if you don't pass this hyper parameters a default defa model will be created with the default hyper parameters right otherwise if you wish to specify these hyper parameters when we are starting you need not to specify These hyper parameters right so in psychic learn once we have uh created a model right now next we need to train our model on our training data sets for training the model the function is called fit right if you
call the fit function fit f function we need to specify your input features and the label because we are using a supervised classification algorithm so now you classifier do fit your input features and the Corresponding feature so in this fit method the model go gets trained so what what is training means it just learns how to associate these input band reflectances to their corresponding levels like we said that in training means it must be able to infer the rules now it must be like it must have internally derived using the cart algorithm it must have
derived the decision tree for for itself right we have not here we have not specifically Mentioned we have not framed the rules so the machine learning algorithm itself had frame the rules how to derive output from the particular set of input right now suppose if you wish to see the performance of our model on this training data set right then you can call this class our classifier do score and pass it your X test and Y test like the correct levels like we already know these are the X test and Y test right so for
the X test model will Produce some output and then it will compare them to the whest which are the true levels of that if you see the performance of the model we can say the average accuracy score is almost 100% so it may be you can say we might have very less number of samples or because of that or it maybe you can say that the model has overfit right once the model is trained we can use it for predicting new on the new data set right so now we because we have kept aside test
data set As well now if I call classify or my classifier do predict xcore X xor test if you pass it so it produces the text now if you if you just wish to see the classification report so then we can see that this is like this is the accuracy macro average and weighted average of these so Precision also is one recall also is one F1 score also is one so we can say that the model has done exceptionally well now suppose if you wish to build a Confusion Matrix from the output of our model
right so then we need to pass it and the true levels and what the model has predicted right now if I see run this confusion Matrix this is the confusion Matrix so here you can say that the for the for True level Z the model has predicted one Z four levels correctly as zero and for level one there were 96 samples or for all 96 levels it could produce correctly outputs like these are Z zos are Misclassification so it is not misclassified right so now let us if you want to see how does the tree
look like like or what kind of decision tree the model has made for that in decision tree there is a function called plot tree right or tree dotplot tree then you can pass it to this these argument like our classifier or model then what class names to or feature names sorry what are the names of feature actually we have Called them band One band two band Three band four so these are their corresponding bands like green red n and swi and what names to be used for these labels zero and one nonwater or water then
access then Feld is equal to true if you pass and PLT do show if you say so you can say that the model has build a tree like this like it it can say that if the N the value of n is less than equal to 922 so you can say the guinea value actually guine value is The you can say the guinea impurity so like if the number is less so it means the split is quite pure if the number is higher then see it is impure so we can say that if you how
do we interpret this graph n if n is less than 8 so there are totally 800 samples right so there are totally 800 samples out of that 8 800 samples 396 samples has n less than uh 39 uh 396 less than 92 and 404 totally there were three so 396 water has 39 396 has value less than 92 And 404 so this was the split and they have the water pixel now now this is the second condition if n is less than 92 and swi is 42 in that case so there are totally 399 samples
that were qualifying this area so in this we can say there were totally 800 samples as we have said so from 800 samples 396 samples has value less than 92 and 404 samples has value greater than 92 right so like you can say that the guine impurity was 50% so there were a 5050 samples classifying This area but these two condition nir less than 92 and swi less than 42 there were totally 392 samples only there were only 392 samples only in that class so in that out of these 392 samples 398 samples were from
the water class and one sample for nonwater class now with very high confidence now we can say that if n is greater than 92 and S also is less than 52 n sorry n is less than 92 and S also is less than 42 for The pixel then we with great confidence we can say that this is a water pixel because almost 395 samples are qualifying for this area and out of 395 all samples are there all all of these samples are water pixels so the gine Purity also is zero like this we can say
that n is less than 92 and swi is greater than 42 in that case if s is 42 then there in that case again we are seing for another thing called ifere is less than equal to 43.5 So there are four such samples so this is also mixed class if in that case now if we break up this now now now we can say what we can say n is greater than 42 and swi is also greater than 42 and swi is 4 greater than 42 and less than 43 43.5 then also we can then
with great confidence we can say that this is a nonwater pixel and same way like this so this is the decision Tre which our model has come out with right we have not told the Model these model so but based on the training dat we have just given it the training data on based on the training data it it itself has come up with this model for classifying the pixels based on their intensi values into the water and nonwater pixel right once a model is trained right now suppose now we now suppose if you wish
to see the performance of model say on a new satellite image right so here now we have four bands of TI Area of list three images right now now I'm just reading all these images I have already available in my folder band two band Three band four and band five images of my data set now with the loop I am reading all those images one by one and there data I am assigning in a list right now from that list I'm just here trying to build a data frame as we have seen in the training
data set so I'm just trying to build a training like so a data frame like this right so this Training dat data set so this entire image now I have converted to onedimensional array first I have converted all bands to one dimensional array now I have from these all one dimensional I have just tried to build a table like this right so this only table for this pixel values we want to predict what is the output level of that whether this is a what or non water pixel right so I have just build a data
frame like this and if I see the shape Of this one one 115 so my original image was of shape 11 cross 115 cross 115 anyway our model has already been trained on the training data now suppose if you want to predict for these four input images all to stacked together right so then now we can call the function called classifier do predict and pass it our data frame so it produces us the water map so if I see the water map it will be containing the levels one or zero right so now first Because
our inputs input was an image so now we need to unravel the mix back to the shape of one cross 1151 cross 1151 right so now I'm reshaping the water map to 1151 cross 1151 right now let us plot this map so right you can see say that this was our original image and our and class our model has produced these outputs right so some some may be false positive as well but to Great extent it was it is able to extract the water bodies with Very high good accuracy right so these are some these
may be some false positive or otherwise it has done quite nice job like this we can do machine learning for class like here we have not framed the rules ourselves for identifying the water body like if the N is less than 42 and S is less than 32 and some more somewhere like this we have not framed the rules we have just given the training data to our model and model itself has framed The rules right once the model has framed the rules now we we have used it for reaching the interference let suppose if
you wish to create write the output to a go file as we have discussed in the first lecture first or second lecture how do we create the files using uh Jal so that this is the same code for that so like driver first I'm creating a driver with GOP driver then actually so I'm using here create create Function because now my source file was having four bands but I now I just want to create a single image so I just create calling using I could have used driver. create as well but anyway I us here
create create and predicted path where I want to write the file the shape uh one one width and height of myage number of bands and because suppose if I want to store that at maybe 8 bit or 16bit integer Jal do gdt U n6 U or in8 can say U unsigned 16bit integer then options if you to compress ljw compression then I'm setting the projection of that get raster band one and in that WR aray water map right so if I do this the file will be saved as this so this is this is how
do we how can you use machine learning as for handling geospatial data so here we have just tried to train a model for doing a binary classification so similar idea You can extend for doing a multiclass classification as well right so actually I have here a land cover classification so I may not be able to explain it in detail so I will just go through the code and show you right now the output actually for similar thing I have just created a training data set and here we are using instead of uh decision tree we
will be using called random Forest right so now if I run go through this code one by one all these things we are doing Here so here this is a multiclass classification in this there are so 10 levels so confusion Matrix also you can see like this and suppose if you wish to make the classification we can see it like this so the steps are same for them as well only difference is now our training set data set is a bit different from the training data set which we have used there now if you see
the data here so the previous case there were Only two levels in our training data set now if you see in our training data set there are these many levels 1 2 3 4 5 6 7 8 or nine now there are multiple levels right not not single class not binary classes now there are multi classes all nine or 10 classes together so then other things are same only instead of random tree Rand sorry decision tree now we have used this the random forest classifier and if I see the map app so Like this here
you can say this was our original input image and though output may not be so correct so we need to do some further processing on that to some great extent you can say that this is the classified output map right so one advantage of uh decision tree or Rod random Forest is that you get to know about the importance of features also right suppose actually we have given these features to our input image like swi s 1 S 2 N blue green and red so you can see that the relative featur nature importance is given
though spere one has the highest uh importance for classification right so the so even suppose if you wish to do make it computationally more less computationally less expensive then even we can drop the feat less important feature also for doing classification right so with that we come to the end of uh this lecture if You have any questions please post them on the chat box we'll try to answer them so we will be back after 5 minutes so thank you very much