1) First read all the prerequisites and then work on a problem
2) Start working on a problem and learn all the math ML/AI as you need
The second option works best.