Machine Learning Foundations: Ep #1 - What is ML?

Google for Developers · Beginner ·📐 ML Fundamentals ·6y ago

Key Takeaways

Introduces machine learning fundamentals with TensorFlow

Full Transcript

Hi, and welcome to this series on machine learning foundations. It's a free training course where you'll learn the fundamentals of building machine learning models using TensorFlow. The only thing that you'll need to know is a little bit of Python. So, if you've tried to learn ML before and you were scared off by all the calculus and other math, well, this is the course for you. We'll start in this episode by talking about what machine learning actually is, as well as how it works. So, first of all, let's think a little bit about programming and what it looks like from a very high level. Perhaps you have to create some financial software where you write code that gets data and does something new with it. There's a popular analytic called a PE ratio, which is called price to earnings. So, code for that would look a little bit like this. But, please think in terms of the three things that I've labeled here. There's data, and there are rules that you write that act on that data, and that's where we programmers bring value because those rules then provide answers. Another way you might program rules is like something like a game where the game will respond to things that happen in the game world. So, maybe something like Breakout where once the ball hits the brick, the ball should bounce back and the brick should vanish. You can do that by writing code like this. So, again, you have data, which is the location of the ball, the location of the bricks, etc. You have rules, which are the lines of code that you write, and you have answers, how the game situation updates in response to these actions. So, I like to summarize traditional programming like this using those terms. You have rules and data that come in, and you have answers that come out. And this is basically what we've all been making a living off of. The ongoing machine learning revolution from a programmer's perspective is just a reorientation of this diagram. So, instead of us as programmers trying to figure out the rules that will give us the answers, what if we can feed in lots of answers along with the data and have a machine figure out what those rules are? And that's really what machine learning is all about. Get lots of data, know what the answers are to that data, and that's a process called labeling, and then establish the rules that will match one to the other. Now, this might seem a little vague right now, so let's look at a scenario. Think about a device for activity recognition, like a smart watch. If you were creating one of these and you had sensors on it that provide data, such as the speed the person is moving at, what are the rules that you would write to give answers? Where the answer, of course, is the activity that the person's performing. For example, you might say that if the speed is less than a certain amount, the answer is that the person's walking. You could extend that then to say if it's greater than that amount, then the person's running. You've now detected two activities, walking and running. It's a little naive, but hopefully it works just for illustration. But what if you want to go further? Another fitness activity, for example, is biking. And you could extend your algorithm to understand biking like this. If the value's less than four, they're walking. Otherwise, if it's less than 12, they're running. Otherwise, they're biking. It still kind of works. But what happens then if you want to detect golfing? Uh-oh, indeed. And not just golfing. Despite the naivety of this algorithm, it's easy to see where this is a really difficult scenario to implement with rules. Your speed will vary if you're going up or downhill, and your walking speed might be my running speed, and so on. Sometimes one cannot just simply figure out the rules to determine complex behavior like this. So, if we return to this diagram and consider machine learning to be answers and data fed in, and the rules get inferred from it, we could then change our activity recognition scenario. So, what if you had lots and lots of people wearing your sensor, and say that they're walking, and that you've captured that data? Similar for running, biking, and yes, even golfing. What if you then looked at that data and had a way to figure out how to match the patterns to the label? You'd have a scenario that says, "This is what walking looks like. This is what running looks like." and so on. And that's really the core of machine learning. Having lots of data, having labels for that data, and then programming a computer to figure out what the distinguishing parts of the data are that fit to the labels. Now, that was just a hypothetical scenario, but the same concept can apply to things like computer vision and natural language processing. And you'll learn those techniques throughout this course. So, let's start with a very simple scenario, and it's what I consider to be the hello world of machine learning. Take a look at these numbers. There's a pattern that connects them. There's a relationship between the X and Y that holds for each XY pairing. So, when X is minus one, Y is minus three. When X is one, Y is one, etc. Can you see what the pattern is? I'll give you a moment to think about it. Did you get it yet? Well, let's look back at the numbers. The relationship here is that every Y is two times the corresponding X minus one. Yes, I know we said we wouldn't do a lot of math, but I hope you're okay with this exception. If you got the answer, well, how did you get it? For me, I saw that Y increased by two when X increased by one. So, I guessed that it was Y equals 2X plus or minus something. I then took a guess that it might be minus one because when X is zero, the answer was minus one. I looked back over all of the other numbers and I found that that relationship worked. That's almost exactly how a neural network does it, too. So, let's explore this in code. So, here's an example of a TensorFlow app that will figure out that relationship for us. I know there's a whole lot of new concepts in here, so I'm going to unpack them one by one. First is this line. This is probably the most mysterious of the bunch, so let's explain it visually. You know how you often see pictures of neural networks that look a little like this? Each of the columns in the red boxes here are called layers. And each of these blue blobs are neurons. Every neuron is connected to every other neuron, and that's called a dense layer because of the dense connectivity between them. You define these kinds of neural networks using code. So, let's look back at our code and see what we've defined. The first part of the line says that it's a Keras sequential. Keras is a framework within TensorFlow for making the definition of training and using ML models easy. I'll be using it extensively in this course. The name sequential basically tells us that we're going to define a sequence of layers. In the diagram earlier, we had three layers. Well, how many layers do you think are in the network that we're defining in the code here? There's only one because we only have one line of code within the sequential. Do you notice what type of layer it is? It's a dense, which is the simplest layer type there is with basic neurons in it. Later, you'll learn more about sophisticated neuron types, but those in a dense are pretty basic. Now, what does our dense look like? Well, that's visible within the dense parameters, and we say we have only one unit or one neuron in this layer. And we only have one layer. The input shape parameter tells us the shape of the data that we'll train our layer on, and it's just one value. So, our neural network will look like this. That's the simplest neural network you can get, one layer, one neuron. And what the neuron can do is learn to match data to labels. So, let's see how this one will do it by returning to our code. The core of how a network learns is in these two parameters, the optimizer function and the loss function. Here's where all the math in machine learning comes from. Now, let me explain what they do. The idea is that the neural network has no idea of the relationship between the data and the labels. So, it has to make a guess. It then looks at the data and evaluates the guess. The loss function is a way of measuring how good or how bad that guess is. The results of this are used by the optimizer to make another guess. That guess is then measured using the loss function again with the logic being that an optimizer can improve the guess. This data is passed back to the optimizer to get another guess and so on. And this is the process of training a neural network. In our code, we're going to be doing that loop, making a guess, measuring its effectiveness with the loss function, optimizing to get another guess, and repeating 500 times. There's some complex math going on to measure the loss and optimize for new guess, but we're not going to dwell on that for now. The loss function here is called mean squared error, and the optimizer is SGD, which stands for stochastic gradient descent. We'll compile the model using them. Next up, we're going to define our data. The NP stands for NumPy, a Python library that makes handling data a lot easier, and which you'll see a lot of when you're using machine learning. We'll call our data X's, and we'll call our labels Y's. Next is where we do the learning. We tell the model to fit the X's to the Y's, and do the loop that we spoke about earlier 500 times or 500 epochs. At the end of this, the rough guess that the neuron makes at the beginning will hopefully be refined into a good model that figured out the relationship between our X's and our Y's. Once the model is done training, you can then predict values using it. So, given what we learned about X and Y, and that the relationship between them was Y equals 2X minus 1, what do you think the answer to predicting 10.0 will be? You might have thought that it would be 19, and you'll be very close to being right. But, it won't be exactly 19 for a few reasons. Most notably, the fact that this model is trained on only six points of data, and that for those six points of data, the relationship is linear, that it's Y equals 2X minus 1. But, there's no guarantee that that would be the case for other points. The data could skew off in other directions, and the neuron has no idea if that's the case or not, because it's only been trained on this limited data. That being said, the probability that it's a straight line is very high, so the neuron factors that into its learning, and when asked to predict, it will give you a number very close to 19, because the probability is very high that the value for Y when X is 10 is 19. It's an important lesson to remember. Neural networks deal in probability. They'll give you a likelihood that an answer is correct, and you'll often have to deal with processing that likelihood. So, if we go back to traditional programming for a second, you might write a function like this. Get result X to return 2X minus 1, and it would work. But, it would only ever return 2X minus 1, because it's hard-coded to do so. You could generalize the function like this, where you pass in the parameters 2 and minus 1, and now the function will return 2X minus 1, and if you wanted to use other values, you could do so. A neuron sort of works like this, where it has the parameters instead of hard-coded values, but it learns those parameters from the data over time. As a result, it's a general function that learns how to behave, and this is what leads to the term machine learning. Our neurons are learning the parameters that will give the desired results, with a view to those results then working in the future with other data. Okay. So, now it's time to see this hands-on. I'll step you through some code, and then you can try it for yourself. So, let's get started looking at this lab. I'm using a piece of software called Google Colab, and if you go to the URL, you'll see it. And you'll be able to execute it that way. What Google Colab does is allow us to execute Python code in the browser. As a result, you don't need to set up a Python environment, and you don't need to set up TensorFlow and all of that. You can actually do it all completely within the browser. So, it's pretty cool. And you can write code within it, too, not just execute it. So, the model that we were looking at is here. And let's go and like take a look through it. So, first of all, what I'm going to do is import the stuff that I need to import. And the first time you run it, you might see a warning like this. It's okay to run it anyway. And up in the top right here, you might see it takes a moment to connect to a virtual machine that it can run on. And now you can see I'm connected. So, I'm going to run this piece of code now, and it's just importing TensorFlow, it's importing NumPy, and it's importing Keras that we spoke about in the video. We're going to define and compile the neural network now. And here you see the same code that we saw earlier. A single unit in a single dense with an input shape of just one value. We're going to compile that model now using stochastic gradient descent and a mean squared error. And now we're going to provide data to the model. And I'm using different data here with a different relationship than we showed in the video. So, I'm going to see here's my X's and Y's, and I'm going to train them. Can you see what the relationship might be? All right. Well, we can see now that we're going to model.fit. So, I'm just going to fit the X's to the Y's over 500 epochs. It goes really fast because this is a very simple neural network, and we're running on a powerful machine. So, we see our loss function. I'll wait till it's complete, and we'll see that our loss function is reducing continuously. So, if I go all the way to the bottom, we can see that our loss function is now 4.5 * 10 ^ -7. It's tiny. And if I go back to the top, we can see that our loss value was initially 80. Now, this value itself doesn't really mean that much, but the thing that you want to look for is it going down. So, it made a guess as to the relationship between X and Y, and it measured that loss, and it came up with a value of 80. That was passed to the optimizer for the second time around, it made another guess, it measured it, that went to 63. The third time around it went to 49, the fourth time around it went to 39, and we can see that loss is diminishing as we go along. So, by the time we reached the end, the loss was tiny, and it was whatever was like something times 10 to the minus seven. So, now we know we have a model with really tiny loss, so that means the guesses that it made were very close to the actual values. So, if I then say print model.predict 10, it's giving me 30.99. So, the relationship here was Y equals 3X plus 1. And if we look at our data, we'll see that that was the case. So, Y equals 3X plus 1. For example, if Y is 1, if X is 1, then Y is 4, if X is 2, then Y is 7. We can see that that's the correct relationship. And when I tried to predict on it, I got 30.99. So, it's something that was very, very close to 31 as we discussed in the video, but not exactly 31. So, please have a look at this workbook, try it out for yourself, and if you want to experiment with different values of X and Y, go ahead and do so, and see what kind of answers you're going to come up with. Thanks. So, that was pretty straightforward. You can try it out for yourself now. You can find the code at this URL. I'd recommend you pause the video while you work on it, and when you're done, come back, and you can try the exercise. Done already? Nice work. Okay, so before we wrap up, here's the URL for the exercise. Give it a try, and see if you can figure out the answer. I'll start the next video with the answer to this exercise. You can learn more about TensorFlow on our channel at youtube.com/tensorflow, and stay tuned to this channel for the rest of this training series. If you have any questions, please leave them in the comments below. Don't forget to hit that subscribe button. Thank you.

Original Description

Machine Learning Foundations is a free training course where you’ll learn the fundamentals of building machine learned models using TensorFlow. In Episode 1 we talk about what machine learning actually is and how it works, including a simple hands-on example to get you started building ML models--the “Hello World” of machine learning! Example: The “Hello World” of ML → https://goo.gle/3dfRtD1 Exercise 1 → https://goo.gle/2zdSPzm TensorFlow is Google’s end-to-end open source machine learning platform. For more videos about TensorFlow, subscribe to the TF YouTube channel → https://goo.gle/TensorFlow Machine Learning Foundations playlist → https://goo.gle/ml-foundations Subscribe to Google Developers → https://goo.gle/developers
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Google for Developers · Google for Developers · 44 of 60

1 Developer Journey - Sunnyvale DSC Summit ‘19
Developer Journey - Sunnyvale DSC Summit ‘19
Google for Developers
2 How Google is working with students - Sunnyvale DSC Summit ‘19
How Google is working with students - Sunnyvale DSC Summit ‘19
Google for Developers
3 Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Starting your career in the Cloud - Sunnyvale DSC Summit ‘19
Google for Developers
4 The Solution Challenge  - Sunnyvale DSC Summit ‘19
The Solution Challenge - Sunnyvale DSC Summit ‘19
Google for Developers
5 Firebase - Sunnyvale DSC Summit ‘19
Firebase - Sunnyvale DSC Summit ‘19
Google for Developers
6 Cloud Hero - Sunnyvale DSC Summit ‘19
Cloud Hero - Sunnyvale DSC Summit ‘19
Google for Developers
7 Panel discussion  - Sunnyvale DSC Summit ‘19
Panel discussion - Sunnyvale DSC Summit ‘19
Google for Developers
8 The art of negotiation - Sunnyvale DSC Summit ‘19
The art of negotiation - Sunnyvale DSC Summit ‘19
Google for Developers
9 Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Courage to care, solve and share - Sunnyvale DSC Summit ‘19
Google for Developers
10 Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Version 9 of Angular, Glass Enterprise Edition 2, path to DX deprecation, & more!
Google for Developers
11 [DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
[DEPRECATING] Introducing a new series (Assistant for Developers Pro Tips)
Google for Developers
12 Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Detecting memory bugs with HWASan, Bazel 2.1, Next ‘20 session guide, & more!
Google for Developers
13 Why Podcast.app chose a .app domain name
Why Podcast.app chose a .app domain name
Google for Developers
14 Machine Learning Bootcamp Jakarta 2019
Machine Learning Bootcamp Jakarta 2019
Google for Developers
15 Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Android Studio 3.6, Android 11 Developer Preview, Kubeflow 1.0, & more!
Google for Developers
16 [DEPRECATING]  Importance of community (Assistant on Air)
[DEPRECATING] Importance of community (Assistant on Air)
Google for Developers
17 Why the Flutter team switched from .io to a .dev domain name
Why the Flutter team switched from .io to a .dev domain name
Google for Developers
18 3 website-building tips from .dev creators
3 website-building tips from .dev creators
Google for Developers
19 Why NimbleDroid chose a .app domain name
Why NimbleDroid chose a .app domain name
Google for Developers
20 Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Android Platform Codelab, Bazel 2.2, Maps Android Utility Library v1.0, & more!
Google for Developers
21 Google for Games Developer Summit: A free, digital experience for game developers
Google for Games Developer Summit: A free, digital experience for game developers
Google for Developers
22 Inspecting Home Graph (Assistant for Developers Pro Tips)
Inspecting Home Graph (Assistant for Developers Pro Tips)
Google for Developers
23 Google for Games Developer Summit Keynote
Google for Games Developer Summit Keynote
Google for Developers
24 Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Stadia Games & Entertainment presents: Keys to a great game pitch (Google Games Dev Summit)
Google for Developers
25 Empowering game developers with Stadia R&D (Google Games Dev Summit)
Empowering game developers with Stadia R&D (Google Games Dev Summit)
Google for Developers
26 Supercharging discoverability with Stadia (Google Games Dev Summit)
Supercharging discoverability with Stadia (Google Games Dev Summit)
Google for Developers
27 Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Stadia Games & Entertainment presents: Creating for content creators (Google Games Dev Summit)
Google for Developers
28 Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Bringing Destiny to Stadia: A postmortem (Google Games Dev Summit)
Google for Developers
29 Live Captioning in Google Slides
Live Captioning in Google Slides
Google for Developers
30 [DEPRECATING]  User engagement for the Google Assistant
[DEPRECATING] User engagement for the Google Assistant
Google for Developers
31 TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
TensorFlow Dev Summit ‘20, Google for Games Dev Summit, Cloud AI Platform Pipelines, & much more!
Google for Developers
32 Top 5 from the TensorFlow Dev Summit 2020
Top 5 from the TensorFlow Dev Summit 2020
Google for Developers
33 Developer Student Clubs 2019 Turkey Leads Summit
Developer Student Clubs 2019 Turkey Leads Summit
Google for Developers
34 Building simpler payment experiences | Google Pay Plugin for Magento 2
Building simpler payment experiences | Google Pay Plugin for Magento 2
Google for Developers
35 Become A Developer Student Club Lead
Become A Developer Student Club Lead
Google for Developers
36 Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Firebase Kotlin Extensions, ARM apps on the Android Emulator, Angular v9.1, & more!
Google for Developers
37 Test suite for Smart Home (Assistant for Developers Pro Tips)
Test suite for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
38 Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google Play updates, Bazel 3.0, Business Console for Google Pay, & more!
Google for Developers
39 How to use error logs (Assistant for Developers Pro Tips)
How to use error logs (Assistant for Developers Pro Tips)
Google for Developers
40 Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Contact Center AI, Android Studio 4.1 Canary 5, TensorFlow QAT API, & more!
Google for Developers
41 WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
WebView DevTools, Kotlin meets gRPC, Flutter CodePen support, & more! (Episode 200)
Google for Developers
42 Offline handling for Smart Home (Assistant for Developers Pro Tips)
Offline handling for Smart Home (Assistant for Developers Pro Tips)
Google for Developers
43 Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Android 11 Dev Preview 3, Google Fonts for Flutter, Shielded VM, & more!
Google for Developers
Machine Learning Foundations: Ep #1 - What is ML?
Machine Learning Foundations: Ep #1 - What is ML?
Google for Developers
45 Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Flutter web support updates, BigQuery materialized views, Cloud Spanner emulator, & more!
Google for Developers
46 Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Computer vision by building a neural network with TensorFlow | Machine Learning Foundations
Google for Developers
47 Machine Learning Foundations: Ep #3 - Convolutions and pooling
Machine Learning Foundations: Ep #3 - Convolutions and pooling
Google for Developers
48 Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Android 11 Beta plans, Flutter 1.17, Dart 2.8, & much more!
Google for Developers
49 Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Machine Learning Foundations: Ep #4 - Coding with Convolutional Neural Networks
Google for Developers
50 Google Developers ML Summit
Google Developers ML Summit
Google for Developers
51 Real-world image classification using convolutional neural networks | Machine Learning Foundations
Real-world image classification using convolutional neural networks | Machine Learning Foundations
Google for Developers
52 Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Adobe XD support for Flutter, Architecture Framework, temporary closures with Places API, & more!
Google for Developers
53 Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Machine Learning Foundations: Ep #6 - Convolutional cats and dogs
Google for Developers
54 Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Machine Learning Foundations: Ep #7 - Image augmentation and overfitting
Google for Developers
55 Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Announcing Firebase Live, Flutter Day, Java 11 on Google Cloud Functions, & more!
Google for Developers
56 Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Machine Learning Foundations: Ep #8 - Tokenization for Natural Language Processing
Google for Developers
57 Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Android 11 Beta, Google Play Asset Delivery, Firebase Crashlytics SDK, & much more!
Google for Developers
58 Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Natural Language Processing: Using sequencing APIs in TensorFlow | Machine Learning Foundations
Google for Developers
59 Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Build a sarcasm classifier using NLP and TensorFlow | Machine Learning Foundations
Google for Developers
60 AR Realism with the ARCore Depth API
AR Realism with the ARCore Depth API
Google for Developers

Related Reads

Up next
Arrays vs Lists: What AI Actually Prefers | Common Tech Interview Questions
SCALER
Watch →