131A_1_new_email_prob - Ps = ; for m=1:Number_words n=1;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % EE131A: Probabilities % % File: new_email_prob.m % % Author: Nikolaos Kontorinis % % Date: 12/01/04 % % Description: Perfoms a look-up of the spam probabilities of the words % in the new email. % % ATTENTION: % 1. The file train_filter.m should be run first and its % variables should not be altered. % 2. The new file must be specified externally as the string % new_file (e.g. new_file = 'new1_freq.txt'). % 3. The number of words in new_file must be specified % externally. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %clear Ps; % this is not necessary clear new_words; clear freq; fid_new= fopen(new_file,'r'); %new_file is a string %Read the words of the new_file and look-up their spam probs.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ps = ; for m=1:Number_words n=1; temp = fscanf(fid_new,'%1c',1); while(~isletter(temp)&&~isfinite(str2double(temp))) %Won't work temp = fscanf(fid_new,'%1c',1); %Without this end %--Ian Salman new_words(m,n)=temp; while(~isspace(temp)) new_words(m,n)=temp; temp = fscanf(fid_new,'%1c',1); n=n+1; end freq(m) = fscanf(fid_new,'%d \n',1); i = strmatch(new_words(m,:),words,'exact'); if isempty(i) %Check if the current word occurs in the training set Ps = [Ps; 0.4]; %If it is a new word, make it's spam prob almost % neutral ( slightly biased towards ham) else Ps = [Ps; prob(i)]; %. ..else use the existing prob. end end fclose('all');...
View Full Document

This note was uploaded on 06/09/2010 for the course EE 131A taught by Professor Lorenzelli during the Spring '08 term at UCLA.

Ask a homework question - tutors are online