Learning and Decision-Making with Data: Optimal Formulations and Phase Transitions