SVM文本分类实验过程

该博客详细记录了SVM文本分类的实验步骤,包括分词和打标签,特征选择采用卡方检验或PCA,数据经过归一化处理,利用libSVM工具,将标签和特征转化为libSVM所需的格式,并通过grid.py进行参数调优,采用交叉验证方法。
摘要由CSDN通过智能技术生成

1、分词,打标签;

2、特征选择: 卡方检验

def chi_select():
#构建停用词表
    stopwords=[]
    with open("../hlt_stop_words.txt","r") as stopword:   
        for line in stopword: #遍历文件,一行行遍历,读取文本
            rs = line.replace('\n', '') 
            stopwords.append(rs)
#读入文本 
    x_text = 1_examples + 2_examples + ...
# 去停用词 
    x_stop=[] 
    for word in x_text:
#        word = word.split(" ")
        rs = []
        for _ in word:
            if _ not in stopwords:
                rs.append(_)
        x_stop.append(rs)

#重组
    x_final=[]
    for i in x_stop:
        x_final.append(str(i))

#建立词典
    max_document_length = max([len(x) for x in x_stop])
    #print(max_document_length)
    vocab_processor = learn.preprocessing.VocabularyProcessor(max_document_length)
    x = np.array(list(vocab_processor.fit_transform(x_final)
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值