Hello world, welcome to Sirajology! Ever wonder how Netflix recommends awesome shows you'd
like? Or how Facebook can auto-tag your face? Or how Google's self driving cars work? Or
how Bing can...whats that? You don't care what Bing does? It's ok nobody does. Anyways,
the answer is Machine Learning. Machine Learning is the study of algorithms that learn from
examples and experience instead of hard-coded rules. So let's say you want to build an app
that can recognize an image of a specific species of flower called Iris. If you decide
to code this without machine learning, you'd have to write a bunch of different functions
to detect all the different features of an Iris flower. The problem is, there are a bunch
of corner cases and there's NO WAY you could account for all of them ahead of time. Like
what if one of the leaves is partially obstructed or a flower is a certain color that you didn't
account for or the shape is totally different than what you expected. You can't just code
all that up before-hand! Unless you're Jeff Dean. Just kidding not even Jeff Dean can
do that, no one can. You have to use machine learning to solve this problem and here's
the best part -- it's actually super easy and you don't need to be a math person to
do it! There are just 4 steps involved in the process -- collect data, pick a model,
train the model, and test the model. We'll basically just add data to a model and it
will start to find patterns in the data FOR us. We're gonna make this iris flower recognition
app with just 7 lines of Python using two dope libraries; SciKit Learn and TensorFlow
which we'll import right at the start.
So let's do this. The first step is to get our data. Datasets come in all different kinds
of formats (PDFs, TXTs, CSVs, holograms) It doesn't matter the format, we can easily parse
it in our code to get the relevant details. We'll be using a well-known dataset that contains
150 samples of Iris flowers. Luckily for us, this dataset comes preloaded with SciKit learn
so we can just load it here. Each sample has a label, one of 3 types of Iris (setosa, virginica,
or versicolor) and a set of features (sepal length, sepal width, petal length, and petal
width). Because our data is labeled, the type of learning we're doing is called supervised
learning. If we didn't have labels for our data, just features, then it would be called
unsupervised learning.
So yeah, these are
good features -- they're simple, independent, and informative as all features should be.
By the way, if you're ever deciding on what kind of features you should look for in a
dataset, a good rule of thumb is thinking about what features you personally would need
to figure out to determine whatever your goal is. So if you're trying to determine jedi
or sith given a dataset of lightsabers, don't pick something like 'weapon status' as a feature.
Use blade colors and curvature as your features!
So now that we have our dataset, the next step is to pick the model. To do that, you
just have to calculate the multivariate equation for discriminant analysis by squaring the
delta of the...just kidding -- you literally just paste in a single line of code. The real
question is how do you know which of the bajillion machine learning models to use? Well, we're
trying to classify an image as either an iris flower or not an iris flower, so we know this
is a classification problem. Therefore, we'll need to use a classifi-er. Ok that narrows
our options, but what type? There are a lot of those too! My gut reaction is to use a
deep neural network because it just sounds dope you know what i mean? But there are countless
others! The answer is it depends. It depends on the size of your data and your application
requirements. Currently, if you have a LOT of data, deep neural networks pretty much
outperform every other machine learning model across a wide variety of use cases. but In
our case, we only have 150 samples so we'll use something simple and standard. A linear
classifier. we'll set the class parameter to 3. You can also easily just switch out
the model with another one and see the difference in accuracy. (It's just one line of code,
like thats all it would take to use a deep neural net to classify this) That way you'll
know which one works best.
Now that we've picked our model, its time to train it. Training is the actual learning
step, as your model iterates through the dataset, it gets better and better at prediction. Since
we're using a classifier we just need to call the fit method on our object to train our
model. Fit is our training algorithm, this method will input the training dataset into
our model find patterns in our data. Boom, done. Now, whenever we input a new flower
from our testing dataset, it'll automatically be able to classify it as one of the 3 types
of Iris flower. We can see in terminal that the accuracy score for classification is pretty
high. How easy was that? Just 7 lines of code and now you have your first model trained
and ready to recognize iris flowers! You just made a learning machine. And you can use this
same model to classify other things like cars, dresses, and republican candidates. Machine
learning can be applied to so many different things from fraud detection to generating
paintings like picasso. If you'd like to see more machine learning videos, please subscribe.
I'm going to release a lot of them. For now, I've gotta go fix a runtime error so thanks
for watching!