Time-dependent speciation and extinction from phylogenies: a least squares approach