我已经为名为tech_raw_data['Product lower']
的pandas dataframae列生成了BoW。你知道吗
count_vect = CountVectorizer()
smer_counts = count_vect.fit_transform(tech_raw_data['Product lower'].values.astype('U'))
smer_vocab = count_vect.get_feature_names()
为了测试字符串与这个BoW向量的相似性,我在dataframe的列中只为一个条目toys['ITEM NAME']创建了BoW。你知道吗
toys = pd.read_csv('toy_data.csv', engine='python')
print('-'*80)
print(toys['ITEM NAME'].iloc[0])
print('-'*80)
inp = [toys['ITEM NAME'].iloc[0]]
cust_counts = count_vect.transform(inp)
cust_vocab = count_vect.get_feature_names()
检查相似性:
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()
for x in cust_counts[0].toarray():
for y in smer_counts.toarray():
ratio = similar(x, y)
#print(ratio)
if ratio>=0.85:
should print the string corresponding to BoW y
现在,每当匹配比超过0.85时,我需要打印与tech_raw_data['Product lower']
数据帧中的smer_counts
对应的字符串。你知道吗
枚举
smer_counts.toarray()
返回的numpy数组,并在ratio>=0.85
返回时使用索引来获取tech_raw_data
数据帧中的相应文本。你知道吗这是有效的,因为
len(smer_counts.toarray()) == len(tech_raw_data)
以及数据帧中记录的顺序都被保留。你知道吗相关问题 更多 >
编程相关推荐