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


Python Feature.extract方法代码示例

本文整理汇总了Python中feature.Feature.extract方法的典型用法代码示例。如果您正苦于以下问题:Python Feature.extract方法的具体用法?Python Feature.extract怎么用?Python Feature.extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在feature.Feature的用法示例。


在下文中一共展示了Feature.extract方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_score

# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import extract [as 别名]
 def get_score(self, msg):
     Feature.extract(msg)
     score = 0.0
     for (f, w) in self.feature_weight.items():
         if f in msg.feature:
             score += msg.feature[f] * w
     return score
开发者ID:Kelvin-Zhong,项目名称:sns-router,代码行数:9,代码来源:score.py

示例2: _weight_feature

# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import extract [as 别名]
 def _weight_feature(self, msg):
     Feature.extract(msg)
     score = 0.0
     for i in range(len(self.feature_name)):
         f = self.feature_name[i]
         w = self.w[i]
         if f in msg.feature:
             score += msg.feature[f] * w
     return score
开发者ID:fqj1994,项目名称:sns-router,代码行数:11,代码来源:autoweight.py

示例3: msg2X

# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import extract [as 别名]
    def msg2X(self, samples):
        '''
        Convert messages to data matrix format. 

        X: A dict. See explanation of _G()
        '''
        X = {}
        for m in samples.values():
            Feature.extract(m)
            x = []
            for name in self.feature_name:
                x.append(m.feature[name])
            X[m.msg_id] = x
        return X
开发者ID:fqj1994,项目名称:sns-router,代码行数:16,代码来源:autoweight.py

示例4: __init__

# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import extract [as 别名]
 def __init__(self, samples, order, init_weight, learner):
     super(AutoWeight, self).__init__()
     self.samples = samples
     self.order = order
     self.learner = learner
     if init_weight is None:
         # Use one of the samples keys as sets of features to be trained. 
         # This is deprecated. Whenever possible, please init your features
         # with weight in 'weights.json'
         m = samples.values()[0]
         Feature.extract(m)
         self.feature_name = m.feature.keys()
     else:
         self.feature_name = init_weight.keys()
     self.X = self.msg2X(samples)
     if init_weight is None:
         self.w = self.initw(self.init_weight_kendall(self.feature_name, self.samples, self.order))
     else:
         self.w = self.initw(init_weight)
开发者ID:fqj1994,项目名称:sns-router,代码行数:21,代码来源:autoweight.py

示例5: export_arff

# 需要导入模块: from feature import Feature [as 别名]
# 或者: from feature.Feature import extract [as 别名]
def export_arff(message_list, ds_name, fn_arff):
    '''
    Export message_list to Weka's arff file

    ds_name: the name of data set. Shown in first line 
             of arff file.
    '''

    all_tags = json.loads(open('tag_mapping.json').read())
    all_tags_r = {}
    for (k, v) in all_tags.iteritems():
        all_tags_r[v] = k
    all_tags_r[0] = "null"

    with open(fn_arff, 'w') as fp:
        fp.write("@relation %s\n\n" % (ds_name))
        fn = []

        # Write schema
        fp.write("@attribute id numeric\n")
        for fe in Feature.feature_extractors:
            for (f, t) in fe.schema.iteritems():
                fp.write("@attribute %s %s\n" % (f, t))
                fn.append(f)
        fp.write("@attribute class {%s}\n" % (",".join(all_tags.keys())))

        # Write data
        fp.write("\n\[email protected]\n")
        for m in message_list:
            # Ignore multi tagged messages for simplicity
            if len(m.tags) == 1:
                i = str(m.msg_id)
                t = all_tags_r[m.tags.keys()[0]]
                Feature.extract(m)
                fields = [str(m.feature[f]) for f in fn]
                fields.insert(0, i)
                fields.append(t)
                fp.write(",".join(fields) + "\n")
开发者ID:fqj1994,项目名称:sns-router,代码行数:40,代码来源:select_samples.py


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