Molecular pattern recognition is ubiquitous in nature, from the primitive chemotaxis systems of bacteria to the highly complex brains of mammals. To date, numerous setups have been developed that mimics such behavior and enable molecules to perform various computational tasks. However, there is still no generalized approach that allows biomolecular systems to achieve the same universality and flexibility in computation as brain structures or artificial neural networks. Molecular commutation is a recently discovered, fundamentally distinct mechanism of biological information processing and storage using weak affinity interactions of virtually any molecules governed by the law of mass action. Using this principle, here, we demonstrate the first universal, dataset-independent two-step methodology for building DNA-based molecular neural networks for solving machine learning tasks. The networks are initially solved as affinity matrices with reasonable-for-real-life constraints using backpropagation-like algorithms. While, these matrices are suitable for any type of biomolecules (DNA, proteins, etc.), we further demonstrate that DNA ensembles can be identified that fit such matrices and allow successful in silico operation of the neural networks. We constructed DNA networks for solving three machine learning benchmark tasks — IRIS flowers classification (IRIS dataset, 4-input, 3-class classification), housing prices prediction (California Housing dataset, 8-input regression), and handwritten digit recognition (MNIST dataset, 784-input, 10-class classification — with performance comparable to classical machine learning algorithms (accuracy for IRIS and MNIST in 80-95 % range). The versatility of the approach, its applicability to arbitrary data, and the complexity of recognizable patterns significantly extends the boundaries of existing views on molecules as computational entities.