Hypericum perforatum L. (HPL), also known as St. John's wort, is one of the extensively researched domestically and internationally as a medicinal plant. In this study, non-targeted metabolomics combined with machine learning methods were used to identify reasonable quality indicators for the holistic quality control of HPL. First, the high-resolution MS data from different samples of HPL were collected, and visualized the chemical compounds through the MS molecular network. A total of 122 compounds were identified. Then, the orthogonal partial least squares-discriminant analysis (OPLS-DA) model was established for comparing the differences in metabolite expression between flower, leaf, and branches. A total of 46 differential metabolites were screened out. Subsequently, analyzing the pharmacological activities of these differential metabolites based on protein-protein interaction (PPI) network. A total of 25 compounds associated with 473 gene targets were retrieved. Among them, 13 highly active compounds were selected as potential quality markers, and five compounds were ultimately selected as quality control markers for HPL. Finally, three different classifiers (support vector machine (SVM), random forest (RF), and K-nearest neighbor (KNN)) were used to validate whether the selected quality control markers are qualified. When the feature count is set to 122 and 46, the RF model demonstrates optimal performance. As the number of variables decreases, the performance of the RF model degrades. The KNN model and the SVM model also exhibit a decrease in performance but still manage to satisfy the intended requirements. The strategy can be applied to the quality control of HPL and can provide a reference for the quality control of other herbal medicines.