Accurate evaluation of coalbed methane (CBM) content is crucial for effective exploration and development. Traditional gas content measurement methods based on laboratory analysis of drill core samples are costly, whereas geophysical logging methods offer a cost-effective alternative by providing continuous high-resolution profiles of rock layer physical properties. However, the relationship between CBM content and geophysical logging data is complex and nonlinear, necessitating an advanced prediction method. This study focuses on the No. 3 coal seam in the Shizhuang South Block of the Qinshui Basin, utilizing geophysical logging data and 148 sets of laboratory core samples. We employed the Random Forest (RF) method optimized with a simulated annealing-genetic algorithm (SA-GA) to develop the SA-GA-RF model for evaluating CBM content. The model's performance was validated using test data and new CBM well data, and it was applied to calculate the vertical gas content profiles of No. 3 coal seam across 128 wells. The SA-GA-RF model demonstrated an average relative error of 13.13% in the test data set, outperforming Backpropagation Neural Network (BPNN), Least Squares Support Vector Machine (LSSVM), Extreme Learning Machine (ELM), and multivariate regression (MR) methods. The model also exhibited strong generalizability in new wells and improved model-building efficiency compared to traditional cross-validation grid search methods. The construction of a three-dimensional CBM content model, incorporating well coordinates and elevation data, allowed for detailed identification of high gas content areas and layers. This three-dimensional model offers a more precise characterization than traditional two-dimensional isopleth maps, providing valuable insights for CBM exploration, reserve evaluation, and production optimization.