With the rapid development of economy, how to accurately analyze and forecast the stock price has become a key problem. There are many methods and models about stock price prediction, such as KNN algorithm. However, the traditional KNN algorithm only uses the data of latest one day to predict the change trend of the next day, which is of little significance for reference. Therefore, this paper proposes an improved KNN algorithm, that is, the share price information group of the first N days is synthesized into a sample, which is input to the KNN model for learning. Experiments show that the improved KNN algorithm has better predictive performance than the traditional KNN algorithm.