The global burden of the opportunistic fungal disease Pneumocystis jirovecii pneumonia (PJP) remains substantial. Polymerase chain reaction (PCR) on nasopharyngeal swabs (NPS) has high specificity and may be a viable alternative to the gold standard diagnostic of PCR on invasively collected lower respiratory tract specimens, but has low sensitivity. Sensitivity may be improved by incorporating NPS PCR results into machine learning models. Three supervised multivariable diagnostic models (random forest, logistic regression and extreme gradient boosting) were constructed and validated using a 111-person Australian dataset. The predictors were age, gender, immunosuppression type and NPS PCR result. Model performance metrics such as accuracy, sensitivity, specificity and predictive values were compared to select the best-performing model. The logistic regression model performed best, with 80% accuracy, improving sensitivity to 86% and maintaining acceptable specificity of 70%. Using this model, positive and negative NPS PCR results indicated post-test probabilities of 84% (likely PJP) and 26% (unlikely PJP), respectively. The logistic regression model should be externally validated in a wider range of settings. As the predictors are simple, routinely collected patient variables, this model may represent a diagnostic advance suitable for settings where collection of lower respiratory tract specimens is difficult but PCR is available.