What keyword density is, and what it is not
Keyword density is the number of times a phrase appears divided by the number of words in the text, expressed as a percentage. That is the whole definition, and every argument about the figure comes from the two halves of it rather than from the division: whether a two-word phrase is one occurrence or two words, and which words the total contains.
It is not a ranking factor, and no search engine publishes a density it prefers. The half a percent to two and a half percent band most guides quote is advice about writing - below it a page reads as a mention rather than a topic, above it a reader notices the repetition - so the verdicts on this page come from that band while saying out loud that it is advice. What a density is genuinely good for is finding accidents: the phrase that appears eleven times in the opening paragraph, the page written for a keyword that never appears in it, the two near-identical pages competing with each other.