Hello everyone and welcome to the tensor flow of contrib learn lecture as we just saw the last few lectures
using tents or flow sessions can get to be very complicated very quickly and it requires a background
knowledge and the various steps of a deep learning process such as cost functions and optimization algorithms
in order to fully understand each step because of this the community develop a psychic learn interface
for tensor flow called S-K flow or psychic flow.
This developed branch became so popular that it's actually now officially part of tensor flow since
tensor flows open source and you can find that under the contrib section of tensor flow which stands
for contributions.
Let's go ahead and jump to a Jupiter notebook to show you how to use this interface.
I think you're really going to like it if you enjoyed sikat learn.
All right.
Here I am at the Jupiter note book where we're going to go ahead and do is start off with some data
to actually show you how to use this contrib learn interface since we're just focusing on how to use
this interface.
We're going to use data that we're already familiar with such as the iris data set.
We'll go ahead and say from mid-scale learn the data datasets import load and you can scroll down see
load Irus here and take out the Sprint CS and then we'll actually call Irus is equal to load ires close
parentheses so actually loads it.
And then if we just Chucko Iris's notice it's a centrally dictionary of description and there's actually
some keys in here that you can grab and we're going to go ahead and grab the data and the target.
So we're already familiar if this will just say Irus data is equal to x and y is equal to Irus target
.
Run that.
So if we check out why looks like it's just a bunch of zeros ones and twos for each species and if we
check the y type at the bottom it says right now integer 64 bit.
Let's go ahead and do a train test split on this will save from S-K learn da cross-validation in poor
train to split we'll do our train to split.
And like we always do we just say shift time to actually see if we scroll down here.
The little quick example that we can copy and paste.
Here it is.
Let's go it.
Copy that and we'll paste it in and we will get rid of some of the stuff we don't really need.
We'll set test size to 0.3 and we'll go out and just leave the random states the default.
Ok so now that was in the train test split ready to actually begin building our model.
Now we're going to build a model just like we would a normal sikat learned model and we're going to
say import sensor flow and I will say Dawk contrib.
Learn Python learn.
And the reason it's kind of doubled up here is because you have tensor flow the contributions tensor
flow.
This learning library.
And we specifically want the python learn version of the library and I to import this whole thing as
learn.
And now we're going to go ahead and do is create a classifier off of this so you can say learn dots
and click tab and you'll see a bunch of options here.
Now there's a DNN classifier a DNN linear combiner aggressor linear combine classifier.
There's other tensor flow basic either auto coder's classifiers regressors.
There's a bunch of different tensor flow models that are available to you here depending on what kind
of neural network we want to run.
But we want to run a deep neural network and we want to run a deep neural network classifier sung with
say D and an classifier and I will set my variable to be classified as equal to learn the DNN classifier
and if you click shift tab here it tells you that it has a couple of arguments you can pasan you can
actually pasand the optimizer and the activation function etc. but will go ahead and use that default
.
Previously we showed you how to kind of with the sessions method fill those all up or go ahead and say
learn TNN classifier and I will say hidden units.
Let's go underscore units is equal to.
And here I'm going to pasand a list of the actual hidden units I want in this case.
We're going to just say 10 20 10.
So those are essentially how many nodes per layer and then we just have to pass in the number of classes
.
So the number of classes equal to three.
So there there's our classifier.
And we're going to go ahead and just take that classifier and just like you would for sikat learn this
estimator object are going to say Dot fit and you're going to pass in the training data.
So if you use sikat learn it's going to feel super familiar.
And the other arguments are going to pasan is steps and batched size.
And here you can kind of play around with it see what works for you.
But we're go go go ahead and say steps is equal to 200.
And we'll say that batch size is equal to let's say 30 to you can kind of play around it isn't here
to fix your model but we're going to just leave it at that.
Now keep in mind this is a deep neural network classifier.
So even on this relatively small dataset it will take some time for fittings.
If you're trying to run this on a much larger dataset this will run but it will take quite a long time
.
So you may need to just walk away from your computer and go take your lunch break if you want.
All right.
So that's basically it.
As far as running the deep neural network now you have this deep neural network that you can play around
with.
Let's go ahead and say get some predictions off of this then I say Irus predictions prove the actions
is equal to.
And we will say classifier predicts it will say X test.
Let's go ahead and run that.
And if we check our ires predictions look like we can see we get an array of values that we predicted
.
So let's go ahead and use sikat learn to get the classification report from this we'll say from S-K
learn metrics import.
Actually the accuracy score what classification report.
There it is.
And let's also do the confusion matrix.
All right.
And then just like we've done earlier you can say Prince classification are poor and you passen the
test values as well as your predictions ires predictions.
All right.
And it looks like our deep neural networks didn't do too bad got around 90 percent precision 90 percent
recall.
You can go ahead and M.R. this more by adjusting these steps and the batch size as well as maybe putting
more hidden units so if you wanted to get this to 20 20 20 and let's go ahead and do maybe some more
steps and we'll keep it just go ahead and keep that size 3 so going to run these again see how that
affects our model.
Notice takes a little longer to fit.
Now since we're running more hit in units and we're going to go ahead to just run these all again and
see if anything's changed.
Right now we're at this old model something new and to just copy and paste this here for the new one
see if anything changes.
All right.
So looks like we were able to increase our accuracy a little bit.
So these are values you can play around with and see if your deep neural network improves.
But the main thing I want to get across is really just these important steps here.
Let me go ahead and copy the lines of code that are probably the most important ones.
And that's going to be these three lines of code the import tensor flowback Contra that learn that Python
learn.
It's a really long import statement but that's just the way it is as learned.
And now you can use all your sikat learn knowledge as far as syntax for creating a model with tensor
flow which is a pretty awesome tool to have at your disposal.
So just in three lines of code you can use tensor faling now to create a model and fit a model.
OK that's it.
You're going to be using this tensor float that contrabass learn for your project exercise since it's
so much easier to use than the previous session methods.
We've gone over it before you can go ahead and check out the tests for the documentation.
If you want to fit find out more about either using contrabass learn or the session methods has really
great documentation and it also has tons of examples for you.
Thanks everyone and I'll see you at the next lecture