Speciation through the learning of habitat features