Get startedGet started for free

Surviving a meteor strike

1. Surviving a meteor strike

Welcome back! We are going to learn just what you're missing to be able to save the Earth from a meteor strike. But first, let's see how to compile, train and predict with your models!

2. Recap

In the previous lesson we saw how easy it was to create a model with Keras. You instantiate your Sequential model,add a couple of layers and their activations, and that's it, you've built a simple model in no time.

3. Compiling

A model needs to be compiled before training. We can compile our model by calling the compile method on it. The compile method receives an optimizer, which we can see as the algorithm that will be used to update our neural network weights, and a loss function, which is the function we want to minimize during training. In this case, we choose ADAM as our optimizer and mean squared error as our loss function. Optimizers and loss functions will be covered later on in the course, so don't worry about it for now. Compiling our model produces no output. Our model is now ready to train!

4. Training

Creating a model is useless if we don't train it. We train our model by calling the fit method and passing the features in X_train, the labels in y_train and the number of epochs to train for. During an epoch, our entire training data passes through the network and the respective weight updates take place using back-propagation. As our model is being trained, we will get some output showing its progress. We can see the model is improving since the mean squared error loss is decreasing at each epoch.

5. Predicting

To obtain predictions from our trained model we just need to call predict on the new set of data. We can store the predictions in a variable for later use. The predictions are just numbers in a numpy array, we will interpret these depending on our dataset and problem at hand.

6. Evaluating

To quickly evaluate how well our model performs on unseen data we can use the model's evaluate method. This performs feed-forward with all samples in our test dataset (X_test). Feed-forward consists in computing a model's outputs from a given set of inputs. It then computes the error comparing the results to the true values stored in y_test. In this particular example, the model we trained for 5 epochs before, has a mean squared error of 0.25.

7. The problem at hand

Are you ready?! A meteor is approaching the earth and we want to make sure it won't take us to extinction. A group of scientists is trying to estimate the orbit by using historical data gathered about previous orbits of similar meteors.

8. Scientific prediction

Scientist have used this data alongside their knowledge to estimate an 80-minute orbit, that is, an orbit from -40 minutes to +40 minutes. t=0 corresponds to the time of crossing the impact region. It looks like the meteor will be close! Perhaps it won't hit us, but we must make sure we are right!

9. Your task

You have data for the path a previous meteor took during a period of 20 minutes, 10 minutes before and 10 minutes after crossing the impact region. You will train a model on this data and then extrapolate your predictions to an 80-minute orbit to see how it compares to the scientists prediction. Will your orbit be similar to that of the scientists or are we facing the extinction of humanity as we know it?

10. Let's save the earth!

Let's find out!