# Can HMM, MRF, or CRF be used to classify the state of a single observation, not the entire observation sequence?

I learn that the Viterbi algorithm used for Hidden Markov Model (HMM) can classify a sequence of hidden states from the corresponding observations; Markov Random Field (MRF) and Conditional Random Field (CRF) can also do it.

Can these algorithms be used to classify a single future state?

Yes this is possible and is exactly what a Markov process aims to accomplish.

The Hidden Markov Model can be considered a simple dynamic Bayesian network. This means that it will generate a probabilistic outcome for a number of states (classes) given a sequence of inputs.

This can be used for a classification task based on a threshold probability to make a confirmed decision.

Let's take a simple example The above example is a model to determine how a person will be feeling given some sample data of the previous days.

# Sample data
data = ['Healthy', 'Healthy', 'Fever']


Using this data, it's possible to calculate the probability of each possible state (outcome).

# Probability after 2 Healthy and 1 Fever day
P = 0.6 * 0.7 * 0.3

# Final day state 'Fever'
# Calculating probabilities for each state
Dizzy  = P * 0.6
Cold   = P * 0.3
Normal = P * 0.1


We can calculate the probability of each state and this will be unique for every unique sequence of historical data.

• Do you have example code? Jun 19 '19 at 18:44
• Code for this example? Or in general? The issue is that HMMs are not easy to generate. The probabilities, specified in the example are dummies, in a real use case, those values will have to be computed statistically from a large dataset before the model can be used. Jun 19 '19 at 21:05
• code in general is fine. I’ve tried a python package, but I can only do decoding to get a sequence of states, while I want to get the state of a single input. Jun 20 '19 at 0:21