I think a lot of people get confused between loneliness & unhappiness. The term loneliness is used so broadly, some people in relationships consider themselves to be lonely, while some people not in relationships don't. Some people with friends feel lonely, and some do without.. And so on.
Unless you're actually alone and have no one around you then it's probably the reason of feeling as you do. If not then perhaps ask yourself if you feel like this ALL the time?
If you don't, then what are you doing when you aren't feeling this way? Doing a sport? Shopping? Gaming? Gyming? Reading? Writing?
Then ask yourself what you're doing when you feel this? Nothing? Trying too hard to socialise? Looking at how happy people come across on Facebook? watching romcoms?
Just try to analyse how you go about your life, and perhaps fill the times you feel unhappy with the things you actually enjoy doing.. Might help