I have to admit that as many times I have read and watched Anne of Green Gables, I have no idea. I suppose it would be easy to say that Anne was born with her imaginative spirit and positive attitude. I know Anne discusses her past with Marilla in chapter 5 Anne's History but it doesn't help much. It seems like she would have met someone at Bolingbroke or Marysville that may have been influential, but this is never discussed.
Cordelia - Anne's imagination did indeed give her comfort in the years before Green Gables. Anne described two of her imaginary friends to Marilla in chapter 8. Katie Maurice lived in Mrs. Thomas' bookcase, and Anne dreamed of them going to a "wonderful place, all flowers and sunshine and fairies." When Anne moved in with the Hammond's, she discovered Violetta, an imaginary "echo girl" who Anne had "become so attached to." Memories of them were sacred to Anne and she remembered to "send them a kiss every day."