Skip to content
Advertisement

Linear regression prediction based on group of data in test set

I have a simple dataset which looks like this:

JavaScript

I created a simple LR model to train and predict the target variable “sales”. And I used MAE to evaluate the model

JavaScript

My code works well, but what I want to do is to predict the sales in the X_test grouped by hour of the day. In the above dataset example, there is three hours slots, 12, 3, and 6. So the output should look like this:

JavaScript

I think I should use for loop to iterate. It could be something like this:

JavaScript

So any idea how to perform it?

Advertisement

Answer

JavaScript

prints

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement