Coder Social home page Coder Social logo

yzspamfilter's Introduction

YZSpamFilter

YZSpamFilter是一款中文垃圾信息过滤工具,可为帖子、邮件、博客等提供中文垃圾信息过滤服务,开发人员提供训练数据即可生成自己所需的过滤模型。特点如下:

  • 准确性高 :离线测试真实垃圾帖,垃圾信息过滤准确率在90%以上;在线测试真实垃圾帖,指标在80%以上;
  • 实时性好 :可提供实时的垃圾信息过滤服务;
  • 模型可自动更新:支持自动更新模型,增加模型的有效性。

[TOC]

依赖

使用前需安装jieba分词组件 命令: sudo pip install jieba

使用方法

  1. 准备两份垃圾信息的文档,一份为正常的信息,一份为垃圾信息,每一行为一条数据,如本项目内的ham.txt与spam.txt 注: 正负样本数量最好各大于1000

  2. 运行数据准备程序createTrainAndTestData.py,生成训练与测试数据 示例: python createTrainAndTestData.py ham.txt spam.txt 0.5 stopwords_common.txt 以下为参数说明: ham.txt --- 正常信息 spam.txt --- 垃圾信息 0.5 --- 用于训练的信息占所有信息的比例,剩余的为测试信息(非必须参数,默认为0.5) stopwords_common.txt --- 停止词列表,stopwords_common.txt为较常用停止词,stopwords.txt较全(非必须参数,默认为stopwords_common.txt ) 运行完毕后,会生成trainPos.txt、trainNeg.txt、testPos.txt、testNeg.txt,分别对应训练正样本、训练负样本、测试正样本、测试负样本

  3. 运行训练测试程序filter.py 示例: python filter.py 该程序首先会利用上步得到的训练样本训练出垃圾信息过滤的模型,然后对上步得到的测试样本进行测试并打印测试结果 其中tar为正确接受率,及正样本测试正确率,trr为错误拒绝率,即负样本测试正确率,accuracy为整体正确率 运行一次后,程序将模型保存为pickle文件,下次会直接从该文件中读取模型

    特别提示: filter.py程序最后的single judge为调用示例

  4. 考虑到实际使用过程中,需要模型进行自动更新,因此autorefresh.py为垃圾信息的自动更新示例 示例: python autorefresh.py 1)当模型错误的将某个正常信息当做垃圾信息时,对于大多数垃圾信息过滤服务而言,问题较为严重,因此,示例中分两步 f.Algorithm.discover(FalseRejectstr, True) --- 将该信息从垃圾信息的统计分布取出 f.Algorithm.cover(FalseRejectstr, False) --- 将该信息加入正常信息的统计分布 2)当模型错误的将某个垃圾信息当做正常信时,问题严重性较低,因此,只做一步 f.Algorithm.cover(FalseAcceptstr, True) --- 将该信息加入垃圾信息的统计分布 注: True表示信息为垃圾信息,False则相反

实际使用过程中,上述两个步骤可根据实际需求自由修改,开发人员可设计程序与数据库对接,实现模型的自动更新

效果统计

  1. 测试效果: tar = 99.49%, trr = 93.48%, accuracy = 97.61%
  2. 线上效果: 经有赞线上效果统计,10.10 - 10.16日一个星期内,对于有赞bbs后台拦截统计,共拦截到垃圾帖子289,其中误拦截为9,漏拦截为43

声明

本工具内所有数据与指标统计皆基于有赞bbs后台真实数据

yzspamfilter's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.