多类别分类的阈值

时间:2020-07-08 08:22:26

标签: python keyword threshold multiclass-classification

我目前正在从事多类别分类项目。在该方法中,每个类别均由词典列表定义,词典中的每个术语均由代表性权重或得分定义,该权重或得分由统计量(例如TF-IDF)确定。

我的问题如下:是否有一种简单的方法来确定每个类别的适当阈值,尤其是根据术语的权重来对文档进行分类?

欢迎提出所有建议。

感谢一切!

编辑:


tf_ = TfidfVectorizer(norm='l2',min_df=0, use_idf=True, smooth_idf=False, sublinear_tf=True, tokenizer=tokenize)
tfidf_matrix = tf_.fit_transform(corpus_theme)

feature_names = tf_.get_feature_names()
sorted_tfidf = {theme: {} for theme in themes_uniq}

for theme in themes_uniq:
    print('\nThème : {0}'.format(theme))
    
    index = theme_match[theme]
    feature_index = tfidf_matrix[index,:].nonzero()[1]
    tfidf_scores = zip(feature_index, [tfidf_matrix[index, x] for x in feature_index])

    res = {}
    
    for w, s in [(feature_names[i], s) for (i, s) in tfidf_scores]:
        res[w] = s

    res = {k: v for k, v in sorted(res.items(), key=lambda item: item[1], reverse=True)}
    res = take(5, res.items())
    sorted_tfidf[theme] = {item[0] : item[1] for item in res if item[0] in dictdump['lexicons'][theme].keys()}
    

    for key, pair in enumerate(res):
        print('{0} : {1}'.format(pair[0], str(pair[1])))

--------------------------------------------------------------

Results :

Theme : Environnement
pollution : 0.22100993944113367
biodiversité : 0.21461866899564078
émissions : 0.19949436710171628
pétrole : 0.1509508724016146
giec : 0.14255687423527078

Theme : Sport
championnat : 0.24159536867091702
coupe : 0.20204707419916948
olympiques : 0.1954497772157803
match : 0.1815176328907646
finaliste : 0.17407788073364622

Theme : Politique
scrutin : 0.14487046470551654
législatives : 0.14487046470551654
libéralisme : 0.14217858901989705
candidature : 0.1372912061161422
candidat : 0.1329112819463253

Etc.

因此,对于我的每个类别(总共17个),我都有一个加权的词典列表。我现在正尝试根据这些信息对将来的文档进行分类,但是我不知道如何确定每个类别的阈值,这使我可以说文档1属于“环境”和“运动”,因为它包含具有如此权重的单词。

0 个答案:

没有答案