Path: blob/master/Week 7/Programming Assignment - 6/ex6/emailFeatures.m
863 views
function x = emailFeatures(word_indices)1%EMAILFEATURES takes in a word_indices vector and produces a feature vector2%from the word indices3% x = EMAILFEATURES(word_indices) takes in a word_indices vector and4% produces a feature vector from the word indices.56% Total number of words in the dictionary7n = 1899;89% You need to return the following variables correctly.10x = zeros(n, 1);1112% ====================== YOUR CODE HERE ======================13% Instructions: Fill in this function to return a feature vector for the14% given email (word_indices). To help make it easier to15% process the emails, we have have already pre-processed each16% email and converted each word in the email into an index in17% a fixed dictionary (of 1899 words). The variable18% word_indices contains the list of indices of the words19% which occur in one email.20%21% Concretely, if an email has the text:22%23% The quick brown fox jumped over the lazy dog.24%25% Then, the word_indices vector for this text might look26% like:27%28% 60 100 33 44 10 53 60 58 529%30% where, we have mapped each word onto a number, for example:31%32% the -- 6033% quick -- 10034% ...35%36% (note: the above numbers are just an example and are not the37% actual mappings).38%39% Your task is take one such word_indices vector and construct40% a binary feature vector that indicates whether a particular41% word occurs in the email. That is, x(i) = 1 when word i42% is present in the email. Concretely, if the word 'the' (say,43% index 60) appears in the email, then x(60) = 1. The feature44% vector should look like:45%46% x = [ 0 0 0 0 1 0 0 0 ... 0 0 0 0 1 ... 0 0 0 1 0 ..];47%48%495051525354555657% =========================================================================585960end616263