Across 350 million years of fish evolution, schooling appeared about 60 times—and vanished roughly 320 times. That pattern, uncovered in a new study of 2,839 fish species, challenges the idea that animals rarely lose collective behaviors once they evolve.

Fish schooling is familiar, but tracing how it began and changed across the history of life has been difficult. Earlier studies of collective behavior usually covered only one or two species at a time. The new research, published Nov. 6 in the Proceedings of the National Academy of Sciences, uses machine learning to examine schooling across nearly 10% of the 39,000 living fish species. The authors describe it as one of the largest studies of the evolution of behavior across species.

Researchers trained a text-based machine learning system to read scientific descriptions of fish behavior and turn them into data. They also analyzed citizen science photos and videos, including images from iNaturalist and other sources. Computer tools helped map fish in three dimensions and estimate the direction each one was swimming. Researchers could then check whether nearby fish were aligned and moving together.

The team found that different fish lineages independently developed the ability to move together about 60 times. But they also found around 320 losses of schooling. In some cases, a lineage that included schooling fish gave rise to a descendant species that lived alone.

“That’s simply not true” is how senior author Andrew Hein, an associate professor of computational biology at Cornell University’s College of Agriculture and Life Sciences, described the old belief that losses of collective behavior are rare. First author Jay Love, a postdoctoral researcher in Hein’s lab, said the study let the team test ideas about why schooling evolves across a much wider range of fish than earlier work could cover.

One idea is that schooling helps fish avoid predators or defend themselves through safety in numbers. The researchers found that species lower in the food chain were more likely to move collectively. But the link was not absolute: many small prey species did not school, and some species higher in the food chain did. That points to several influences on whether schooling evolves or disappears, rather than one simple rule.

The researchers also examined whether schooling might help fish find scarce resources. The source material does not give the result of that test, so the finding cannot be stated here. Even so, the study’s broader advance is clear: machine learning made it possible to compare behavior across thousands of species and a vast span of evolutionary time. The same approach could help scientists ask large-scale questions about other behaviors, from birds flocking to animals living or feeding together.