We look at the keywords a domain ranks for (or buys) and then find the competitors whose own paid or organic rankings closely match the same keywords.
However, there more to it to give you more relevant results.
While Amazon is going to have the same keywords that a specialty shop like baseballexpress.com does, we consider domains like homerunmonkey.com and baseballrampage.com to be closer competitors because a larger portion of their keywords match what baseballexpress.com has.