Gravity data inversion is of critical importance in geophysics, encompassing a range of applications, such as the exploration of geological resources, the identification of geological structures, and the detection of groundwater resources. This study proposes a three-dimensional (3D) machine learning approach to enhance the efficiency of the aforementioned exploration tasks by leveraging gravity data. The mapping relationship between gravity data and subsurface density structures is modeled by the broad learning network, distinguished by its high training efficiency and robust modeling capability. Notably, the proposed inversion method obviates the constraints on the number of anomalies prior to the inversion process. This is achieved by setting one anomaly with varied locations for different training samples. Numerical and field data applications demonstrate the efficiency of the proposed 3D machine learning gravity data inversion method, especially in automatically determining the number of anomalies. In particular, the proposed method produced accurate density inversion results in the field application, aiding in the identification of potential oil and gas reservoirs in the target region and offering the potential for broader application in other resource exploration. The proposed inversion method can promote the construction of density structures of subsurfaces based on gravity data.