What to do when you spend several months working on an idea that fails in a masters thesis?
Step 1: Don't panic

I was in a similar situation halfway through my MSc. I was in a panic, sure that my academic career was in ruins. My supervisor calmed me down, reminded that a negative result was still a result, and and told me that a for a master's degree, it was not strictly required that I make a scientific contribution or have a publication. In the worst case, in my thesis I would present my negative results, explain why this technique didn't work, and suggest what could be done differently by future researchers. (Once I was relaxed enough to think clearly, I came up with new things to try, and everything worked out grand.)

I suggest you discuss the "worst case scenario" with your supervisor; you'll probably find out it's not as bad as you think. Remember that this is research: positive results are not guaranteed.

Step 2: Think about why this technique isn't working.

I'm sure you've learned something about why your technique isn't working. That should give you some ideas for what to try next. If you're out of ideas, sit a friend down and explain everything to them. The friend doesn't need to know anything about machine learning; they're just a sounding board. The naive questions they ask may give you ideas. Maybe you need a week off to recharge your batteries.

Step 3: Try something new.

Take those new ideas you got in step 2, and apply them. But now that you're more experienced, think about how you could find out more quickly if the idea is feasible, so you can change tack again if needed.