ABSTRACT We present a new method of predicting the ages of galaxies using a machine learning (ML) algorithm with the goal of providing an alternative to traditional methods. We aim to match the ability of traditional models to predict the ages of galaxies by training an artificial neural network (ANN) to recognize the relationships between the equivalent widths of spectral indices and the mass-weighted ages of galaxies estimated by the magphys model in data release 3 (DR3) of the Galaxy and Mass Assembly (GAMA) survey. We discuss the optimization of our hyperparameters extensively and investigate the application of a custom loss function to reduce the influence of errors in our input data. To quantify the quality of our predictions we calculate the mean squared error (MSE), mean absolute error (MAE) and R2 score for which we find MSE = 0.020, MAE = 0.108 and R2 = 0.530. We find our predicted ages have a similar distribution with standard deviation σp = 0.182 compared with the GAMA true ages σt = 0.207. This is achieved in approximately 23 s to train our ANN on an 11th Gen Intel Core i9-11900H running at 2.50 GHz using 32 GB of RAM. We report our results for when light-weighted ages are used to train the ANN, which improves the accuracy of the predictions. Finally, we detail an evaluation of our method relating to physical properties and compare with other ML techniques to encourage future applications of ML techniques in astronomy.