Skip to content

Instantly share code, notes, and snippets.

@mylamour
Created December 18, 2018 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mylamour/1e930a10c1a9ab4e6f9206d813819d10 to your computer and use it in GitHub Desktop.
Save mylamour/1e930a10c1a9ab4e6f9206d813819d10 to your computer and use it in GitHub Desktop.
import numpy as np
from hmmlearn import hmm
from sklearn.datasets import load_iris,load_diabetes
from sklearn.metrics import accuracy_score
from sklearn.model_selection import train_test_split
CLASSES = 4
ITERATIONS = 100000
iris = load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
m1 = hmm.GaussianHMM(n_components=CLASSES, covariance_type="full", n_iter=ITERATIONS)
m1.fit(X)
y_pred = m1.predict(X)
print(accuracy_score(y,y_pred))
print("modele stand prob ", m1.startprob_)
m2 = hmm.GMMHMM(n_components=CLASSES, covariance_type="full", n_iter=ITERATIONS)
m2.fit(X)
y_pred = m2.predict(X)
print(accuracy_score(y,y_pred))
print("modele stand prob ", m2.startprob_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment