资源简介
基于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完成聚类功能的小程序
相关资源
- RSA加密算法的Matlab程序
- MATLAB7.70有源电力滤波器APF(SVG)模型
- puma560轨迹规划
- 模糊滑膜控制matlab
- 小数时延滤波器matlab程序
- 平坦衰落信道的仿真
- 局部搜索解决最优化问题matlab程序
- 多自由度体系中心差分法matlab编程
- 加窗傅里叶变换的演示 matlab程序 分别
- 自己做的提取语音信号的基音周期的
- 数字图像处理图像点运算和代数运算
- 基于matlab的连续DTMF信号检测的程序实
- WIFI定位算法MATLAB代码
- TOA的MATLAB定位算法代码
- 点云三角剖分matlab代码
- matlab中算rice米粒的个数代码及图片
- 单像后方交会matlab代码
- MATLAB二元函数绘图
- MATLAB希尔伯特Hilbert变换求包络谱 源程
- D2D资源分配仿真 MATLAB
- delta机械臂的matlab仿真
- 多尺度熵 matlab程序
- LANDMARC算法
- FMCW雷达matlab仿真
- 多尺度小波模极大值法检测频谱边缘
- PMSM的矢量控制仿真模型
- 可以直接运行求解VRP的matlab程序,
- 超分辨率重建的matlab代码
- matlab课程设计源代码肺实质的提取
- matlab实现图像的配准,手动选点
评论
共有 条评论