Algebraic Machine Learning with an Application to Chemistry