基本信息
源码名称:C# 贝叶斯 分类算法 实例
源码大小:0.26M
文件格式:.zip
开发语言:C#
更新时间:2016-09-03
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Expat.Bayesian;
namespace SpamFilterSample
{
public partial class Form1 : Form
{
private SpamFilter _filter;
public Form1()
{
InitializeComponent();
}
private void TestFile(string file)
{
if (_filter == null)
{
MessageBox.Show("Load first!");
return;
}
string body = new StreamReader(file).ReadToEnd();
txtOut.Text = file Environment.NewLine "score: " _filter.Test(body).ToString();
txtOut.AppendText(Environment.NewLine Environment.NewLine body);
}
#region clicks
private void btnLoad_Click(object sender, EventArgs e)
{
Corpus bad = new Corpus();
Corpus good = new Corpus();
bad.LoadFromFile("../../TestData/spam.txt");
good.LoadFromFile("../../TestData/good.txt");
_filter = new SpamFilter();
_filter.Load(good, bad);
// Just for grins, we'll dump out some statistics about the data we just loaded.
txtOut.Text = String.Format(@"{0} {1} {2}{3}"
, _filter.Good.Tokens.Count
, _filter.Bad.Tokens.Count
, _filter.Prob.Count
, Environment.NewLine);
// ... and some probabilities for keys
foreach (string key in _filter.Prob.Keys)
{
if (_filter.Prob[key] > 0.02)
{
txtOut.AppendText(String.Format("{0},{1}{2}", _filter.Prob[key].ToString(".0000"), key, Environment.NewLine));
}
}
}
private void btnTest1_Click(object sender, EventArgs e)
{
TestFile("../../TestData/definatelyOK.txt");
}
private void btnTest2_Click(object sender, EventArgs e)
{
TestFile("../../TestData/maybeSpam.txt");
}
private void btnTest3_Click(object sender, EventArgs e)
{
TestFile("../../TestData/definatelySpam.txt");
}
private void btnTestBox_Click(object sender, EventArgs e)
{
if (_filter == null)
{
MessageBox.Show("Load first!");
return;
}
string body = txtOut.Text;
txtOut.Text = _filter.Test(body).ToString();
txtOut.AppendText(Environment.NewLine body);
}
private void btnToFile_Click(object sender, EventArgs e)
{
if (_filter == null)
{
MessageBox.Show("Load first!");
return;
}
_filter.ToFile("../../TestData/out.txt");
}
private void btnFromFile_Click(object sender, EventArgs e)
{
_filter = new SpamFilter();
_filter.FromFile("../../TestData/out.txt");
}
#endregion
}
}