本文整理汇总了Python中hmm.HMM.learn_from_observations方法的典型用法代码示例。如果您正苦于以下问题:Python HMM.learn_from_observations方法的具体用法?Python HMM.learn_from_observations怎么用?Python HMM.learn_from_observations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hmm.HMM
的用法示例。
在下文中一共展示了HMM.learn_from_observations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: train_N_state_hmms_from_data
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import learn_from_observations [as 别名]
def train_N_state_hmms_from_data(filename, num_states, debug=False):
""" reads all the data, then split it up into each category, and then
builds a separate hmm for each category in data """
dataset = DataSet(filename)
category_seqs = split_into_categories(dataset)
# Build a hmm for each category in data
hmms = {}
for cat, seqs in category_seqs.items():
if debug:
print "\n\nLearning %s-state HMM for category %s" % (
num_states, cat)
model = HMM(range(num_states), dataset.outputs)
model.learn_from_observations(seqs, debug)
hmms[cat] = model
if debug:
print "The learned model for %s:" % cat
print model
return (hmms, dataset)
示例2: task
# 需要导入模块: from hmm import HMM [as 别名]
# 或者: from hmm.HMM import learn_from_observations [as 别名]
def task(self):
num_states = range(1, MAX_NUM_HIDDEN_STATES)
filename = "weather_bos_la.data"
dataset = DataSet(filename)
category_seqs = split_into_categories(dataset)
boston_seqs = category_seqs["boston"]
likelihoods = []
for N in num_states:
model = HMM(range(N), dataset.outputs)
ll = model.learn_from_observations(boston_seqs, False, True)
likelihoods.append(ll[-1])
chart = {"chart": {"defaultSeriesType": "line"},
"xAxis": {"title": {"text": "number of hidden states"},
"categories": num_states},
"yAxis": {"title": {"text": "Fraction Correct"}},
"title": {"text": "log likelihood of HMMs"
" modeling boston weather"},
"series": [{"name": "boston training data",
"data": likelihoods}]}
return chart