Beispiel #1
0
new_test = np.asarray(test_set)

predictions = []

chunk = train_set[2500:]
'''find prob for each test point, compare to expected, then re-fit HMM with it'''
for idx, x in enumerate(chunk):
  _, pst_prob = model.score_samples([x])
  max_ind = pst_prob.argmax()
  trn = model._get_transmat()[max_ind]

  '''Get the max one for now. Maybe use some other method later one'''
  max_trn = trn.argmax()

  cov = model._get_covars()[max_trn]
  mns = model._get_means()[max_trn]
  rd = np.random.multivariate_normal(mns, cov)

  int_rd = [int(x) for x in rd]
  predictions += [int_rd]

  # retrain HMM with new data point
  moving_idx = 30-idx
  mov_train_set = []
  if moving_idx < 1:
    mov_train_set = []
  else: mov_train_set = train_set[-moving_idx:]

  mov_new_set_idx = 0
  if idx >= 30:
    mov_new_set_idx = idx-30