Advanced methods in data science are driving the characterization and control of nonlinear dynamical systems in optics. In this work, we investigate the use of machine learning, sparsity methods and adaptive control to develop a self-tuning fiber laser, which automatically learns and adapts to maintain high-energy ultrashort pulses. In particular, a two-stage procedure is introduced consisting of a machine learning algorithm to recognize different dynamical regimes with distinct behavior, followed by an adaptive control algorithm to reject disturbances and track optimal solutions despite stochastically varying system parameters. The machine learning algorithm, called sparse representation for classification, comes from machine vision and is typically used for image recognition. The adaptive control algorithm is extremum-seeking control, which has been applied to a wide range of systems in engineering; extremum-seeking is beneficial because of rigorous stability guarantees and ease of implementation.