Variational approach for learning Markov processes from time series data