Last active
October 11, 2023 16:55
-
-
Save quantra-go-algo/0d7d673d87b93f8ce803fa7dc2ba3bde to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create an HMM object with two hidden states | |
model = hmm.GaussianHMM(n_components = 2, covariance_type = "diag", n_iter = 100, random_state = 42) | |
# Create an array input for the HMM model | |
X = data[['R']].values | |
# Estimate the HMM model | |
results = model.fit(X) | |
# Use the Viterbi algorithm to find the fitted hidden states | |
data['states'] = results.predict(X) | |
# Count the number of days in which we find the two states | |
data['states'].value_counts() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment