sklearn文本特征预处理1: WordPunctTokenizer, CountVectorizer, TF-IDF

本文介绍了如何使用sklearn库进行文本预处理,包括基本预处理、词袋模型构建、N-Grams和TF-IDF模型的应用。在预处理中涉及了WordPunctTokenizer进行分词,移除停用词和标点符号,以及向量化操作。接着,文章详细解释了CountVectorizer创建词频词袋模型,并展示了获取的特征名称。最后,提到了TF-IDF模型在文本处理中的作用。
摘要由CSDN通过智能技术生成

构造一个文本数据集

import pandas as pd
import numpy as np

corpus = ['The sky is blue and beautiful.',
		 'Love this blue and beautiful sky!',
         'The quick brown fox jumps over the lazy dog.',
         'The brown fox is quick and the blue dog is lazy!',
         'The sky is very blue and the sky is very beautiful today',
         'The dog is lazy but the brown fox is quick!']
labels = ['weather','weather','animals','animals','weather','animals']
corpus = np.array(corpus)
corpus_df = pd.DataFrame({
   'Document': corpus, 'Category': labels})
corpus_df

在这里插入图片描述

一. 基本预处理

import<
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值