Automatic Learning of Algebraic Models for Optimization