Hydrogel-based negative hydration expansion (NHE) metamaterials are composite structures composed of responsive hydrogels and polymers, and their properties depend on their unique structures. In this paper, an optimization method based on the combination of the back-propagation neural network (BPNN) and the multi-population genetic algorithm (MPGA) is developed to rapidly design isotropic and anisotropic hydrogel-based metamaterials with specific NHE effects. In this method, several dimensionless design parameters are introduced to describe the structural characteristics of the metamaterial. The initial dataset is constructed based on the finite element method simulation results, and the mapping relationship between the design parameters and the equivalent linear strain is constructed by the BPNN, and the metamaterial with specific effect is efficiently optimized by combining the MPGA. The method is proved to have high accuracy and efficiency, and is applied to design many novel 2D and 3D metamaterials. The 3D metamaterial designed by this method has an ultra-large NHE ratio about 82 %. Compared with the topology optimization method, this method can significantly reduce the amount of computation, and can effectively avoid falling into the local optimum. The results show that the optimization method based on machine learning is an efficient means to design hydrogel-based metamaterials.