Riot how exactly does the Mastery scoring work??
Riot specifically stated they aren't letting anyone know exactly how it works so it can't be exploited.
Riot has also stated grading works in several ways to counter people exploiting how it works to game the system.
How it works in general is that if you pick, say, Annie support you are then compared to all the Annie supports in your region and graded based on how well you did vs. everyone else playing Annie support.
What exactly Riot is comparing in their formula is up for debate, but seeing as they don't have to show off a sleek and sexy tooltip or easily digestible explanation: the math involved is probably pretty complex, and the stats compared are clearly more than just your K/D ratio. KDA at the very least is taken into account along with CS, and it's quite likely things like kill-participation, warding, and game length are all considered as well.