For His own glory. That is quite clear in many places in Scripture. However, you would be hard pressed to support your notion that He did so out of loneliness, because He needed love, or due to any other "need" that He might have. A "needy" God is no God, the God that I worship is complete and lacking nothing.