【发布时间】:2018-01-17 12:20:45
【问题描述】:
问题陈述是:根据匹配技能(S1、S2、S3、S4)为项目(ABC、DEF、....)确定合适的人(X、Y、Z...) , S5, S6....)。
示例: 有一个人 X 精通 S1、S2、S3。 另一个精通 S4、S5、S6 的人 Y。 另一个精通 S1、S3、S5、S6 的人 Z。
然后有一个项目 ABC,它使用这些技能之一 - 比如说技能 S1。 所以我们应该能够识别项目 ABC 的人 X,因为它使用技能 S1。
同样,如果另一个项目 DEF 来了,需要技能 S5 和 S6,我们应该分配人员 Y 和人员 Z,因为技能匹配。
是否有一个等效的 python 可以以最好的方式实现这一点?
我试过这个:
import re, math
from collections import Counter
WORD = re.compile(r'\w+')
def get_cosine(vec1, vec2):
intersection = set(vec1.keys()) & set(vec2.keys())
numerator = sum([vec1[x] * vec2[x] for x in intersection])
sum1 = sum([vec1[x]**2 for x in vec1.keys()])
sum2 = sum([vec2[x]**2 for x in vec2.keys()])
denominator = math.sqrt(sum1) * math.sqrt(sum2)
if not denominator:
return 0.0
else:
return float(numerator) / denominator
def text_to_vector(text):
words = WORD.findall(text)
return Counter(words)
text1 = 'python, c, perl'
text2 = 'perl,c'
vector1 = text_to_vector(text1)
vector2 = text_to_vector(text2)
cosine = get_cosine(vector1, vector2)
print 'Cosine:', cosine
【问题讨论】:
-
试试你自己的,当卡住或发现这里提到的困难。这是好的做法
-
@all - 非常感谢您投反对票,但这并没有帮助解决问题,还是这样做了?也仅供参考 - 我尝试过 Pearson 相关关系,阅读有关 Levenshtein 距离以计算接近距离的信息,还通过了 difflab 和 Fuzzywuzzy 等 python 包。但想知道什么是正确的方法,而不是尝试一下。
标签: python comparison matching recommendation-engine