<jupyter_start><jupyter_text>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('Arthitris.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 dataframe for 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 some classificators for evaluating their performance 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>KNN  KNN - Classifier (Don´t run the code if you want to implement other classifier) Downloading the sklearn Knn classifier and fitting it into our data<jupyter_code>from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors = 5)
knn.fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Once we have design our classifier, we are going to evaluate the accuracy<jupyter_code>print(knn.score(X_test, y_test))<jupyter_output>0.9771428571428571<jupyter_text>Finally, we will compute the confusion matrix of the classified data<jupyter_code>knn_predictions = knn.predict(X_test) 
cm = confusion_matrix(y_test, knn_predictions)
cm<jupyter_output><empty_output><jupyter_text>KNN - Channel Bivariate Entropy Triangle Plotting The last step will be calculating the entropic measures for the contingency matrix and plot the entropy triangle. The coordinates will be calculated multiplying the normalized values needed by the scale used for plotting the triangle, and will appear behind the triangle plot for comparission<jupyter_code>edf = jentropies_binary(cm)
#edf1 = jentropies(pd.DataFrame(y_test),pd.DataFrame(knn_predictions))
edf
#edf1
entriangle(edf,s_mk=150, gridl = 20, pltscale=12 ,fonts = 20, ticks_size= 15,chart_title="Knn-Classifier with BreastCancer")<jupyter_output><empty_output><jupyter_text>Naive Bayes  Naive Bayes - Classificator  Now we are going to provide another example of the channel bivariate entropy triangle using the Naive Bayes classificatior. We will need first to download the GaussianNB class from scikit-learn and apply the following command to train the classifier<jupyter_code>from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB().fit(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Once we have model our classifier, we are going to evaluate the accuracy using the test set<jupyter_code>print(gnb.score(X_test, y_test))<jupyter_output>0.9542857142857143<jupyter_text>Finally, we will compute the confusion matrix of the classified data<jupyter_code>gnb_predictions = gnb.predict(X_test)
cm = confusion_matrix(y_test, gnb_predictions)
cm<jupyter_output><empty_output><jupyter_text>Naive Bayes - Channel Bivariate Entropy Triangle Plotting The last step will be calculating the entropic measures for the contingency matrix and plot the entropy triangle. The coordinates will be calculated multiplying the normalized values needed by the scale used for plotting the triangle. First we will calculate the entropy data frame for the contingency matrix<jupyter_code>edf = jentropies_binary(cm)
edf<jupyter_output><empty_output><jupyter_text>Once we obtained the appropiate entropy data frame, we just need to execute the entriangle function for the plotting<jupyter_code>entriangle(edf,s_mk=150, gridl = 20, pltscale=12 ,fonts = 20, ticks_size= 15,chart_title="Naive Bayes-Classifier with BreastCancer")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08174648970955953, 'fraction_numerical': 0.012887093671859973, 'mean_word_length': 7.51063829787234, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '290114', 'license': 'MIT', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1591, 'n_words': 504, 'path': 'vignettes/CBET - BinaryJointCase.ipynb', 'repo_name': 'Jaimedlrm/entropytriangle', 'size': '5199'}