To construct a prediction model of olfactory dysfunction after transnasal sellar pituitary tumor resection based on machine learning algorithms. A cross-sectional study was conducted. From January to December 2022, 158 patients underwent transnasal sellar pituitary tumor resection in three tertiary hospitals in Sichuan Province were selected as the research objects. The olfactory status was evaluated one week after surgery. They were randomly divided into a training set and a test set according to the ratio of 8:2. The training set was used to construct the prediction model, and the test set was used to evaluate the effect of the model. Based on different machine learning algorithms, BP neural network, logistic regression, decision tree, support vector machine, random forest, LightGBM, XGBoost, and AdaBoost were established to construct olfactory dysfunction risk prediction models. The accuracy, precision, recall, F1 score, and area under the ROC curve (AUC) were used to evaluate the model's prediction performance, the optimal prediction model algorithm was selected, and the model was verified in the test set of patients. Of the 158 patients, 116 (73.42%) had postoperative olfactory dysfunction. After missing value processing and feature screening, an essential order of influencing factors of olfactory dysfunction was obtained. Among them, the duration of operation, gender, type of pituitary tumor, pituitary tumor apoplexy, nasal adhesion, age, cerebrospinal fluid leakage, blood scar formation, and smoking history became the risk factors of olfactory dysfunction, which were the key indicators of the construction of the model. Among them, the random forest model had the highest AUC of 0.846, and the accuracy, precision, recall, and F1 score were 0.750, 0.870, 0.947, and 0.833, respectively. Compared with the BP neural network, logistic regression, decision tree, support vector machine, LightGBM, XGBoost, and AdaBoost, the random forest model has more advantages in predicting olfactory dysfunction in patients after transnasal sellar pituitary tumor resection, which is helpful for early identification and intervention of high-risk clinical population, and has good clinical application prospects.