from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.feature_selection import SelectKBest, chi2
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.naive_bayes import MultinomialNB
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn import metrics
from text.textpredict import *
from sklearn.cross_validation import * def chi22():
train_words=["急需 钱用 不用 出售 如图 价值 千多 便宜 出售 出售 急 ",
"读 读 重复 读好输 不变 绿 求高人 指点迷津 ",
"诚召搛只呆家小时工,全职妈妈、在校学生、在家待业者、上班族、游戏者皆可做!每天5",
"发福利了 火熱找小莳工,每天在綫2--3小莳,莳涧地點没限制,薪资鈤结80--150/",
"急招小时工,每天在綫2--3小拭,时间地点没限制,薪资日结80--150/天,适 急招小时工,每天在綫2--3小拭,时间地点没限制,薪资日结80--150/天,适合学生党,手机党,上班族,有空闲时间者,有興趣缪系,QQ(937117723)咨询,此处不回!!",
"发福利来 火熱找小莳工,每天在綫2--3小莳,莳涧地點没限制,薪资鈤结80--150/",
" 读 不好 呜呜 ","这句 话 总是 知道 连读 ","求 师傅 交 口语 求有 耐心 老师 基础 学 ",
"听到 读 "
]
train_tags=[1,0,1,1,1,1,0,0,0,0] """
##就提取了词频CountVectorizer
count_v1 = CountVectorizer(stop_words=None, max_df=0.5)
counts_train = count_v1.fit_transform(train_words)
##卡方检验chi,配合selectkbest 对特征进行选择
chi= SelectKBest(chi2,10)
mychi2 = chi.fit(counts_train, train_tags)
hi2_train = mychi2.transform(counts_train)
clf = MultinomialNB(alpha=0.01)
clf.fit(hi2_train, np.asarray(train_tags))
priediced = cross_val_predict(clf, hi2_train, train_tags)
print metrics.confusion_matrix(train_tags, priediced)
"""
##tf-idf
Tfidf = TfidfVectorizer()
tfidf_train = Tfidf.fit_transform(train_words)
clf = MultinomialNB(alpha=0.01)
clf.fit(tfidf_train, np.asarray(train_tags))
priediced = cross_val_predict(clf, tfidf_train, train_tags)
print metrics.confusion_matrix(train_tags, priediced) #print hi2_train chi22()

  

trate的更多相关文章

  1. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  2. Tensorflow二分类处理dense或者sparse(文本分类)的输入数据

    这里做了一些小的修改,感谢谷歌rd的帮助,使得能够统一处理dense的数据,或者类似文本分类这样sparse的输入数据.后续会做进一步学习优化,比如如何多线程处理. 具体如何处理sparse 主要是使 ...

  3. 【MPI学习6】MPI并行程序设计模式:具有不连续数据发送的MPI程序设计

    基于都志辉老师<MPI并行程序设计模式>第14章内容. 前面接触到的MPI发送的数据类型都是连续型的数据.非连续类型的数据,MPI也可以发送,但是需要预先处理,大概有两类方法: (1)用户 ...

  4. ab压力测试工具-批量压测脚本

    ab(Apache benchmark)是一款常用的压力测试工具.简单易用,ab的命令行一次只能支持一次测试.如果想要批量执行不同的测试方式,并自动对指标进行分析,那么单靠手工一条一条命令运行ab,估 ...

  5. 抽象基类(ABC),纯虚函数

    #ifndef _ACCTABC_H_ #define _ACCTABC_H_ //(* #include <iostream> #include <string> //*) ...

  6. Tcp 数据对象传输接口对象设计

    输入是一个对象inputObj,接口对象.Send(inputObj),对端接收之后解包成outputObj(与inputObj应相同),触发onPackageReceive事件 事件 public ...

  7. poj 3266 Cow School 分数规划

    这个题目难度非常大,首先对于老师的一种方案,应用分数规划的一般做法,求出所有的c=t-rate*p,如果没有选择的c值中的最大值比选择了的c值中的最小值大,那么这个解是可以改进的. 那么问题就转化成了 ...

  8. Akka FSM 源代码分析

    Akka FSM 源代码分析 萧猛 <simonxiao@qq.com> 啰嗦几句 有限状态机本身不是啥新奇东西,在GoF的设计模式一书中就有状态模式, 也给出了实现的建议.各种语言对状态 ...

  9. 通过ant-jmeter读取jtl文件拆分数据并insert DB

    前言:之前详解过通过jmeter生成的csv文件,解析csv存入DB,这个有弊端 第一:需独立创建一个job 第二:需按照一定规范输出 因此,放弃解析csv方式,直接解析自动化生成的原始jtl文件并集 ...

随机推荐

  1. Generic repository pattern and Unit of work with Entity framework

    原文 Generic repository pattern and Unit of work with Entity framework Repository pattern is an abstra ...

  2. 离线应用Application Cache详解

    特点:     1.离线可访问            - 没有网络仍可访问整个应用     2.很小的服务器负载  - 缓存在本地,不需要到服务器请求     3.高速                 ...

  3. List应用举例

    1.集合的嵌套遍历 学生类: package listexercise; /** * Created by gao on 15-12-9. */ public class Student { priv ...

  4. linux 命令学习大全

    转载  http://blog.csdn.net/xiaoguaihai/article/details/8705992/

  5. 转 命令行下玩VC

    说明:(1)转载请注明出处:http://www.cnblogs.com/opangle/p/4298155.html (2)以下以VS2013为例,并假设VC安装路径为%VC_INSTALL_PAT ...

  6. [HDOJ4612]Warm up(双连通分量,缩点,树直径)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 所有图论题都要往树上考虑 题意:给一张图,仅允许添加一条边,问能干掉的最多条桥有多少. 必须解决 ...

  7. [LeetCode#267] Palindrome Permutation II

    Problem: Given a string s, return all the palindromic permutations (without duplicates) of it. Retur ...

  8. HTML空格符号 &nbsp / &ensp / &emsp

      半角的不断行的空白格(推荐使用)    半角的空格    全角的空格

  9. Java [Leetcode 225]Implement Stack using Queues

    题目描述: Implement the following operations of a stack using queues. push(x) -- Push element x onto sta ...

  10. 搭建LAMP测试环境

    LAMP:Linux+Apache+Mysql+Php,组合统称为LAMP,关于其中的独立个体,这里就不多介绍了. 1.首先准备一下软件包,如下: mysql-5.0.22.tar.gz httpd- ...