Seismic prediction of fluid and lithofacies distribution is of great interest to reservoir characterization, geologic model building, and flow unit delineation. Inferring fluids and lithofacies from seismic data under the framework of machine learning is commonly subject to issues of limited features, imbalanced data sets, and spatial constraints. As a consequence, an extreme gradient boosting-based workflow, which takes feature engineering, data balancing, and spatial constraints into account, is proposed to predict the fluid and lithofacies distribution by integrating well-log and seismic data. The constructed feature set based on simple mathematical operations and domain knowledge outperforms the benchmark group consisting of conventional elastic attributes of P-impedance and ratio. A radial basis function characterizing the weights of training samples according to the distances from the available wells to the target region is developed to impose spatial constraints on the model training process, significantly improving the prediction accuracy and reliability of gas sandstone. The strategy combining the synthetic minority oversampling technique and spatial constraints further increases the F1 score of gas sandstone and also benefits the overall prediction performance of all of the facies. The application of the combined strategy on prestack seismic inversion results generates a more geologically reasonable spatial distribution of fluids, thus verifying the robustness and effectiveness of our workflow.