Optimizing class sizes and training budgets