Miners want to earn as much as possible. So there is a default algorithm in Bitcoin called "getBlockTemplate" that picks the most rewarding transactions first, in order. This is what the Mempool app is doing when it sorting the transactions by transaction fees with highest fee first in line.
So we are merely guessing that miners will pick and it usually hits 97%+ accuracy because not all mempools are the same, there is delay in the network and miners could also manually pick transactions we can't predict.