433-6 Guided Project: Building a Spam Filter with Naive Bayes

Hi Sahil,
I tried the hard refresh but when I run my project (Spam Filter), I am still getting the message “The kernel appears to have died. It will restart automatically.”

I’m currently experiencing ‘Kernel has died’ error on the Statistics Conditional Probability Guided Project. However, the missions are working fine. Hope this helps the team.

Thank you,
Shankha

Hi @aastha.2112, @shankhap1,

Mission Screen Link: https://app.dataquest.io/m/433/guided-project%3A-building-a-spam-filter-with-naive-bayes/6/calculating-constants-first

I contacted the content team about it and the root cause of the issue was this code in the solution page:

# P(Spam) and P(Ham)
p_spam = training_set_clean['Label'].value_counts(normalize=True)['spam']
p_ham = training_set_clean['Label'].value_counts(normalize=True)['ham']

# N_Spam, N_Ham, and N_Vocabulary
n_spam = training_set_clean[training_set_clean['Label'] == 'spam'].sum(
                                                    axis=1).sum()
n_ham = training_set_clean[training_set_clean['Label'] == 'ham'].sum(
                                                    axis=1).sum()
n_vocabulary = len(vocabulary)

# Laplace smoothing
alpha = 1

This was causing the kernel to die due to being a memory intensive operation, so the content team replaced the above code to this one:

# Isolating spam and ham messages first
spam_messages = training_set_clean[training_set_clean['Label'] == 'spam']
ham_messages = training_set_clean[training_set_clean['Label'] == 'ham']

# P(Spam) and P(Ham)
p_spam = len(spam_messages) / len(training_set_clean)
p_ham = len(ham_messages) / len(training_set_clean)

# N_Spam
n_words_per_spam_message = spam_messages['SMS'].apply(len)
n_spam = n_words_per_spam_message.sum()

# N_Ham
n_words_per_ham_message = ham_messages['SMS'].apply(len)
n_ham = n_words_per_ham_message.sum()

# N_Vocabulary
n_vocabulary = len(vocabulary)

# Laplace smoothing
alpha = 1

Please replace your code with this and let me know how that goes.

Thanks,
Sahil

1 Like