machine-learning - TF-IDF提取关键词

标签 machine-learning scikit-learn nlp tf-idf

处理函数有点像这样:

def get_feature_name_by_tfidf(text_to_process):
    with open(master_path + '\\additional_stopwords.txt', 'r') as f:
        additional_stop_words = ast.literal_eval(f.read())
    stop_words = text.ENGLISH_STOP_WORDS.union(set(additional_stop_words))
    tf = TfidfVectorizer(analyzer='word', ngram_range=(1, 4), min_df=0, stop_words=stop_words)
    tfidf_matrix = tf.fit_transform(text_to_process.split(','))
    tagged = nltk.pos_tag(tf.get_feature_names())
    feature_names_with_tags = {k: v for k, v in dict(tagged).items() if v != 'VBP'}
    return list(feature_names_with_tags.keys())

返回传递文本中的关键字列表。 有没有什么方法可以让关键字与提供的情况相同? 就像传递的字符串

输入:

a = "TIME is the company where I work"

不要将关键字列表获取为:

['time', 'company']

我喜欢得到:

['TIME', 'company']

最佳答案

默认情况下,TfidfVectorizer 将单词转换为小写。使用此行:

  tf = TfidfVectorizer(analyzer='word',lowercase=False, ngram_range=(1, 4), min_df=0, stop_words=stop_words)  

它应该可以工作。使用此链接作为引用。 TfidfVectorizer

关于machine-learning - TF-IDF提取关键词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47793039/

相关文章:

machine-learning - Caffe 进行数据洗牌的方式

python - 卷积神经网络中的形状误差

scikit-learn - 拟合模型时更改默认 RandomForestClassifier 的 "score"函数?

python - 如何在 clf.predict_proba(X_test) 中获得更多小数?

java - 是否可以按词性在 Lucene 索引中搜索单词

machine-learning - Scikit 决策树分类特征

r - R 中的 princomp 用于 PCA - 输出实例中的分数变量。

python - 使用 scikit-learn,如何在小数据集上学习 SVM?

python - 在 Amazon Comprehend Medical 中识别单词的不同时态

python - 在多类分类问题中将 class_weights 参数与 Keras 一起使用时出错