In order to improve the defects of the Sparrow Search Algorithm (SSA) in single-species search, which causes redundancy in its speed of collection and easily ignores high-quality solutions and falls into local optimality, a K-means Multigroup Sparrow Search Algorithm (KSSA) based on K-means clustering was proposed. Firstly, the multi-population mechanism is introduced into SSA to weaken the collection ability of a single population and reduce the probability of falling into the local optimum. Secondly, the K-means algorithm is used to divide the sub-populations to increase the differences between the sub-populations, and at the same time, the individuals in the sub-populations focus on searching in a small range, thereby improving the efficiency of the initial search. Then, the weighted centroid communication strategy is used to improve the quality of communication between populations, reduce the interference of the own population, and reduce the risk of all sub-populations falling into the local optimum due to a sub-population falling into the local optimum. Finally, dynamic reverse learning is introduced into the vigilant to enhance its anti-predator behavior and improve the defects of slower collection speed and insufficient collection accuracy caused by the increase in the number of sub-populations. The test function simulation experiment shows that KSSA has better optimization performance than SSA and other algorithms.