title: Generating Markov transition matrix in Python
body: <p>Imagine I have a series of 4 possible Markovian states (A, B, C, D): </p>
  
  <pre><code>X = [A, B, B, C, B, A, D, D, A, B, A, D, ....]
  </code></pre>
  
  <p>How can I generate a Markov transformation matrix using Python? The matrix must be 4 by 4, showing the probability of moving from each state to the other 3 states.
  I've been looking at many examples online but in all of them, the matrix is given, not calculated based on data.
  I also looked into hmmlearn but nowhere I read on how to have it spit out the transition matrix. Is there a library that I can use for this purpose?</p>
  
  <p>Here is an R code for the exact thing I am trying to do in Python:
  <a href="https://stats.stackexchange.com/questions/26722/calculate-transition-matrix-markov-in-r">https://stats.stackexchange.com/questions/26722/calculate-transition-matrix-markov-in-r</a></p>