<jupyter_start><jupyter_text>Convert alphabets to numbersthe data is in alphebeticla e.g o represents orange, b represents bluewe will now map each rows letters with a number<jupyter_code>le = LabelEncoder()
#applies tranformation on each method
ds = df.apply(le.fit_transform)

(ds.head(50))
data = ds.values
print(data.shape)
print(type(data))
print(data[:5,:])

data_x = data[:,1:]
data_y = data[:,0]
x_train, x_test, y_train, y_test = train_test_split(data_x,data_y, test_size = 0.2)
print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)
np.unique(y_train)<jupyter_output><empty_output><jupyter_text>Classifier<jupyter_code>def prior_prob( y_train, label):
    total_examples = y_train.shape[0]
    class_examples = np.sum(y_train==label)
    
    return (class_examples/float(total_examples))
y = np.array([0,5,5,1,1,1,1,0,0,0])
prior_prob(y,5)
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)
def predict(x_train, y_train, xtest):
    classes = np.unique(y_train)
    n_features = x_train.shape[1]
    post_probs = []
    
    for label in classes:
        likelihood = 1.0
        prior = prior_prob(y_train, label)
        for f in range(n_features):
            cond = cond_prob(x_train, y_train, f, xtest[f], label)
            likelihood *= cond
        
        post = likelihood*prior
        post_probs.append(post)
    pred = np.argmax(post_probs)
    return pred
output = predict(x_train, y_train, x_test[1])
print(output,y_test[1])
def score(x_train, y_train, x_test, y_test):
    pred = []
    for i in range(x_test.shape[0]):
        pred_label = predict(x_train, y_train, x_test[i])
        pred.append(pred_label)
    pred = np.array(pred)
    accuracy = np.sum(pred==y_test)/y_test.shape[0]
    return accuracy
print(score(x_train, y_train, x_test, y_test))<jupyter_output>0.9950769230769231
{'fraction_non_alphanumeric': 0.12512266928361138, 'fraction_numerical': 0.021099116781157997, 'mean_word_length': 4.268733850129199, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '518171', 'license': 'MIT', 'n_tokens_mistral': 796, 'n_tokens_neox': 776, 'n_words': 148, 'path': 'naive Bayes mushroom dataset.ipynb', 'repo_name': 'thelokeshgoel00/MushroomClassification-NaiveBayes', 'size': '2038'}