Skip to content

Commit

Permalink
Merge pull request #185 from 42-AI/162-ml03ex09-confusion-matrix-last…
Browse files Browse the repository at this point in the history
…-2-examples-uses-`y_true`-instead-of-`y`

isue #162: ML03ex09 Confusion matrix: Last 2 examples uses y_true instead of y
  • Loading branch information
ppeigne committed Mar 16, 2022
2 parents 2ed32f5 + 0cb0e8a commit 11a909a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 14 additions & 11 deletions module08/en.subject.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,10 @@ \section*{Instructions}
"""
Compute confusion matrix to evaluate the accuracy of a classification.
Args:
y_true:a numpy.ndarray for the correct labels
y_hat:a numpy.ndarray for the predicted labels
labels: optional, a list of labels to index the matrix. This may be used to reorder or select a subset of labels. (default=None)
y_true: numpy.ndarray for the correct labels
y_hat: numpy.ndarray for the predicted labels
labels: Optional, a list of labels to index the matrix.
This may be used to reorder or select a subset of labels. (default=None)
Returns:
The confusion matrix as a numpy ndarray.
None on any error.
Expand Down Expand Up @@ -1310,17 +1311,18 @@ \subsection{Objective(s):}
\subsection{Instructions:}

In the \texttt{confusion\_matrix.py} file, write the following function as per the instructions below:

\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
def confusion_matrix_(y, y_hat, labels=None, df_option=False):
def confusion_matrix_(y_true, y_hat, labels=None, df_option=False):
"""
Compute confusion matrix to evaluate the accuracy of a classification.
Args:
y:a numpy.ndarray for the correct labels
y_hat:a numpy.ndarray for the predicted labels
y_true: a numpy.ndarray for the correct labels
y_hat: a numpy.ndarray for the predicted labels
labels: optional, a list of labels to index the matrix. This may be used to reorder or select a subset of labels. (default=None)
df_option: optional, if set to True the function will return a pandas DataFrame instead of a numpy array. (default=False)
Returns:
The confusion matrix as a numpy ndarray or a pandas DataFrame according to df_option value.
Confusion matrix as a numpy ndarray or a pandas DataFrame according to df_option value.
None on any error.
Raises:
This function should not raise any Exception.
Expand All @@ -1329,21 +1331,22 @@ \subsection{Instructions:}
\end{minted}

\section{Examples:}

\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python}
import numpy as np
y_hat = np.array([['norminet'], ['dog'], ['norminet'], ['norminet'], ['dog'], ['bird']])
y_true = np.array([['dog'], ['dog'], ['norminet'], ['norminet'], ['dog'], ['norminet']])
y_hat = np.array(['norminet', 'dog', 'norminet', 'norminet', 'dog', 'bird'])
y = np.array(['dog', 'dog', 'norminet', 'norminet', 'dog', 'norminet'])

# Example 1:
confusion_matrix_(y_true, y_hat, df_option=True)
confusion_matrix_(y, y_hat, df_option=True)
# Output:
bird dog norminet
bird 0 0 0
dog 0 2 1
norminet 1 0 2

# Example 2:
confusion_matrix_(y_true, y_hat, labels=['bird', 'dog'], df_option=True)
confusion_matrix_(y, y_hat, labels=['bird', 'dog'], df_option=True)
# Output:
bird dog
bird 0 0
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v4.0.5
v4.0.6

0 comments on commit 11a909a

Please sign in to comment.