Improved Balanced Classification with Theoretically Grounded Loss Functions