This paper introduces the magnetic neural gas (MNG) algorithm, which extends unsupervised competitive learning with class information to improve the positioning of radial basis functions. The basic idea of MNG is to discover heterogeneous clusters (i.e., clusters with data from different classes) and to migrate additional neurons towards them. The discovery is effected by a heterogeneity coefficient associated with each neuron and the migration is guided by introducing a kind of magnetic effect. The performance of MNG is tested on a number of data sets, including the thyroid data set. Results demonstrate promise.