Mathematical foundations of machine learning and forecasting