Most of the methods that produce space weather forecasts are based on deterministic models. In order to generate a probabilistic forecast, a model needs to be run several times sampling the input parameter space, in order to generate an ensemble from which the distribution of outputs can be inferred. However, ensemble simulations are costly and often preclude the possibility of real-time forecasting. We introduce a simple and robust method to generate uncertainties from deterministic models, that does not require ensemble simulations. The method is based on the simple consideration that a probabilistic forecast needs to be both accurate and well-calibrated (reliable). We argue that these two requirements are equally important, and we introduce the Accuracy-Reliability cost function that quantitatively measures the trade-off between accuracy and reliability. We then define the optimal uncertainties as the standard deviation of the Gaussian distribution that minimizes the cost function. We demonstrate that this simple strategy, implemented here by means of a regularized deep neural network, produces accurate and well-calibrated forecasts, showing examples both on synthetic and real-world space weather data.