A living cell responds in sophisticated ways to its environment. Such behavior is all the more remarkable when one considers that a cell is a bag of molecules. A detailed algorithmic explanation is required for how a network of chemical reactions can produce sophisticated behavior. Several previous works have shown that reaction networks are computationally universal and can, in principle, implement any algorithm. The problem is that these constructions have not mapped well onto biological reality, have made wasteful use of the computational potential of the native dynamics of reaction networks, and have not made any contact with statistical mechanics. We seek to address these problems. We find that the mathematical structure of reaction networks is particularly well suited to implementing modern machine learning algorithms. We describe a new reaction network scheme for solving a large class of statistical problems including the problem of how a cell would infer its environment from receptor-ligand bindings. Specificially we show how reaction networks can implement information projection, and consequently a generalized Expectation-Maximization algorithm, to solve maximum likelihood estimation problems in partially-observed exponential families on categorical data. Our scheme can be thought of as an algorithmic interpretation of E. T. Jaynes's vision of statistical mechanics as statistical inference.