<jupyter_start><jupyter_text>Bernoulli<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.naive_bayes import BernoulliNB
from sklearn.metrics import accuracy_score
dataset = pd.read_csv('../0_datasets/census.csv')
dataset.head()
dataset['sex'].unique()
X = dataset['sex'].values
X
from sklearn.preprocessing import LabelEncoder

label_enconder = LabelEncoder()
X = label_enconder.fit_transform(X)
X
sns.histplot(X)
X.shape
X = X.reshape(-1,1)
X.shape
y = dataset['income'].values
bernoulli_naive_bayes = BernoulliNB()
bernoulli_naive_bayes.fit(X,y)
previsoes = bernoulli_naive_bayes.predict(X)
previsoes, y
accuracy_score(y, previsoes)<jupyter_output><empty_output><jupyter_text>Multinomial<jupyter_code>from sklearn.naive_bayes import MultinomialNB
dataset = pd.read_csv('../0_datasets/census.csv')
dataset.head()
dataset['workclass'].unique()
from sklearn.preprocessing import LabelEncoder
workclass = LabelEncoder()
dataset['workclass'] = workclass.fit_transform(dataset['workclass'])

education = LabelEncoder()
dataset['education'] = education.fit_transform(dataset['education'])

marital_status = LabelEncoder()
dataset['marital-status'] = marital_status.fit_transform(dataset['marital-status'])

occupation = LabelEncoder()
dataset['occupation'] = occupation.fit_transform(dataset['occupation'])

relationship = LabelEncoder()
dataset['relationship'] = relationship.fit_transform(dataset['relationship'])

race = LabelEncoder()
dataset['race'] = race.fit_transform(dataset['race'])

native_country = LabelEncoder()
dataset['native-country'] = native_country.fit_transform(dataset['native-country'])
dataset.head()
X = dataset.iloc[:, [1,3,5,6,7,8,13]].values
X
y = dataset['income'].values
y
multinomial_naive_bayes = MultinomialNB()
multinomial_naive_bayes.fit(X,y)
previsoes = multinomial_naive_bayes.predict(X)
previsoes
accuracy_score(y, previsoes)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13350649350649352, 'fraction_numerical': 0.006233766233766234, 'mean_word_length': 9.19047619047619, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '585459', 'license': 'MIT', 'n_tokens_mistral': 687, 'n_tokens_neox': 651, 'n_words': 107, 'path': '6_distribuicoes_estatisticas/distribuicoes_naive_bayes.ipynb', 'repo_name': 'AlissonRaphael/statistics_for_data_science_and_machine_learning', 'size': '1925'}