<jupyter_start><jupyter_text>Naive - Bayes // Binary Joint Use Case (Single DataFrameCase)  In this vignette a use case of the Binary Channel Entropy Triangle is presented. We are going to evaluate different multiclass-classification scenarios in order to analyze the data.The main functionalities for the classification of the database will be extracted from: https://www.geeksforgeeks.org/multiclass-classification-using-scikit-learn/  Importing Libraries We import the package entropytriangle, which will import the modules needed for the evaluation<jupyter_code>from entropytriangle import * #importing all modules necessary for the plotting<jupyter_output><empty_output><jupyter_text>Download the databases In this case, the csv files for the use case, are stored locally<jupyter_code>#df = pd.read_csv('Arthritis.csv',delimiter=',',index_col='Unnamed: 0').drop(['ID'],axis = 1)
df = pd.read_csv('Breast_data.csv',delimiter=',',index_col='Unnamed: 0').drop(['Sample code number'],axis = 1).replace('?',np.nan) # in this DB the missing values are represented as '?' 
#df = pd.read_csv('Glass.csv',delimiter=',')
#df = pd.read_csv('Ionosphere.csv',delimiter=',')
#df = pd.read_csv('Iris.csv',delimiter=',',index_col='Id')
#df = pd.read_csv('Wine.csv',delimiter=',').drop(['Wine'],axis = 1)
df.info(verbose=True)
df = df.fillna(0)
df.head(5)<jupyter_output><empty_output><jupyter_text>Prepare the data for the classification (Features - Classes)  We are going to load the train_test_split that will allow us to separe automatically the data in a train/test sets. Additionally, we are going to import the contingency matrix that will allow us to calculate the joint entropy matrix of the classifier<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix<jupyter_output><empty_output><jupyter_text>Separating the data farmes features and classes<jupyter_code>X = df[df.columns[df.columns != 'Class']]
y = df['Class']<jupyter_output><empty_output><jupyter_text>We are now to define a split in the data for evaluating the performance of classifiers with the BreastCancer database.<jupyter_code># dividing X, y into train and test data
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state = 0)<jupyter_output><empty_output><jupyter_text>Naive Bayes  Naive Bayes - Classifier  All the steps showed in the CBET - BinaryJointCase at the Naives Bayes Region. Now we are using a loop for plotting all the values on the same diagram.<jupyter_code>from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB().fit(X_train, y_train)
gnb_predictions = gnb.predict(X_test)
cm = confusion_matrix(y_test, gnb_predictions)
edf = jentropies_binary(cm)<jupyter_output><empty_output><jupyter_text>Iterations for varying the train size for checking the performance. We are going to vary the train set size.<jupyter_code>l = [0.10,0.20,0.30,0.40,0.50,0.60,0.70,0.8]
names_l = list(str('Train size = '+ str(l[i])) for i in range(len(l)))
lis = list()
for i in range(len(l)):
    # dividing X, y into train and test data
    X_train, X_test, y_train, y_test = train_test_split(X, y,train_size = l[i], random_state = 0)
    gnb = GaussianNB().fit(X_train, y_train)
    gnb_predictions = gnb.predict(X_test)
    cm = confusion_matrix(y_test, gnb_predictions)
    edf = jentropies_binary(cm)
    lis.append(edf.iloc[[2]])
entriangle_list(lis,names=names_l,s_mk=150, gridl = 20, pltscale=13 ,fonts = 20, ticks_size= 15,chart_title="Naive Bayes - Classifier with Breast Cancer")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10917276308384918, 'fraction_numerical': 0.012380416432189083, 'mean_word_length': 6.3602484472049685, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '313409', 'license': 'MIT', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1166, 'n_words': 340, 'path': 'vignettes/CBET - Naive BinaryJointCase.ipynb', 'repo_name': 'Jaimedlrm/entropytriangle', 'size': '3554'}