本文整理汇总了Python中hmm.HMM.learn_from_labeled_data方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.learn_from_labeled_data方法的具体用法?Python HMM.learn_from_labeled_data怎么用?Python HMM.learn_from_labeled_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.learn_from_labeled_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_hmm_learning
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import learn_from_labeled_data [as 别名]
def test_simple_hmm_learning(self):
state_seq = [[0, 1, 1, 0, 1, 0, 1, 1], [0, 0, 1, 0]]
obs_seq = [[0, 0, 1, 1, 0, 0, 0, 1], [0, 1, 0, 0]]
hmm = HMM(range(2), range(2))
hmm.learn_from_labeled_data(state_seq, obs_seq)
print hmm
eps = 0.00001
self.assertTrue(max_delta(hmm.initial, [0.750000, 0.250000]) < eps)
self.assertTrue(max_delta(hmm.transition, [[0.285714, 0.714286], [0.571429, 0.428571]]) < eps)
self.assertTrue(max_delta(hmm.observation, [[0.625000, 0.375000], [0.625000, 0.375000]]) < eps)
示例2: train_hmm_from_data
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import learn_from_labeled_data [as 别名]
def train_hmm_from_data(data_filename, debug=False):
if debug:
print "\n\nReading dataset %s ..." % data_filename
data_filename = normalize_filename(data_filename)
d = DataSet(data_filename)
#if options.verbose:
# print d
if debug:
print "Building an HMM from the full training data..."
hmm = HMM(d.states, d.outputs)
hmm.learn_from_labeled_data(d.train_state, d.train_output)
if debug:
print "The model:"
print hmm
return (hmm, d)