1st image is my code and 2nd image is error. can anyone explain?

Seems a bit unusual, can you try one thing…
Just take all the code out of fit function, and run that cell directly, without any need to call fit()

got the error

for param in parameters() should have been

for param in fn.parameters()