In order to better understand the purchase decision-making process of consumers, this paper makes an in-depth study on the precision marketing of e-commerce products on the basis of KNN algorithm. Through data mining, classic KNN algorithm, BPNN algorithm, and other methods, this paper takes the price and purchase intention of e-commerce agricultural products as an example. Based on the classic nearest neighbor algorithm, binomial function is combined with Euclidean distance formula when calculating the nearest neighbor through similarity. The particle swarm optimization algorithm is used to optimize the binomial function coefficient and the K value of the nearest neighbor algorithm, and the results of the best prediction model for the prediction application of e-commerce agricultural product price and purchase intention are established. Both pricing strategies and promotion strategies will weaken the compromise effect of consumers when they choose e-commerce agricultural products. After studying the calculation method of the KNN algorithm, it not only correctly predicts the price of e-commerce agricultural products but also makes a corresponding prediction and analysis of consumers’ purchase intention of e-commerce agricultural products, with the highest accuracy of 94.2%. At the same time, in the future precision marketing process, e-commerce agricultural products enterprises use data technology to achieve precision marketing, which effectively changes the shortcomings of traditional marketing and improves the product marketing effect and economic benefits.