The variational wave functions based on neural networks have recently started to be recognized as a powerful ansatz to represent quantum many-body states accurately. In order to show the usefulness of the method among all available numerical methods, it is imperative to investigate the performance in challenging many-body problems for which the exact solutions are not available. Here, we construct a variational wave function with one of the simplest neural networks, the restricted Boltzmann machine (RBM), and apply it to a fundamental but unsolved quantum spin Hamiltonian, the two-dimensional $J_1$-$J_2$ Heisenberg model on the square lattice. We supplement the RBM wave function with quantum-number projections, which restores the symmetry of the wave function and makes it possible to calculate excited states. Then, we perform a systematic investigation of the performance of the RBM. We show that, with the help of the symmetry, the RBM wave function achieves state-of-the-art accuracy both in ground-state and excited-state calculations. The study shows a practical guideline on how we achieve accuracy in a controlled manner.