Skip to content

Commit 761bfd2

Browse files
committed
Add doctests to manual_accuracy function in scoring_functions
1 parent bc9ccd9 commit 761bfd2

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

machine_learning/scoring_functions.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,37 @@ def mbd(predict, actual):
136136

137137

138138
def manual_accuracy(predict, actual):
139+
"""
140+
Calculate the accuracy score for binary classification predictions.
141+
142+
Accuracy = (Number of correct predictions) / (Total predictions)
143+
144+
Parameters:
145+
- predict: Predicted labels
146+
- actual: True labels
147+
148+
Returns:
149+
- float: Accuracy score between 0 and 1
150+
151+
Examples:
152+
>>> actual = [1, 0, 1, 1, 0]
153+
>>> predict = [1, 0, 1, 0, 0]
154+
>>> float(manual_accuracy(predict, actual))
155+
0.8
156+
157+
>>> actual = [1, 1, 1]
158+
>>> predict = [1, 1, 1]
159+
>>> float(manual_accuracy(predict, actual))
160+
1.0
161+
162+
>>> actual = [0, 0, 0]
163+
>>> predict = [1, 1, 1]
164+
>>> float(manual_accuracy(predict, actual))
165+
0.0
166+
167+
>>> actual = [1, 0, 1, 0]
168+
>>> predict = [0, 1, 0, 1]
169+
>>> float(manual_accuracy(predict, actual))
170+
0.0
171+
"""
139172
return np.mean(np.array(actual) == np.array(predict))

0 commit comments

Comments
 (0)