You can just go to the document configuration menu and select the right modules. I can't tell you the exact text because I use lyx in spanish, but it should be something like: Document -> Document options Modules Number figures in sections
Using that LyX will do everything and you won't need to write anything in the preamble.