Apparatus for numerically controlling a machine tool with a learning mode