A team is training a neural network to forecast next week's electricity demand as a continuous numeric value from historical usage data. Which loss function is best suited to this time-series forecasting task?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Forecasting a continuous number like electricity demand is a regression problem, plain and simple, and the workhorse loss for regression is mean squared error. MSE takes the difference between the predicted value and the actual value, squares it so negative and positive errors don't cancel out and big misses get punished extra hard, and averages that across all your examples. That's exactly what you want when the output is a real number on a continuous scale, like demand in megawatts. That's answer B. Categorical cross-entropy and binary cross-entropy are both built for classification — comparing predicted class probabilities against actual class labels — and they don't even make sense mathematically for a continuous numeric target. Hinge loss is also a classification loss, most associated with support vector machines, built around maximizing margin between classes, which again has nothing to do with predicting a numeric quantity like demand.
Full explanation below image
Full Explanation
Mean squared error (MSE) computes the average of the squared differences between predicted and actual continuous values across all training examples: MSE = (1/n) * sum((y_actual - y_predicted)^2). It is the standard loss function for regression tasks, including time-series forecasting problems like predicting electricity demand, because it directly penalizes the numeric distance between prediction and ground truth, with the squaring term making larger errors disproportionately costly, which tends to push the model toward more accurate predictions especially where large deviations are undesirable. Its smooth, differentiable form also makes it convenient to optimize with gradient-based methods.
Categorical cross-entropy is incorrect because it is designed for multi-class classification problems, measuring the difference between a predicted probability distribution over discrete class labels and the true one-hot encoded class; it has no meaningful formulation for a single continuous numeric target such as a demand forecast. Binary cross-entropy is incorrect for the same underlying reason, specialized instead for two-class classification problems where the model outputs a probability between 0 and 1 for a single binary label; forecasting a continuous quantity like electricity demand is not a binary decision, so this loss does not apply. Hinge loss is incorrect because it is used primarily with margin-based classifiers such as support vector machines, penalizing predictions that fall on the wrong side of, or too close to, a decision boundary between classes; it is built around class separation, not around minimizing the numeric distance between a predicted and an actual continuous value, so it is not appropriate for regression-style forecasting.
A reliable rule of thumb: whenever the model's target is a continuous numeric quantity — prices, temperatures, demand levels, or any other measurement on a continuous scale — reach for a regression loss such as MSE or mean absolute error (MAE); whenever the target is a discrete class label, reach for a classification loss such as cross-entropy or hinge loss instead. Choosing the loss family that matches the nature of the target variable is one of the most fundamental setup decisions in any deep learning project.