Optimization problem is widely used in production management, military command and scientific experiments and other fields, moth-flame optimization algorithm as a new swarm intelligence optimization algorithm, has the advantages of fast convergence, simple structure, strong robustness, memory mechanism, it is also one of the focus of scholars. K-means clustering is the most famous partition clustering algorithm. Given a set of data points and the required number of clustering k, k is specified by the user, and the K-means algorithm repeatedly divides the data into K clusters according to a certain distance function. This article first on moth-flame optimization algorithm (MFO) the existence of complex or slightly larger scale function to solve the problems of slow convergence speed, put forward by the flame number greater than the number of moths reference grey wolf optimizer (GWO) comes first algorithm do rectilinear flight, later periods the scaling factor are introduced to improve moth-flame optimization algorithm, in order to realize broaden the moths search area, improve the ability of global optimization and convergence rate of the target. Through experiments to verify the feasibility of the improved Moth-flame optimization algorithm (IMFO), the convergence speed is significantly higher than MFO algorithm, and the solution accuracy is also greatly improved. Then the algorithm is used to guide the clustering center of k-means clustering algorithm to improve the clustering accuracy. The three algorithms of K-means, MFO Fusion K-means (MFO-KM) and IMFO Fusion K-means (IMFO-KM) algorithms were compared in the international standard data set Iris, Seeds and Wine Quality. The results showed that: IMFO-KM algorithm has the best performance improvement in Wine Quality data set, with the accuracy improved by 3.82%-6.37% compared with other algorithms, the class average distance G reduced by 7.18%-13.58%, and the standardized mutual information improved by 14.17%.