本文整理汇总了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
示例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
示例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
示例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)
示例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")