0:04 welcome to artificial intelligence
0:06 tutorial my name is richard kirschner
0:09 i'm with the simply learn team that's
0:11 www.simplylearn.com
0:14 get certified and get ahead what's in it
0:17 for you today what is artificial
0:19 intelligence so we'll start with a
0:21 general concept types of artificial
0:23 intelligence covering the four main
0:25 areas ways of achieving artificial
0:28 intelligence and some general
0:30 applications of artificial intelligence
0:32 in today's world finally we'll dive into
0:34 a use case predicting if a person has
0:37 diabetes or not and we'll be using
0:39 tensorflow for that in the python
0:42 environment what is artificial
0:44 intelligence and today's world is
0:46 probably one of the most exciting
0:47 advancements that we're in the middle of
0:49 experiencing as humans so what is
0:52 artificial intelligence and here we have
0:54 a robot with nice little clampy hands
0:56 hey what am i you are what we call
0:58 artificial intelligence i am your
1:01 creator reminding him who programmed him
1:03 and who he's supposed to take care of
1:05 artificial intelligence is a branch of
1:07 computer science dedicated to creating
1:10 intelligent machines that work and react
1:12 like humans in today's place where we're
1:15 at with artificial intelligence i really
1:17 want to highlight the fact that they
1:19 work and react like humans because that
1:22 is where the development of artificial
1:23 intelligence is and that's what we're
1:24 comparing it to is how it looks like
1:27 next to a human thanks any tasks you
1:29 want me to do for you get me a cup of
1:31 coffee poof here you go he brings him a
1:33 cup of coffee that's my kind of robot i
1:36 love my coffee in the morning you'll see
1:37 there's kind of a side theme of coffee
1:39 today's tutorial so here we have a robot
1:41 that's able to bring him a cup of coffee
1:43 seems pretty far out there you know that
1:45 we have a walking robot that's doing
1:47 this but it's not as far out there as
1:48 you think we have automatic coffee pots
1:51 we have devices that can move an object
1:53 from one point to the other you know
1:55 anything from amazon delivering packages
1:57 or whatever you want all these things
1:59 are in today's world we're right on the
2:01 edge of all this that's what makes this
2:03 so exciting such an exciting topic and a
2:06 place of study so let's take a look a
2:08 real general look at types of artificial
2:10 intelligence in the really big picture i
2:13 mean we drill into it there's like
2:14 machine learning and all kinds of
2:16 different aspects but just a generic
2:18 level of artificial intelligence so hi
2:22 there discovered four different types
2:24 come have a look so we have our kind of
2:25 einstein looking guy or professor at
2:28 some college so the very first part that
2:31 we're really this is uh as reactive
2:33 machines they've been around a long time
2:35 this kind of ai are purely reactive and
2:37 do not hold the ability to form memories
2:40 or use past experiences to make
2:42 decisions these machines are designed to
2:44 do specific jobs remember i talked about
2:47 the programmable coffee maker that makes
2:49 coffee in the morning it doesn't
2:50 remember yesterday from tomorrow it runs
2:53 its program even going back to our
2:55 washing machines they have automatic
2:57 load balancers that have been around for
2:59 decades so reactive machines we program
3:02 to do certain tasks and they have no
3:05 memory but they're very functional then
3:07 we have limited memory this is kind of
3:10 right where we're at right now this kind
3:12 of ai uses past experience and the
3:14 present data to make a decision
3:16 self-driving cars are kind of limited
3:18 memory ai we bring up self-driving cars
3:21 because that's a big thing especially in
3:22 today's market they have all these
3:25 images that they brought in and videos
3:27 of what's gone on before and they use
3:29 that to teach the automatic car what to
3:32 do so it's based on a limited memory
3:34 limited memory means it's not evolving
3:36 new ideas they have to actually when
3:39 they need to make a change they have the
3:40 programming built on the memory but then
3:43 they have to make those changes outside
3:45 of that and then put the new setup in
3:47 there so it's continually reprogramming
3:48 itself theory of mind these ai machines
3:52 can socialize and understand human
3:54 emotions machines with such abilities
3:56 are yet to be developed of course that's
3:59 under debate there's a lot of places
4:00 that are working on the theory of mind
4:02 and having it be able to cognitively
4:04 understand somebody based on the
4:06 environment their
4:08 facial features all kinds of things and
4:11 evolve with them so their own they have
4:13 some kind of reflective ability to
4:15 evolve with that and finally
4:16 self-awareness this is the future of ai
4:19 these machines will be super intelligent
4:21 sentient and conscious so they'll be
4:23 able to react very much like a human
4:25 being although they'll have their own
4:26 flavor i'm sure achieving artificial
4:29 intelligence so how in today's world
4:31 right now are we going to achieve
4:33 artificial intelligence well the main
4:36 arena right now is machine learning
4:38 machine learning provides artificial
4:40 intelligence with the ability to learn
4:42 this is achieved by using algorithms to
4:44 discover patterns and generate insights
4:47 from the data they are exposed to and
4:49 here we have a computer as we get more
4:51 and more to the human realm of art and
4:53 official intelligence you see this guy
4:55 splits in two and he's inside his hidden
4:57 networks and machine learning programs
4:59 deep learning which is a subcategory of
5:02 machine learning deep learning provides
5:04 artificial intelligence the ability to
5:06 mimic a human brain's neural network it
5:09 can make sense of patterns noise and
5:11 sources of confusion in the data let's
5:14 try to segregate different kinds of
5:16 photos using deep learning so first we
5:18 have our pile of photographs much more
5:20 organized than my boxes in my closet of
5:22 photographs the machine goes through the
5:24 features of every photo to distinguish
5:26 them this is called feature extraction
5:28 bingo figures out the different features
5:31 in the photos and so based on those
5:33 different features labels of photos it
5:35 says these are landscapes these are
5:36 portraits these are others so it
5:38 separates them in there if you've ever
5:40 been on google photos a favorite of mine
5:43 i go through there and i type in dog and
5:45 i get all the images of my dog it's
5:47 pretty amazing how it's able to pull
5:48 those features out so when we're
5:50 achieving artificial intelligence and
5:52 the deep learning let's take a closer
5:53 look and see just how deep learning
5:55 works there are a lot of models out
5:58 there this is the most basic model used
6:01 this is a neural network there are three
6:03 main layers in a neural network the
6:05 photos that we want to segregate go into
6:07 the input layer and so we have a picture
6:09 of mona lisa it looks like in a couple
6:11 of people when it goes into the first
6:14 input layer the arrows are drawn to like
6:16 individual dots each one of those white
6:18 dots in the yellow layer or in the input
6:20 layer would be a pixel in the picture
6:22 maybe a value for that pixel so the
6:25 picture of the mountains goes in there
6:27 and it fills in that whole input layer
6:30 and then the next picture of the
6:31 nightscape goes in there the hidden
6:33 layers are responsible for all the
6:34 mathematical computations or feature
6:37 extraction on our inputs so when you see
6:39 here we have the two uh kind of orangish
6:41 red layers here and there's all these
6:43 lines in there those lines are the
6:46 weights each one of those represents a
6:49 usually a float number or a decimal
6:52 number and then it multiplies it by the
6:54 value in the input layer and you'll see
6:56 that as it adds all these up in the
6:58 hidden layer each one of those dots in
7:01 the hidden layer then has a value based
7:03 on the sum of the weights and then it
7:04 takes those and puts it into another
7:06 hidden layer and you might ask well why
7:08 do we have multiple hidden layers well
7:10 the hidden layers function as different
7:12 alternatives to some degree so the more
7:14 hidden layers you have the more complex
7:16 the data that goes in and what can they
7:18 can produce coming out the accuracy of
7:20 the predicted output generally depends
7:23 on the number of hidden layers we have
7:25 so there we go the accuracy is based on
7:27 how many hidden layers we have and again
7:28 it has to do with how complex the data
7:30 is going in the output layer gives us
7:33 the segregated photos so once it adds up
7:36 all these weights and you'll see there's
7:38 weights also going into the output layer
7:40 based on those weights it'll say yes
7:42 it's a portrait no it's a portrait yes
7:44 it's a landscape no it's a landscape and
7:46 that's how we get our setup in there so
7:48 now we were able to label our photos
7:51 let's take a look and see what that
7:52 looks like in another domain we have
7:54 photograph domain now let's look at it
7:56 in the airline ticket so let's predict
7:59 the airline ticket prices using machine
8:02 learning these are the factors based on
8:03 which we're going to make the
8:04 predictions and choosing your factors is
8:07 so important but for right here we'll
8:09 just go ahead and take a look what we
8:10 got we have airlines we have the origin
8:13 airport the destination airport the
8:15 departure date here are some historical
8:17 data of ticket prices to train the
8:19 machine so we pull in the old data this
8:22 is what's happened over the years now
8:24 that our machine is trained let's give
8:25 it new data for which it will predict
8:27 the prices and if you remember from our
8:30 four different kinds of machines we have
8:32 machines with memory well this is the
8:33 memory part it remembers all the old
8:35 data and then it compares what you put
8:37 in to produce the new data to predict
8:39 the new prices the price is 1 000 that's
8:43 an expensive flight of course
8:45 if that is a us dollars if it's india i
8:48 don't know what the price range is on
8:49 that hopefully it's a good deal for
8:50 wherever you're going so we predict the
8:52 prices and this is kind of nice because
8:53 if you're looking way ahead it'd be nice
8:55 to know if you're planning a trip for
8:56 next year
8:58 how much those tickets are going to cost
8:59 and they certainly fluctuate a lot so
9:02 let's take a look at the applications of
9:04 artificial intelligence we're going to
9:07 dive just a little deeper because we
9:08 talked about photos we've talked about
9:10 airline ticket prices kind of very
9:13 specific you get one specific number but
9:15 let's look at some more things that are
9:17 probably more in-home more common right
9:19 now speaking of home this young
9:22 gentleman is entering his room of course
9:24 makes a comment like we all do we walk
9:25 into a room this room is dark isn't it
9:28 let's see what happens when i enter it
9:30 the sensors in my room detect my
9:32 presence and switch on the lights
9:34 this is an example of non-memory
9:37 machines okay you know it senses you it
9:39 doesn't have a memory whether you've
9:40 gone in or not some of the new models
9:42 start running a prediction as to whether
9:44 you're in the room or not when you show
9:46 up when you don't so they turn things on
9:48 before you come down the stairs in the
9:50 morning especially if you're trying to
9:52 save energy you might have one of those
9:54 fancy thermostats which starts guessing
9:57 when you get up in the morning so it
9:58 doesn't start the heater until it knows
10:00 you're going to get up so here he comes
10:02 in here and this is one of the examples
10:03 of smart machine and that is one of the
10:06 many applications of artificial
10:07 intelligence one of the things we're
10:09 developing here in our homes okay bye
10:12 abruptly he leaves leaving his nice
10:14 steaming cup of coffee there on the
10:16 table and when he leaves the sensors
10:18 detect he's gone and turn off the lights
10:20 let's watch some tv did someone say tv
10:24 the sound sensors on the tv detect my
10:26 voice and turn on the tv sounds kind of
10:29 strange but with the google dongle and a
10:32 google home mini you can actually do
10:34 just that you can ask it to play a movie
10:36 downstairs on your downstairs tv true
10:39 also with the amazon fire stick and all
10:41 the different artificial intelligent
10:43 home appliances that are coming out
10:45 pretty amazing time to be alive and in
10:48 this industry here you have one more
10:50 application of artificial intelligence
10:52 and you can probably think of dozens of
10:54 others that are right now on the cutting
10:56 edge of development so let's jump into
10:58 my favorite part which is a use case
11:01 predict if a person has diabetes and in
11:04 the medical domain i mean if you read
11:05 any of these they say predictive a
11:07 person has diabetes but in the medical
11:09 domain we would want to restate this as
11:11 what is the risk is a person a high risk
11:14 of diabetes should just be something on
11:16 their radar to be looking out for and
11:18 we'll be helping out with the use case
11:20 there we are with a cup of coffee again
11:22 i forgot to shave as you can see we'll
11:24 start with the problem statement the
11:26 problem statement is to predict if a
11:27 person has diabetes or not and we might
11:30 start with this prediction statement but
11:31 if you were actually using this in a
11:33 real case again you would say your
11:35 higher risk of diabetes would be the
11:37 proper way to present that to somebody
11:39 if you ran their test data through here
11:40 but that's very domain specific which is
11:42 outside of the problem statement as far
11:45 as the computer programmers involved so
11:47 we have a look at the features these are
11:49 the things that have been recorded and
11:50 they already have this data from the
11:52 hospitals one of them would be number of
11:54 times pregnant obviously if you're a guy
11:56 that would be zero glucose concentration
11:58 so these are people who've had their
12:00 glucose measured blood pressure age age
12:03 is a big factor an easy thing to look at
12:06 insulin level so if someone's on insulin
12:08 they probably have diabetes otherwise
12:10 they wouldn't be taking insulin but that
12:11 would affect everything else and we add
12:13 that in there if they're if they're
12:14 using insulin let's start off with the
12:16 code so we're going to start off by
12:18 importing parts of our data set and if
12:21 we're going to do this let's jump into
12:23 one of our favorite tools we're going to
12:25 use the anaconda jupiter notebook so let
12:28 me flip over there and we'll talk just
12:30 briefly about that and then we'll look
12:32 over this code so here we are in the
12:34 jupiter notebook and
12:36 this is an inline editor which is just
12:39 really cool for messing with python on
12:41 the fly you can do demos in it it's very
12:44 visual you can add pieces of code it has
12:46 cells so you can run each cell
12:48 individually you can delete them but you
12:50 can tell the cell to be a comment so
12:53 that instead of running it it just skips
12:54 over it there's all kinds of cool things
12:56 you can do with jupyter notebook we're
12:58 not going to go into that we're actually
12:59 going to go with the tensorflow and you
13:01 do have to import all the different
13:02 modules in your python now if you're in
13:04 a different python ide that's fine it'll
13:07 work in just about any of your python
13:08 ides and i'll point out the one
13:10 difference in code when we get to that
13:12 which is the inline for doing our graph
13:14 and in this code we're going to go
13:16 through we're going to load our data up
13:18 we're going to explore it we're going to
13:20 label it and then we'll use the
13:21 tensorflow and then we'll get down to
13:23 the end where we're going to take a look
13:25 at how good the model is does it work so
13:28 let's start with the top part here and
13:30 let me go ahead and let's paste that
13:31 code in there i've added a line in at
13:33 the top i've added the folder because i
13:35 didn't put it in the same folder as the
13:38 program that's running you don't need to
13:40 worry too much about that but if you
13:41 have a folder issue or says file doesn't
13:43 exist you probably have it in the wrong
13:44 folder or you need to add the folder
13:46 path and then we're going to import
13:48 pandas and let me just one of the cool
13:50 things since it's in internet chrome we
13:53 can just do that control plus and zoom
13:55 right in there and we have the import
13:57 pandas as pd so go ahead and draw a line
14:00 of there you can see that the pandas as
14:02 pd add a little drawing thing in there
14:04 to make it easier to see pandas is a
14:06 data set it's a really nice package you
14:09 can add into your python usually it's
14:11 done as pandas as pd that's very common
14:13 to see the pd here let's circle that
14:15 it's basically like an excel spreadsheet
14:17 it adds columns it adds headers it adds
14:20 a lot of functionality to look at your
14:22 data and the first thing we're going to
14:23 do with that is we're going to come down
14:25 here and we're going to read and this is
14:27 a csv it's a csv file you can open up
14:29 the file on your computer if you want if
14:31 you need access to the file you can
14:33 either search it and download it from
14:35 the main thing or type a note in down
14:37 below on the youtube video and simply
14:39 learn will help you get that file also
14:41 and that's true of any questions you
14:42 have on this you can add comments down
14:44 there and somebody at simplylearn
14:46 actually keeps an eye on that and we'll
14:47 try to answer those questions for you i
14:49 put in the full path you don't have to
14:51 if you have your data files saved in the
14:53 same folder you're running your program
14:54 in and this is just a csv file comma
14:57 separated variables and with the pandas
14:59 we can read it in there and we're going
15:00 to give it put it right in a variable
15:02 called diabetes and then finally we take
15:05 diabetes and you'll see diabetes.head
15:08 this is a pandas command and it's really
15:10 nice because it just displays the data
15:12 for us let me go ahead and erase that
15:14 and so we go up to the run button up
15:16 here in our jupyter notebook which runs
15:18 the script in this that's a cell we're
15:20 in and you can see with thediabetes.head
15:23 since it's a pandas data frame it prints
15:26 everything out nice and neat for us this
15:28 is really great and if i go ahead and do
15:30 a control minus i can get it all to fit
15:31 on the same screen and this is the first
15:34 five lines when you do the head of the
15:35 data just prints out the first five
15:37 lines in programming of course we start
15:39 with zero so we have zero one two three
15:42 and four there we go we have yeah here
15:43 we go we start with zero we have zero
15:45 one two three and four we have our
15:47 titles going across the top and of
15:49 course the first column is number of
15:51 pregnancies glucose concentration
15:54 for the second one blood pressure
15:56 measurements of triceps as we keep going
15:58 you'll see you can guess what most of
16:00 these things are group i'm not sure this
16:03 is probably the test group i didn't look
16:05 it up to see specifically what that is
16:06 anytime you start exploring data and for
16:09 this example we don't really need to get
16:11 too much in detail you want to know the
16:13 domain what does this information mean
16:15 are we duplicating information going in
16:18 that's beyond the scope of this for
16:20 right now though we're just going to
16:21 look at this data and we're going to
16:22 take apart the different pieces of this
16:24 data so let's jump in there and take a
16:26 look at what the next set of code is so
16:29 in our next setup or our next step we
16:31 got to start looking at cleaning the
16:33 data we got to start looking at these
16:34 different columns and how are we going
16:36 to bring them in which columns are what
16:38 i'm going to jump ahead a little bit and
16:40 also as we look at the columns we're
16:42 going to do our import our tensorflow as
16:45 tf that's a common import that's our
16:47 tensorflow model tensorflow was
16:50 developed by google and then they put it
16:52 into open source so that it's free for
16:53 everybody to use which is always a nice
16:55 thing so let's take a look at what these
16:57 two steps look like in our jupiter
16:59 notebook so let's paste this code in
17:01 here and this is something that happens
17:03 when you're messing with data is you'll
17:06 repeat yourself numerous times we
17:08 already have diabetes head so i'm going
17:10 to put the little pound sign which tells
17:12 python that this is just going to be a
17:13 comment we're not going to run it a
17:15 second time in here we have diabetes dot
17:18 columns and then diabetes columns to
17:20 norm equals diabetes columns to
17:22 norm.apply lambda x let's talk about
17:25 that but let me first run that and let's
17:28 see that comes out with that and then
17:31 let's put the next set of code in also
17:33 and i'm going to run that let me just
17:35 hit the run button it doesn't really
17:37 have an output but we did a lot of stuff
17:39 here so let's go over what we did on
17:41 this so i've turned on my drawing
17:43 implement to help go through all this
17:45 there's a lot going on here the first
17:47 thing is we have all of our columns up
17:50 here all of our column names let me just
17:52 highlight that and draw a circle around
17:53 that like we did earlier and we want to
17:55 look at just specific columns and we're
17:58 going to start let me change the color
18:00 on this so it really sticks out i'll use
18:03 like a blue i'm going to look at these
18:06 columns and we're not going to do age
18:08 class or group we're going to look at
18:10 those in a different way and i'll
18:12 explain in a little bit what that's
18:13 about so we're looking at number of
18:15 pregnancies
18:17 uh glu basically anything that can be
18:19 read as a float number and you might say
18:22 age could be read as a float number
18:24 we're going to address that differently
18:25 because when you're doing statistics we
18:28 usually take the ages and we group them
18:30 into buckets and we'll talk about that
18:32 and so we're going to take these columns
18:34 and we're going to do what they call
18:36 normalize them call them to normalize
18:38 what is normalize if you're using the sk
18:41 learn module one of their neural
18:42 networks they call it scaling or scalar
18:45 this is in all of these neural networks
18:47 what happens is if i have two pieces of
18:50 data and let's say
18:52 one of them is in this case zero to six
18:55 and one of them is in insulin level is
19:00 zero to maybe point two would be a very
19:02 high level i don't know what they
19:03 actually go to a neural network we'll
19:05 look at this six and it'll go zero to
19:07 six and as you get into zero six here's
19:10 an eight even a higher number it will
19:12 weight those heavier and so it'll skew
19:14 the results based more on the number of
19:16 pregnancies than based on the insulin or
19:19 based on the blood pressure so we want
19:21 to level the playing field we want these
19:24 values to all be in the same area we do
19:26 that by normalizing it here and we use a
19:29 lambda function this is always a kind of
19:30 a fun thing we take the diabetes it's a
19:33 panda set up and let me just erase all
19:35 that so we can go down here put it back
19:37 to red and we take our diabetes which is
19:40 a panda data set and we only want to
19:42 look at the columns to normalize because
19:45 that's what we built we built a list of
19:46 those columns and we're going to apply
19:49 a lambda function and you'll see lambda
19:51 and all kinds of python programming it
19:53 just means it's a function we put x in
19:56 and whatever is outside of the x over
19:59 here it then takes that and returns that
20:02 value so
20:03 the new value is going to be whatever x
20:06 is minus x min again it's a panda's data
20:09 set so we can get by with that which is
20:10 really cool makes it easy to read so we
20:12 take x we look for the minimum value of
20:14 x and then we divide that by the maximum
20:17 value x minus the x min or the width and
20:20 what this essentially does is if you're
20:23 going from 0
20:25 to 15
20:27 it's going to divide by 15 and then we
20:29 subtract it let's make this 2 instead of
20:31 0 or 2 20 to 115 there we go first off
20:34 we set this to zero so we subtract x min
20:37 so right off the bat the minimal value
20:40 is going to be zero and then we divide
20:43 it by the difference here x min minus x
20:45 max or x max minus x min this basically
20:48 sets all the values between zero to one
20:51 and that's very important if we want to
20:54 make sure that it's not going to be a
20:55 skew in the results if it's not going to
20:57 weight the values one direction or the
20:58 other zero to one that's what this is
21:01 doing and again there's like so many
21:02 different ways to scale our data this is
21:04 the most basic scale it's standard
21:06 scaling and it's the most common and we
21:09 spelled it out in the lambda you can
21:10 there's actual um modules that do that
21:12 uh but lambda is just it's such an easy
21:14 thing to do and you can see really see
21:17 what we're doing here so now we've taken
21:19 these columns we've scaled them all and
21:21 changed them to a zero to one value we
21:23 now need to let the program know the
21:25 tensorflow model that we're going to
21:27 create we need to let it know what these
21:29 things are so to do that i create a
21:32 variable called number pregnancy keep it
21:34 simple and we've imported the tensorflow
21:37 as tf one line of code brings our
21:39 tensorflow in for us awesome love python
21:42 so you get number of pregnancies in
21:44 tf.feature column.numeric column we're
21:47 going to tell it's a numeric column so
21:48 it knows that this is a float value zero
21:50 to one and then number underscore
21:52 pregnant so we're taking that column and
21:54 we've reshaped that column from zero to
21:56 one and no that doesn't mean you have a
21:58 point one pregnancy it just means zero
22:00 point one equals one or something number
22:02 pregnant so we're just mapping this data
22:04 so tensorflow knows what to do with it
22:06 and we go through all of these we go
22:07 through all the way up to again we're
22:10 not doing age let me just separate h
22:12 down here these have all been adjusted
22:15 age we're going to handle differently we
22:17 still put it as a numerical column
22:18 because it is so let me just circle age
22:21 and group we didn't even touch group yet
22:23 we're going to look at group and h and
22:25 we're going to do some special stuff
22:26 with that class we're going to look at
22:28 last why because this is whether they
22:31 have diabetes or not that's what we're
22:33 testing for so this is our history we
22:35 know these people have diabetes or not
22:36 and we want to find out we want to
22:38 create a model and then we want to test
22:40 that model predicting whether somebody
22:41 new has diabetes or not so here i am
22:44 still with my cup of coffee working away
22:46 refill number three let's explore both
22:50 the categorical group which is going to
22:52 be the b c and d on the end and also the
22:56 age we're going to talk about those a
22:58 little bit more and then we're going to
23:00 combine all those features and we'll
23:02 jump into splitting the data although
23:04 that's kind of the next step but we'll
23:05 put that all together what are we doing
23:07 with the age and what are we doing with
23:09 the group down there so let's flip on
23:12 over and take a look at our
23:14 jupiter notebook so the first thing is
23:16 let's put this new set of code in here
23:18 and run it and let's talk about what
23:20 we're doing on this set of code in i
23:22 actually want to go one more step
23:23 forward on the next set of code or part
23:25 of it there we go and i can go and just
23:27 run that while we have it that's fine
23:29 let's just scroll up a little bit here
23:31 and let's go through what we just did
23:33 with this set of code if we go back up
23:35 here to the top part we have group b c b
23:39 b c we learned from the header so when i
23:41 come down here we're going to create a
23:43 signed group and let me get my drawing
23:45 pad out so we're looking at this first
23:47 one up here assigned group tf feature
23:50 column categorical column with
23:52 vocabulary list that is a mouthful this
23:56 is saying that this is a categorical
23:58 list in this case we have a b c d you
24:00 see this a lot in tensorflow a lot of
24:03 times tensorflow is used to analyze text
24:05 or logs error logs and they're just full
24:08 of all this information and they take
24:10 these in this case a b c d but in other
24:13 cases it'd be words and they create
24:15 numbers out of them so it has 0 this is
24:17 one column this is another column this
24:19 is another column this is another column
24:21 and it's just this way of being able to
24:23 look at this in a different light and
24:24 assigning them different values you
24:26 really don't want to assign this a float
24:28 value first thought might be let's
24:30 assign this 0 to 3 0 1 2 3 for a b c d
24:34 but if you did that it would try to add
24:37 1 plus 2 to get 3 as part of its math
24:40 and functions and that just isn't true c
24:43 does not equal a plus b c is just a
24:45 categorical name it could have been the
24:47 frank group and laura's group in a bids
24:50 group but it's not you know these are
24:52 they're not float numbers so very
24:54 important you have that distinction in
24:55 your data the next step we're looking at
24:57 is our map plot and we're going to do
24:59 this
25:00 this is a cool useful tool we're going
25:02 to import matplotlibrary.pi
25:05 plot as plt that's standard import and
25:07 this next line here is really important
25:10 we're doing the matplot library we want
25:12 it to be inline that's because we're in
25:14 a jupyter notebook remember i told you
25:15 before that if you're running this in a
25:17 different ide you might get a different
25:18 result
25:19 this is the line you need if you want to
25:21 see the graph on this page and then we
25:23 do diabetes we're going to look at just
25:25 the age and dot hist bins equals 20.
25:30 what the heck is that well it turns out
25:32 that because this is remember it's a
25:33 pandas there's our pd pandas as pd
25:36 because this is a pandas panda
25:38 automatically knows to look for the
25:40 matplot library and a hist just means
25:42 it's going to be a histogram and we're
25:44 going to separate it into 20 bins and
25:46 that's what this graph is here so when i
25:48 take the diabetes and i do a histogram
25:50 of it it produces this really nice graph
25:52 we can see that
25:54 at 22 most of the participants in this
25:57 probably around
25:58 174 of the people that were
26:01 recorded were of this age bracket
26:03 they're right here in this this first
26:05 column here and as they get further and
26:07 further down they have less and less and
26:10 less until when you're at 80 you can
26:12 actually see down here there's almost
26:13 none in a couple of these categories and
26:15 this is important to know because when
26:16 you're doing census you know the older
26:18 the the group is the more the people
26:20 have passed away so you're going to have
26:22 this in any of your senses as you take
26:24 you're always going to have a much
26:25 larger group in the younger crowd and
26:27 then it gets lower and lower as they get
26:29 older and i mentioned the word buckets
26:31 here we go we're going to create an age
26:32 bucket we're going to put people in
26:34 buckets can you imagine people sitting
26:36 in buckets kind of a funny way of
26:37 looking at it this just makes it easier
26:40 for us to separate it when i go to the
26:41 doctor's office i don't want to be told
26:44 well your age 22 this is you know you'll
26:46 get a decent one at 22.
26:50 here we are back to my cup of coffee i
26:52 told you coffee was an underlying theme
26:54 these next couple steps are very
26:57 specific to tensorflow up until now we
27:00 had some tensorflow as we set the
27:02 categories up but you'd have to set that
27:04 up with any model you use to make sure
27:06 they're set correctly they'd be set up a
27:07 little differently but we run input
27:09 functions and in tensorflow this allows
27:12 for some really cool things to happen
27:14 and this is why tensorflow is so
27:16 predominant in a lot of areas so let's
27:18 take a look at these next couple lines
27:20 of code here we're going to create the
27:22 input function and we're going to go
27:23 ahead and create the model and let me go
27:26 ahead and put these codes in here i went
27:28 ahead and split it up so it's different
27:29 lines so we can talk a little bit about
27:31 that and then the actual model and let
27:33 me go ahead and run this so we can see
27:36 what that looks like and in my
27:37 particular environment it just prints
27:39 out a little bit of information about
27:41 the model not too worried about looking
27:43 at that but we do want to take a closer
27:44 look at what we did here so we've
27:46 created an input function and again this
27:49 is very specific to tensorflow with the
27:51 input function we have our train we have
27:54 our x equals x train and our y equals y
27:57 train because we want to train it with a
27:58 particular information but we have these
28:00 other settings in here these two
28:02 settings and the number of epics is how
28:05 many times it's going to go over our
28:07 training model epic means large that
28:08 means all the data so we're going to go
28:10 over it a thousand times that's actually
28:11 a huge overkill for this amount of data
28:14 usually it only needs probably about 200
28:16 but you know when we're putting it
28:17 together and you're trying things out
28:18 you just kind of throw the numbers in
28:19 there and then you go back and fine-tune
28:21 it sometimes the batch size is really
28:24 important this is where tensorflow does
28:26 some really cool things if you're
28:28 processing this over a huge amount of
28:30 data and you try to batch everything at
28:32 once you end up with a problem this
28:34 means we're only going to read 10 lines
28:35 at a time through our data so each one
28:37 of those rows of testing they've done
28:39 we're only going to look at 10 of them
28:40 at a time and put that through our model
28:42 and train it and then shuffle
28:44 self-explanatory we're just moving we're
28:45 just randomly selecting which data and
28:47 what order we go in that way if there's
28:49 like you know five in a row that are
28:50 kind of weighted one way and vice versa
28:52 it mixes them up and then finally we
28:54 create our model so the model goes in
28:57 there and goes okay i have a
28:58 tf.estimator.linearclassifier
29:01 we're going to put in the feature
29:02 columns equals feature columns we
29:04 defined all our columns up above and
29:06 then we have in classes equal 2 and that
29:08 just means we have our out result is
29:11 zero or one you have diabetes or you
29:13 don't have diabetes or in this case we
29:15 actually call it high risk of diabetes
29:17 and then i put one more line of code in
29:19 there which i forgot we've set up our
29:21 model we set up our feature columns now
29:24 we need to actually train it model.train
29:27 you'll see this
29:28 so common in so many different neural
29:31 network models this is like a standard
29:33 what's different though is we have to
29:34 feed it the function remember we created
29:36 this function with all this information
29:38 on it and then we have steps in uh steps
29:42 similar to number of batches and batch
29:44 size it's more like a individual lines
29:47 we step through a thousand is a lot more
29:49 common for steps than epics but steps is
29:51 used you probably leave this out in this
29:53 particular example and let's go ahead
29:55 and run this all together because it has
29:57 a site when we start training it we get
29:59 a different output so here we go i've
30:01 run it it's given me the information
30:03 from when i created the model and now it
30:05 just starts going through and we get
30:07 this information tensor loss equals
30:09 global step all kinds of stuff going on
30:11 here and if you're following this it's
30:14 just going through the steps and
30:15 training it it gives you information you
30:17 could dig deep into here but for this
30:19 particular setup we're not going to go
30:21 too deep on what's going on just know
30:22 that we've trained our model this model
30:24 now has the information we need in it to
30:26 start running predictions so as we sip
30:29 our next um take our next step of coffee
30:31 or maybe it's tea or
30:33 if you're one of those strange late
30:34 night workers maybe it's a sip of wine
30:36 we go into the next step and we actually
30:38 want to run some predictions on here but
30:40 we don't want to run the training we
30:42 want to run the test on there we want to
30:44 take our test data and see what it did
30:46 and so that's what we're going to do
30:47 next is we're going to run the test
30:48 through and actually get some answers so
30:50 if you were actually deploying it you
30:52 would pull the answers out of the data
30:53 it's bringing back let's take a look at
30:55 that in our jupyter notebook so here we
30:57 go let's paste it in there i'm going to
30:59 go ahead and run it and you'll see that
31:01 as it goes it's actually putting the
31:03 answers out if you remember correctly
31:05 well we'll walk through this here in
31:06 just a second but it goes through and it
31:08 runs each line and it gives you a
31:09 prediction for each line one at a time
31:11 and prints them out so let's take a look
31:12 and see what that actually looks like
31:14 let's start with this first part we've
31:16 created another function this is just
31:18 like the other function except for
31:21 x equals x test and there's no y why is
31:24 there no y because we don't know what
31:27 the answer is on this yet we don't want
31:29 to tell it the answer we wanted to guess
31:32 what the answer is so we can evaluate
31:34 that and see how good it did on that 33
31:36 percent of the data so this is our x
31:38 test batch size is 10 again so if we
31:40 were watching this roll down here we
31:42 would see that it actually processes it
31:44 10 lines at a time it's only going to go
31:46 through once it goes through all the x
31:49 test data one time we don't need to have
31:51 it predict multiple times and shuffle
31:53 equals false
31:55 very important we set the shuffle to
31:56 false because if we were tracking this
31:58 and actually giving people answers we
32:00 want to make sure it connects to the
32:01 right person so they get the right
32:03 results of course we're just doing this
32:04 to evaluate it so let's take a look down
32:06 here what i put out and as i scroll down
32:09 to my jupiter notebook we have some
32:10 information as far as a tensorflow
32:12 running and then the actual output and
32:14 if we look at the output we know by this
32:16 first bracket in python it's an array we
32:19 know
32:20 by this squiggly bracket that this is a
32:23 dictionary so that this is a label the
32:25 dictionary has logistic probabilities
32:28 class ids classes and so this whole
32:30 first part let me redo that this whole
32:33 first part is one
32:35 output and we know that because there is
32:38 the bracket there and there is this
32:40 bracket here for the dictionary and it's
32:42 a dictionary of terms so if i pulled
32:44 this out and i looked at object 0 in
32:46 here i would go down to and let me just
32:48 find it here it is classes remember how
32:51 we define classes we define classes as
32:54 our answer and so it's guessing our
32:56 tensorflow says based on all the
32:58 information you gave me i'm guessing
32:59 this first entry of our first test data
33:02 is high risk diabetes uh oh go get
33:04 tested change your diet watch what
33:06 you're eating you know high risk one and
33:08 if we go down far enough we can see down
33:11 here is another one where classes equal
33:13 zero i skipped a couple because they're
33:15 all ones up here the b
33:16 this particular output b
33:19 in front of the one means it's a binary
33:21 output it only comes out as zero or one
33:24 and there's a lot of other information
33:26 in here you can dig deep into tensorflow
33:28 and explain these different numbers
33:30 that's way beyond the scope of what
33:32 we're working on today so the basics of
33:33 it though is you get an output and we
33:35 have an output of whether the person has
33:36 diabetes or not well in this case it's
33:38 high risk of diabetes or not so now that
33:41 we've run our predictions take a sip of
33:43 coffee a little short break and we say
33:44 well what do we need to do well we need
33:46 to know how good was our predictions we
33:48 need to evaluate our model so if you're
33:50 going to publish this to a company or
33:52 something like that they want to know
33:53 how good you did let's take a look at
33:55 what that looks like in the code so
33:56 let's paste that in here and
33:59 just real quick go back over this by now
34:02 this function should look very
34:05 this is we're going to call it eval
34:06 input function it should be pretty
34:07 straightforward here we have our tf
34:09 estimator inputs pandas input function
34:12 and then we have our x test our y test
34:16 because we this time we want to give it
34:17 the answer so it has something to see
34:20 how good it did on batch is 10
34:21 processing 10 at a time we're only going
34:24 once through the data we're not
34:25 shuffling it although it doesn't really
34:27 matter with this and then we're going to
34:28 do results equals
34:31 model.evaluate and we put our evaluation
34:34 function in there this should all look
34:35 familiar because we're repeating the
34:36 same thing it's very similar with a
34:38 couple different changes as far as what
34:39 we're feeding it and the fact that we're
34:41 doing an evaluation let's see what that
34:43 looks like when we run it and we go up
34:45 here to our run model you'll see
34:46 warnings on some of these because i
34:48 didn't install this on its own install
34:50 so a lot of it is just temporary files
34:52 because i'm using the jupyter notebook
34:53 instead of setting it up on a regular
34:55 machine and we get our output and we'll
34:57 go ahead and just look at this output
34:58 real quick and then we'll flip over and
35:00 from here you'll see that it generates
35:02 an accuracy a baseline average loss the
35:06 mean gives you a precision prediction it
35:09 gives you all kinds of information on
35:10 here so let's flip over and see what's
35:12 important and we'll look at the slide
35:14 here we are in this slide and this
35:16 should be exciting because we just about
35:17 wrapped up our whole tensor flow and
35:19 tensorflow is one of the more
35:21 complicated models out there so give
35:23 yourself a pat on the back for getting
35:25 all the way through this when we look at
35:26 this output we have an accuracy of
35:28 0.7165
35:30 that's really what we want to look at
35:32 that means that we have an accuracy if
35:34 you're just truncating it of 71 percent
35:37 that's quite good for our model you know
35:38 given a small amount of data we came up
35:40 with the 71 percent of letting people
35:43 know they're high risk or not with
35:44 diabetes so we created a model that can
35:46 predict if a person has diabetes based
35:49 on some previous records of people who
35:51 were diagnosed with diabetes and we've
35:53 managed to have an accuracy of 71
35:55 percent which is quite good the model
35:57 was implemented on python using
35:59 tensorflow again pat yourself on the
36:02 back because tensorflow is one of the
36:03 more complicated scripts out there it's
36:05 also one of the more diverse and useful
36:07 ones so the key takeaways today is we've
36:10 covered what is artificial intelligence
36:12 with our robot that brings us coffee and
36:14 we noted that we are comparing it to how
36:17 it reacts and looks like humans very
36:19 important to note that in today's world
36:21 where we're at and we looked at types of
36:23 artificial intelligence from the
36:24 reactive machines to limited memory and
36:27 looking into the future of theory of
36:29 mind and self awareness then we went in
36:32 there and took a look at taking photos
36:34 and how artificial machine learning work
36:37 we took a glance at deep learning with
36:40 our neural networks and how we have
36:41 hidden layers in our input layer and our
36:43 output layer we then looked at a use
36:45 case of somebody walking into a room and
36:47 activating their tv using artificial
36:49 intelligence or part of the ai category
36:51 and finally we dug in deep and we did
36:54 some coding in the tensorflow in python
36:56 with that let's wrap it up i'd like to
36:58 thank you for joining us today for more
37:01 information visit www.simplylearn.com
37:04 get certified get ahead again if you
37:06 have any questions or would like some
37:09 verifications or or more information
37:11 please feel free to add a note in the
37:13 youtube video comment section we look
37:16 forward to hearing from you and i wish
37:17 you a wonderful day
37:23 hi there if you like this video
37:24 subscribe to the simply learn youtube
37:26 channel and click here to watch similar
37:29 videos turn it up and get certified
37:31 click here