Instead of getting angry, you can simply leave politely, and keep your dignity. That is, if you are absolutely sure they won't hire you. You'd have to have very clear unmistakable evidence for that.

Without such external evidence, you don't know if they really won't hire you. There may be all kinds of reasons for the interviewers' behavior. You don't know what is going on in the interviewers minds, how you compare to other candidates, and what conclusions they will draw.  Taking that into account, you can rarely make a correct preemptive judgement, and without forming such a judgement, there is no reason to become angry.

Both anger and leaving early will **guarantee** that you do not get the job, so they are the poorest choices strategically if you actually want the job.

<sub>Edit, from comment:</sub>
> *OP:* A interviewer might say oh you have no experience with Y and we want someone with X, then [...] I put all this effort trying to learn interview question and the unfairness of the situation, make me get confrontational with the interviewer

There is nothing "unfair" in what you are describing. The purpose of the interview is to find out if you match the job, not to test how well you learned interview questions. Despite a lack in some areas, they might still hire you. And sometimes the interview will show that that you and the employers aren't a good match, which is normal, and if you acknowledge that, it should leave little reason for angry outbursts.