当前位置: 首页>>代码示例>>Python>>正文


Python HMM.learn_from_observations方法代码示例

本文整理汇总了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)
开发者ID:jmdupont,项目名称:Stanford-Machine-Learning-Course,代码行数:22,代码来源:classify.py

示例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
开发者ID:jmdupont,项目名称:Stanford-Machine-Learning-Course,代码行数:26,代码来源:task_hmm.py


注:本文中的hmm.HMM.learn_from_observations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。