Microsoft Corp.’s $26.2 billion deal to buy LinkedIn Corp. is the latest turn in a race by the software giant and its competitors to mine vast quantities of data—searches, emails, social networks, browsing behavior—for insights that would help their products serve and even anticipate customer needs.

Microsoft, Apple Inc. and Alphabet Inc. are moving deeper into using machine learning, in which computers rapidly examine existing information in search of patterns that their products can use to understand new information as...