资源简介
基于matlab的垃圾邮件处理,朴素贝叶斯算法

代码片段和文件信息
[spmatrix tokenlist category] = readMatrix(‘MATRIX.TEST‘);
testMatrix = full(spmatrix);
numTestDocs = size(testMatrix 1);
numTokens = size(testMatrix 2);
% Assume nb_train.m has just been executed and all the parameters computed/needed
% by your classifier are in memory through that execution. You can also assume
% that the columns in the test set are arranged in exactly the same way as for the
% training set (i.e. the j-th column represents the same token in the test data
% matrix as in the original training data matrix).
% Write code below to classify each document in the test set (ie each row
% in the current document word matrix) as 1 for SPAM and 0 for NON-SPAM.
% Construct the (numTestDocs x 1) vector ‘output‘ such that the i-th entry
% of this vector is the predicted class (1/0) for the i-th email (i-th row
% in testMatrix) in the test set.
output = zeros(numTestDocs 1);
%---------------
% YOUR CODE HERE
%%%%%%%%%%%% CODE BY 王委涛 %%%%%%%%%%%%%%%%%%%%%%%%
%result_test = zeros(numTestDocs1); % the result of Test = output
result = zeros(numclassifier1); % 存储每个测试样本的属于各个类别的概率
for i = 1:numTestDocs %处理每一个测试样本
for k = 1:numclassifier %在各个类别下的情况
for j = 1:numTokens %对每个Token进行处理
result(k) = result(k) + testMatrix(ij) * log(P_numToken(kj));%计算P(Xi|Ck)
end
result(k) = result(k) + log(P_category(k)); %计算P(Xi|Ck)P(Ck)
end
if(result(1) > result(2)) %比较result(k)判断测试样本类型
output(i) = 0;
else
output(i) = 1;
end
for r = 1:numclassifier %将存储矩阵清零,以用于存储下一个样本值
result(r) = 0;
end
end
%%%%%%%%%%%%%%CODE BY 王委涛 %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%CODE BY 葛新朋 %%%%%%%%%%%%%%%%%
%计算误判次数
numerror = 0;
for g = 1: numTestDocs
if(category(g) ~= output(g))
numerror = numerror + 1;
end
end
%display
disp(‘The test set error on MATRIX.TEST ‘)
disp(numerror/numTestDocs);
%%%%%%%%%%%%%%%CODE BY 葛新朋%%%%%%%%%%%%%%%%%%
%---------------
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 74967 2013-09-25 13:35 作业\hw1.pdf
文件 129205 2013-11-04 23:16 作业\hw2.pdf
文件 657 2013-11-04 23:16 作业\hw2data.txt
文件 201135 2012-10-26 14:20 作业\MATRIX.TEST
文件 525629 2012-10-26 14:20 作业\MATRIX.TRAIN
文件 33910 2012-10-26 14:20 作业\MATRIX.TRAIN.100
文件 343763 2012-10-26 14:20 作业\MATRIX.TRAIN.1400
文件 58065 2012-10-26 14:20 作业\MATRIX.TRAIN.200
文件 107274 2012-10-26 14:20 作业\MATRIX.TRAIN.400
文件 21769 2012-10-26 14:20 作业\MATRIX.TRAIN.50
文件 205046 2012-10-26 14:20 作业\MATRIX.TRAIN.800
文件 2197 2013-10-27 00:21 作业\nb_test.m
文件 3116 2013-10-27 00:21 作业\nb_train.m
文件 1159 2013-07-14 17:29 作业\readMatrix.m
文件 2665 2013-10-27 00:21 作业\Result_HW1.txt
文件 15391 2012-10-26 14:20 作业\TOKENS_LIST.txt
目录 0 2013-11-04 23:17 作业
----------- --------- ---------- ----- ----
1725948 17
- 上一篇:max贴图批量重命名
- 下一篇:svm完成聚类功能的小程序
相关资源
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
评论
共有 条评论