The electricity grid has added many renewable and non-renewable energy sources to meet expanding demand. Sudden load variations exacerbate generator, transmission line, and distribution network issues. Load modelling choices are crucial for system prediction. This study indicates that ZIP load models with contingency criteria can accurately forecast load behaviour over time. The NR method predicts the contingency ranking with the High Bride Line Stability Ranking Index (HLSRI) under single line outage conditions, and an artificial neural network (ANN) is trained to predict the severity of the line outage and the system's behaviour. A mathematical model was utilised to analyse stability and cost with and without the UPFC and IPFC. Machine learning (ML) is used to rapidly predict the most affected transmission line during a contingency by clustering data using the J48 algorithm for the location of compensating devices. The PSO algorithm is used to develop an objective function to minimise fuel costs by maximising generating capacity. A transmission line failure and load variation might damage the electrical system. This study prioritises transmission line breakdowns and load changes. Power system security analysis provides power system status.