We report on the application of machine learning (ML) methods for predicting and optimizing the e-beam distribution of particle accelerators, with a focus on proof-of-principle studies aimed at future applications in the FACET-II linac (including longitudinal phase space prediction and round-to-flat beam transforms). The approach consists of training ML-based virtual diagnostics to predict the e-beam distribution using only nondestructive linac and beam measurements as inputs. We study this approach in start-to-end simulations for the FACET-II linac and show its feasibility in a proof of principle experiment at the LCLS. The e-beam longitudinal phase space images at LCLS are obtained with a transverse deflecting cavity and used as training data for our ML model. We also present initial results obtained at the UCLA Pegasus beamline, where ML models were used to predict and optimize the e-beam spot size ratios in a round-to-flat beam transformation set up. We discuss the sensitivity of these ML models to input uncertainties, drift and noise and comment on opportunities for integrating such diagnostics in existing and future accelerator facilities.