It may be possible to change it via your Google or other device account by logging in to the account on another device, otherwise you may have to factory reset, an unavoidable consequence of forgetting such a small but important thing. All personal data not backed up would be lost.
In the future, keep something like KeePass on your phone (the Android version is called Keepass2Android Password Safe) and keep the password file on Google Drive (that way, all your devices share the same password file). So if you forget the password for your phone, use a PC to look it up. (I had to reboot my PC this morning, and forgot the password, so I looked it up on my phone.)