Plasma density is an important factor in determining wave-particle interactions in the magnetosphere. We develop a machine-learning-based electron density (MLED) model in the inner magnetosphere using electron density data from Van Allen Probes between September 25, 2012 and August 30, 2019. This MLED model is a physics-based nonlinear network that employs fundamental physical principles to describe variations of electron density. It predicts the plasmapause location under different geomagnetic conditions, and models separately the electron densities of the plasmasphere and of the trough. We train the model using gradient descent and backpropagation algorithms, which are widely used to deal effectively with nonlinear relationships among physical quantities in space plasma environments. The model gives explicit expressions with few parameters and describes the associations of electron density with geomagnetic activity, solar cycle, and seasonal effects. Under various geomagnetic conditions, the electron densities calculated by this model agree well with empirical observations and provide a good description of plasmapause movement. This MLED model, which can be easily incorporated into previously developed radiation belt models, promises to be very helpful in modeling and improving forecasting of radiation belt electron dynamics.