Heart failure is a critical condition with a high mortality rate, making accurate survival prediction essential for timely interventions. This study proposes an optimized machine learning approach using Gradient Boosting Machine (GBM) and Adaptive InertiaWeight Particle Swarm Optimization (AIW-PSO) to predict heart failure survival. The dataset, sourced from Kaggle, includes clinical features such as age, ejection fraction, and serum creatinine levels for 299 heart failure patients. To address the imbalance in survival outcomes, Synthetic Minority Over-sampling Technique (SMOTE) was employed to balance the dataset, followed by SelectKBest and Chi-square feature selection methods to retain the most significant predictors. The optimized hyperparameters for the GBM model were identified using the AIW-PSO algorithm, which effectively balanced exploration and exploitation by adaptively adjusting inertia weights. This approach outperformed traditional machine learning models, achieving a test accuracy of 94% with the optimized GBM. The study demonstrates the importance of hyperparameter tuning through metaheuristic algorithms and highlights the potential of AIW-PSO in enhancing model performance for clinical prediction tasks. These findings could have significant implications for clinical decision-making, offering a reliable tool for predicting patient outcomes in heart failure management.