Probably the most optimal way to punish is to learn how to read your opponents. One of the things that I'm noticing is that mentality plays a big part when it comes to being focused, since being/getting frustrated will make you lose track of your focus, and jot out random moves. I'd say to just stay focused and keep track of the habits that your opponents tend to do, since it will help you in neutral. Once you focus and have an idea of the reactions that your opponents tend to do, you can mix-up your moves to get the same reaction and then punish them for it. Learning to adapt is important since not everyone is going to have the same linear playstyle, so keep that in mind. Spacing and neutral is the most important part, and your habit of spamming random moves is what's costing you stocks and games. Perfect shield practicing is great since it helps open up even more opportunities to punish your opponents.
This is how I did it. Eventually, I learned how to punish people since coming from Melee to Ultimate was somewhat of a difficult process, since there's no advanced techniques like L-canceling. I kept a positive mindset and mentality and focused during my matches to seek out any weaknesses/habits that my opponents kept doing, and punished them for it. It all comes down to how you position, and attack in neutral, but that's all up for you to decide since you're the player. It also comes from experience from using the kit your character possesses, since utilizing them will help you understand the situations to use them in. Mario has cape, fireballs, and FLUDD that can be used to his advantage, (ex: using FLUDD against an opponent's recovery that focuses more on vertical distance than horizontal, like Chrom and Little Mac's recovery, and cape off-stage to gimp recoveries like Fox's Illusion).
I know that this seems so little, but a mindset really does effect how well you play in the game, since a negative mindset will only hold you further back from your true potential. A positive mindset will help you focus and adapt to your opponents without frustrating you, although it is normal to still be frustrated.