Keras with R: Predicting car sales

This means that we are essentially training our model over 150 forward and backward passes, with the expectation that our loss will decrease with each epoch, meaning that our model is predicting the value of y more accurately as we continue to train the model.Let’s see what this looks like when we plot our respective losses:Both the training and validation loss decrease in an exponential fashion as the number of epochs is increased, suggesting that the model gains a high degree of accuracy as our epochs (or number of forward and backward passes) is increased.PerformanceSo, we’ve seen how we can train a neural network model, and then validate our training data against our test data in order to determine the accuracy of our model.Unlike when working with classification data, an accuracy reading does not particularly help us in this instance.The predicted car sales may be within 1% of actual car sales, but unless the predicted value is exact, then it will not be regarded as accurate.Therefore, we should redefine accuracy as the degree of deviation between the predicted and actual values.Let’s take a look at how we can calculate this:> pred <- data.frame(y = predict(model, as.matrix(X_test)))> df<-data.frame(pred,X_test)> attach(df)The following objects are masked from maxmindf: age, debt, gender, income, miles, sales> deviation=((pred-sales)/sales)> mean(deviation$y)*100[1] 0.02819805We see that the mean deviation between predicted and actual car sales stands at 2.819%.ConclusionIn this tutorial, you have learned how to:Construct neural networks with KerasScale data appropriately with MinMaxScalerCalculate training and test lossesMake predictions using the neural network modelMany thanks for your time, and please feel free to leave any questions you have in the comments below..You can also feel free to follow more of my data science content at More details

Leave a Reply