Although the NaV1.7 sodium channel is a promising drug target for pain, traditional screening strategies for discovery of NaV1.7 inhibitors are very painstaking and time-consuming. Herein, we aimed to build machine learning models for screening and design of potent and effective NaV1.7 sodium channel inhibitors. We customized the imbalanced data set from ChEMBL and BindingDB to train and filter the best classification model. Then, the whole-cell voltage-clamp was employed to validate the inhibitors. We assembled a molecular group optimization method by combining the Grammar Variational Autoencoder, classification model, and simulated annealing. We found that the RF-CDK model (random forest + CDK fingerprint) performs best in the imbalanced data set. Of the three compounds that may have inhibitory effects, nortriptyline has been experimentally verified. In the molecule optimization process, 40 molecules located in the applicability domain of RF-CDK were used as a starting point, among which 34 molecules evolved to molecules with greater molecular scores (MS). The molecule with the highest MS was derived from CHEMBL2325245. The model and method we developed for NaV1.7 inhibitors are also applicable to other targets.