One of the most important elements that appears in Shakespearean plays is the inclusion of a tragic flaw on the part of the "hero." The protagonist of the play is usually an extraordinary person who is nevertheless impaired by a large flaw. In this case, Macbeth's flaw is his ambition.
In the play, Macbeth's ambition turns him into a less likeable character. However, towards the end of the story, he begins to show positive qualities once more. The purpose of this is to encourage the audience to feel sympathy for Macbeth. Moreover, his flaws and regret make him a more realistic and relatable character, which contributes to the effect of the story.