Your post is hard to read because of the way you have formatted the code. Could you enclose code between two lines, where each line has just three consecutive back-ticks on it? The back-tick is this character: ` . It may be on the same key as the tilde, ~ .  It is not the same as the single quote (’) or the double quote ("). (You can just copy-paste the above back-tick, if you can’t find it on your keyboard.) Also, don’t use one single quote and a double quote together, instead of three back-ticks! That doesn’t work, as you can see from the way your post looks.
So the formatting will look like this:
line1 with just three back-ticks one after the other
your code goes here
line2 with just three back-ticks one after the other
Also: could you show the line where you call your train() function?