Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Refactored) Guarantee that labels are aligned #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions confusion_matrix_pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,29 @@ def plot_confusion_matrix_from_data(y_test, predictions, columns=None, annot=Tru
from sklearn.metrics import confusion_matrix
from pandas import DataFrame

#data
if(not columns):
#labels axis integer:
##columns = range(1, len(np.unique(y_test))+1)
#labels axis string:
from string import ascii_uppercase
columns = ['class %s' %(i) for i in list(ascii_uppercase)[0:len(np.unique(y_test))]]

confm = confusion_matrix(y_test, predictions)
cmap = 'Oranges';
fz = 11;
figsize=[9,9];
# data
if not columns:
generated_columns = [
"class {0}".format(str(x).upper()) for x in np.unique(y_test)
]

confm = confusion_matrix(y_test, predictions, labels=np.unique(y_test))
cmap = "Oranges"
fz = 11
figsize = [9, 9]
show_null_values = 2
df_cm = DataFrame(confm, index=columns, columns=columns)

df_cm = pd.DataFrame(
confm,
index=(np.unique(y_test) if not columns is None else generated_columns),
columns=(np.unique(y_test) if not columns is None else generated_columns),
)

# reorders confusion matrix to respect columns passed as arguments
if columns:
df_cm = df_cm.reindex(index=columns, columns=columns)
df_cm = df_cm.fillna(0.0)

pretty_plot_confusion_matrix(df_cm, fz=fz, cmap=cmap, figsize=figsize, show_null_values=show_null_values, pred_val_axis=pred_val_axis)
#

Expand Down