Can a bad grade in a class be negated by a good grade in a more advanced class? I am an undergraduate who is expecting a mediocre grade in my optimization class this semester (roughly B-), which is in significant contrast to my near straight A transcript. Unfortunately, I want to do a PhD in machine learning and so I expect this grade to be viewed in a negative light by graduate admissions committees due to the relevance of the material and the aforementioned contrast. But I will take an advanced graduate level machine learning course this coming semester which has the optimization course as a prerequisite. Will a good performance in this  graduate level class negate my mediocre grade in my optimization class? In general, can (and will) good grades in more advanced classes negate bad grades in prerequisite classes in the context of graduate admissions? To what extent? I understand that each admissions committee will view this situation differently. I am looking for a general opinion.
In general, can (and will) good grades in more advanced classes negate bad grades in prerequisite classes in the context of graduate admissions?


Only to a very limited extent. Getting a C (or F) in calculus during Freshman year is likely to be completely ignored if you got straight As after that. Other than in such extreme examples, no, I would not expect to be able to negate past grades. But of course, each grade is only one data point, and additional data points can significantly improve your overall record. 


  roughly B-, which is in significant contrast to my near straight A transcript.


So, this is an outlier. Like in any other sort of data analysis, a single outlier in an otherwise homogeneous record is unlikely to have much/any effect. Sure, getting a good grade in the more advanced course could make it even more clear that this outlier was not related to the subject. But it seems like you are already on track to get put in the highest "tier" with respect to GPA, so you may want to consider investing time on the other facets of your application.