Mushroom classification using bayes theorem

def cond_prob(x_train,y_train,feature_col,feature_val,label):

x_filtered = x_train[y_train==label]
numerator = np.sum(x_filtered[:,feature_col]==feature_val)
denominator = np.sum(y_train==label)

return numerator/float(denominator)

Can you please give me an example to run this peice of code? What values i can pass in this function?
Actually i am not sure what value to pass for feature_col and label to run this code independently.

Hey @Roopa1i_ma1hotra, yes sure,
label = class label for which we are calculating the conditional probability
feature_col = feature/column name for which we are calculating conditional probability
feature_val = feature value that is value corresponding to the feature column above, which is present in our test example.

To run this independently, just you can use

temp = cond_prob(x_train,y_train,0, 0,1)
here referring to the ipynb notebook.

feature_col = 0 ( cap_shape )
feature_val = 0 ( ‘b’ as cap_shape)
label = 1 ( ‘p’ as type)

Hope this resolved your doubt. :blush:

Thankyou very much!!! :relaxed:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.