- Home
- Training Library
- Big Data
- Courses
- Introduction to Data and Machine Learning

# First Deep Learning Model

## The course is part of this learning path

## Contents

###### Introduction to Deep Learning

**Difficulty**Beginner

**Duration**37m

**Students**275

### Description

In this Zero to Deep Learning course has been expertly created to provide you with a strong foundation in machine learning and deep learning. So whether you're just starting out with your practice of machine learning or you're a more experienced data scientist that is adding deep learning to the mix, this course will provide the necessary skills to serve as a solid foundation for you to continue learning after the course has been completed.

The course will start out covering simple data and structured data, then moving onto images, with sound, with text, and more complex data where deep learning comes to life. By the end of the course, you'll be able to recognize which problems can be solved with deep learning and organize data in a way that can be used by a neural network. Understanding and learning how to build a neural network model, including fully connected, convolutional, and recurrent neural network and train a model using cloud computing, all within this course.

This course is made up of 5 cohesive lectures that start off the journey into Data and Machine Learning with Cloud Academy.

**Learning Objectives**

- Learn the key principles of data and machine learning
- Come away with a strong foundation of the subject in order to develop new skills further
- Understanding and learning how to build neural network models

**Intended Audience**

- No prior knowledge of data and machine learning required

### Transcript

Hello, and welcome to our first coding session. In this video, we'll familiarize with the IPython Notebook Environment and we will run a first deep learning model. Don't worry if you don't understand everything in the code, because this is just to wet your appetite. And we will have plenty of occasions in the course to actually understand what we are doing. The Jupyter Notebook is an interactive environment that allows us to execute Python code in cells. This, for example, is a cell, but this too is a cell. This is a markdown cell that we can use to add text to comment our work. Comment our work. If I double click on a cell, the cell becomes active and I can edit it. For example, I can change this and say author. For example, I can change this and add a word. Hello, this is our first model. To execute the cell, I can either hit cell run, which will run it or, more simply, I can hit shift return. This will also run the cell. Running a markdown cell just renders it in markdown.

Running a cell that contains code executes the code contained in the cell. If I run a cell with an error, the error will be shown. If you're new to Python, it's important that you understand how to read error messages. The most important part of an error message is the last part. Here it's saying SyntaxError, invalid syntax. And then it indicates where the problem is. In this case, since there's only a line, it's very simple to correct the error. But keep in mind that when there's a long error message always look for the last message or the last line first. That contains the clue of solving the problem. Okay, so the first line here imports numpy, which is the library that contains all the linear algebra functions, like vectors, matrices, and so on. It's always good to import it when you're doing data work.

Then, in this cell, we import matplotlib and use a cell magic. A cell magic is a very special IPython construct that allows us to add functionality to the IPython Notebook Environment. In this particular case, we are setting the inline instruction to the matplotlib plotter. What this means is that, when we generate the plot using matplotlib, it will be displayed in the notebook itself. Then we import a generator of samples from a library called scikit-learn. Scikit-learn is Python's primary machine learning library and it comes with a lot of utilities like, for example, a data samples generator. We import the make_circles and you will understand immediately what this does. In the next cell, we call the make_circles function with some parameters, let's look at them. We have number of samples, we say 1000, a certain level of noise, a factor of 0.2 and we'll see what that means, and we also set the random_state. Don't worry about this. What's important is that this function has two outputs. We assign them to the variables X and y. So let's look at X first. X is a matrix, so it has rows and columns, and if we look at the shape, it has 1000 rows and two columns.

This corresponds to the number of samples and we have two features for each sample. Let's plot the values of X and let's plot them in two different colors. In blue, for the points of X that correspond to y equals to zero and in red, with a cross, for the points that corresponds to the label of y equals to one. This is our training data. We have data on the outer circle, that belongs to a certain class, and data in the inner space here the crosses that is belongs to the other class. In machine learning, we often want to train models to separate two classes. In this case, a model should learn that there is kind of a circular boundary between the red crosses and the blue dots. Now, let's go ahead build our first deep learning model. I will not explain what each of these line does, because we will go through these for the rest of the course.

Let's just see how simple it is to define a deep learning model. It's literally these three lines, where we import the relevant classes from keras. Keras is the library we will use for the whole course for doing deep learning. And then one, two, three, four, four lines to define the model and a fifth line to fit the model. Now, what's important is, when you execute the line that fits the model on the training data X and y, you can define a number of epochs and we will learn what these are in the course. Now, focus your attention on the output here. The output here tells us a certain number, loss, which seems to be decreasing over time. And another number, called acc, which stands for accuracy, which seems to increasing over time. Again, we will have the whole course to learn about these numbers and what they mean, but keep in mind this, we are running a fitting procedure over a thing called epoch. So first epoch, second epoch, third epoch, et cetera.

And a number called loss is decreasing, while a number called accuracy is increasing. Now, what we do in the rest of the notebook is just to draw the decision boundary of our model. To do this, we define a grid of points using a function from numpy called linspace. Linspace generates a sequence of numbers, exactly in this case 101 numbers, between the minimum value of minus 1.5 and the maximum value of 1.5. We call these horizontal ticks. And then we have vertical ticks, which have the same grid space. Then we do a bit of manipulation here to generate the grid of points that we end up called ab. So ab is a grid of points that, both in X and y, are have coordinates between minus 1.5 and 1.5. Then we predict, with our model, the values of the grid and we reshape the prediction to have the same shape as the grid. Don't worry if you don't understand this line. It's just boilerplate in order to generate the next figure. In the next figure, we plot the same data and we overlay a contour function, a contour plot, of our prediction grid.

As you can see, our model has learned a profile that separates really well the internal red crosses from the outer blue dots. I hope this served to wet your appetite. Maybe you've not understood everything, but I hope I've convinced you that building a deep learning model with keras is actually very, very simple. Before I go, I want to teach you a little trick of IPython Notebook. If you're in a cell, you can see that the cell is surrounded by a green rectangle. If you hit the button escape, the rectangle becomes blue, light blue. This means we are in notebook mode and in notebook mode, we can access some keyboard shortcuts to facilitate our navigation of the notebook environment. The most important shortcut is the letter h. If I press h in notebook mode, it will display all the keyboard shortcuts in a help. So look how many keyboard shortcuts there are. I strongly encourage you to have looked at these keyboard shortcuts. In particular, how to run a cell. We've already seen that, it's shift return. But also how to add cells and how to delete cells. This will make you very proficient in the use of IPython Notebook. Thank you for watching and see you in the next video.

### About the Author

**Students**744

**Courses**8

**Learning paths**3

I am a Data Science consultant and trainer. With Catalit I help companies acquire skills and knowledge in data science and harness machine learning and deep learning to reach their goals. With Data Weekends I train people in machine learning, deep learning and big data analytics. I served as lead instructor in Data Science at General Assembly and The Data Incubator and I was Chief Data Officer and co-founder at Spire, a Y-Combinator-backed startup that invented the first consumer wearable device capable of continuously tracking respiration and activity. I earned a joint PhD in biophysics at University of Padua and Université de Paris VI and graduated from Singularity University summer program of 2011.