New materials are an important driving force for social development. In recent years, attention on boron-containing materials is growing in the fields of new energy and catalysis, and calls for compelling need for in-depth study of their structure-property relationship to contribute to the research and development of boron-containing materials. In this work, on the aware of the shift of materials research from traditional trial-and-error paradigm to data-driven research paradigm, we explored the application of ten important machine learning algorithms in the prediction of band gaps of boron-containing materials through feature selection (Pearson correlation analysis), grid search-based optimization (Model optimal parameters), and feature importance analysis (interpretability analysis of the model). The results show that the band gap prediction model using the Random Forest algorithm outperforms the other models with a 84% prediction accuracy, and the total magnetization of boron-containing materials is identified to significantly correlate negatively with the band gap, i.e. the smaller the total magnetization of the material, the larger its band gap. The advantage of the Random Forest algorithm over other models is that it is better able to capture correlations between features. For example, the linear model is unable to detect the importance of the total magnetization of boron-containing materials from the material features, thus leading to a lower model prediction performance. This work shows that machine learning methods can be used to guide the design of boron-containing materials with specific band gap. Meanwhile, the results also show that, as an integrated learning model, Random Forest has good learning ability and stable prediction performance, and can be applied to the prediction of band gap and other material properties of other types of material systems, accelerating the design and optimization process of material properties, and is of great scientific significance for the rapid screening and high-performance prediction of new functional materials.