From the course: Artificial Intelligence Foundations: Neural Networks
Solution: Build a neural network
From the course: Artificial Intelligence Foundations: Neural Networks
Solution: Build a neural network
(upbeat music) - [Instructor] Well, I hope you enjoyed that challenge. Let's now take a look at the solution. What we're going to do is just run through the cells one by one and see the output. So first we need to import our necessary libraries. Then we need to grab our data from the GitHub repo, put that into a pandas data frame. And then we're using the pandas info function to get a concise summary of the data frame. And now we want to get some summary statistics of the data. And here we're just looking to see the shape of the data frame. And in this cell, we're really just using the is null method to check and see if there are any null values. So let's do a little bit of exploratory data analysis. So here we're just going to plot the heat map so that the values are shown. And here we're going to use a correlation matrix. And then down here we're going to have another correlation matrix but this time in table form. We're going to here visualize the correlation using gradient coloring. And down here we're going to use a scatter plot to again see the linear relationship between the features and sales. So now we enter the data pre-processing step. We're just going to go ahead and split the features X feature and Y target. We're going to go ahead and scale those features or normalize those features. Now we're going to split the data into a training and test set. Going to go ahead and print that and see what that looks like. So now we're at step two and this is the section where I challenged you to write your own code to create a simple three layer neural network. So your first line should have said model equals sequential because you're using the Keras Sequential API, then you needed to build the network by adding layers so you added the input layer, you added a hidden layer and you added an output layer. Your input layer had four neurons. Your hidden layer had three, and your output layer had one. You then compile the model using the atom optimizer. You used MSE for your loss function and a metric as well. And then you fit the model by writing this bit of code. You should have put in 32 for your number of epochs. So let's go ahead and run it. It'll go through 32 iterations. And for our final step, let's look at a visualization of our model. So here we're using some standard graphing code just to plot the model and see the visualization. We're essentially plotting a graph of the model loss where we are showing the graph of model loss in training and validation. You simply have to make sure that you have your metrics here, and then just run the code. And there you have it. We have our graph and you can see there's convergence. And this is just what we expected. I hope you enjoyed that challenge. Don't worry if your code doesn't look exactly like mine. That is the nature of working with data and its iterations. And if you're interested in learning more and playing more, check out the extras file we provided.