Electronic health records (EHRs) provide meaningful knowledge of drug‐related adverse events (AEs) that are not captured in standard drug development and postmarketing surveillance. Using variables obtained from EHR data in the University of California San Francisco de‐identified Clinical Data Warehouse, we aimed to evaluate the potential of machine learning to predict two hematological AEs, thrombocytopenia and anemia, in a cohort of patients treated with linezolid for 3 or more days. Features for model input were extracted at linezolid initiation (index), and outcomes were characterized from index to 14 days post‐treatment. Random forest classification (RFC) was used for AE prediction, and reduced feature models were evaluated using cumulative importance (cImp) for feature selection. Grade 3+ thrombocytopenia and anemia occurred in 31% of 2,171 and 56% of 2,170 evaluable patients, respectively. Of the total 53 features, as few as 7 contributed at least 50% cImp, resulting in prediction accuracies of 70% or higher and area under the receiver operating characteristic curves of 0.886 for grade 3+ thrombocytopenia and 0.759 for grade 3+ anemia. Sensitivity analyses in strictly defined patient subgroups revealed similarly high predictive performance in full and reduced feature models. A logistic regression model with the same 50% cImp features showed similar predictive performance as RFC and good concordance with RFC probability predictions after isotonic calibration, adding interpretability. Collectively, this work demonstrates potential for machine learning prediction of AE risk in real‐world patients using few variables regularly available in EHRs, which may aid in clinical decision making and/or monitoring.