RATIONALE: Acute respiratory failure is a life-threatening clinical outcome in critically ill pediatric patients. In severe cases, patients can require mechanical ventilation (MV) for survival. Early recognition of these patients can potentially help clinicians alter the clinical course and lead to improved outcomes. OBJECTIVES: To build a data-driven model for early prediction of the need for mechanical ventilation in pediatric intensive care unit (PICU) patients. METHODS: The study consists of a single-center retrospective observational study on a cohort of 13,651 PICU patients admitted between 1/01/2010 and 5/15/2018 with a prevalence of 8.06% for MV due to respiratory failure. XGBoost (extreme gradient boosting) and a convolutional neural network (CNN) using medication history were used to develop a prediction model that could yield a time-varying risk-score-a continuous probability of whether a patient will receive MV-and an ideal global threshold was calculated from the receiver operating characteristics (ROC) curve. The early prediction point (EPP) was the first time the risk-score surpassed the optimal threshold, and the interval between the EPP and the start of the MV was the early warning period (EWT). Spectral clustering identified patient groups based on risk-score trajectories after EPP. RESULTS: A clinical and medication history-based model achieved a 0.89 area under the ROC curve (AUROC), 0.6 sensitivity, 0.95 specificity, 0.55 positive predictive value (PPV), and 0.95 negative predictive value (NPV). Early warning time (EWT) median [inter-quartile range] of this model was 9.9[4.2-69.2] hours. Clustering risk-score trajectories within a six-hour window after the early prediction point (EPP) established three patient groups, with the highest risk groups PPV being 0.92. CONCLUSIONS: This study uses a unique method to extract and apply medication history information, such as time-varying variables, to identify patients who may need mechanical ventilation for respiratory failure and provide an early warning period to avert it.