One of the leading causes of maternal death is ectopic pregnancy (EP), which is defined as the implantation and growth of the embryo outside of the uterus. Early diagnosis and treatment are therefore essential. Unfortunately, practitioners cannot rely on specific clinical symptoms or laboratory findings to predict the likelihood of these uncommon presentations. As a result, the radiologist plays a critical role in making a prompt diagnosis, with ultrasonography being pivotal in detecting rare EP. Enhancing a machine learning model for the purpose of categorizing and segmenting EP in tubal, cervical, and ovarian tissues from ultrasound images is the main objective of this research. Using recurrent neural networks, the research uses Long Short-Term Memory (LSTM) networks to diagnose EP. To find the ideal hyperparameters, it incorporates the Mutated Black Widow Optimisation (MBWO) algorithm. The results demonstrate that the MBWO-configured machine learning diagnostic model achieves an accuracy of 98%, surpassing competing techniques. Furthermore, for segmentation, the MBWO-associated modified region-growing approach attains an average recall measure of 93.98% for tubal, cervical, and ovarian EP. Therefore, the proposed machine learning diagnostic model reduces the risk of complications and increases the patient's likelihood of receiving the most suitable treatment.