0

I'm making a weather prediction program in Python using a Markov chain. The programs asks the user for input on past days' weather and predicts the next seven days.

I was wondering how I can change my transition matrix so it uses the percentages of how often the specified pair happens i.e. 'DD' 'DR' 'RR' 'RD' rather than default probability as I have shown below.

#Possible sequences of events
transitionName = [["DD","DR"],["RR","RD"]]

pastweather = input("Enter a string of D's and R's to represent dry/rainy days: ")

#transition matrix
transitionMatrix = [[0.8,0.2],[0.4,0.6]]
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Joe
  • 21
  • 1
  • 4

1 Answers1

2

I'm not sure if a Markov chain is the most suitable tool here. In general, a Markov model has no memory, i.e. the next transition depends only on the current state (dry or rainy) and you want to do a seven day forecast...

However, concerning your questions about the calculation of the transition matrix I would suggest the following approach:

Let's consider a user's input like : DDDRDD

  • Overall there are five transitions.
  • There are three transitions D->D
  • There is one transition D->R
  • There is one transition R->D

Prerequisites:

  • All transitions starting with D have to sum up to 1.
  • All transitions staring with R have to sum up to 1.

Therefore, the probability for D->D according to the input string would be 3/4. The probability for D->R would be 1/4. Probability R->D is 1 and R->R is 0 - as there was no transition in the input string from R -> R.

hatze
  • 521
  • 4
  • 12