Skip to content

Commit b82f1bd

Browse files
committed
Fix some more numpy tests
1 parent 770d4f0 commit b82f1bd

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

Diff for: machine_learning/loss_functions.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def binary_cross_entropy(
2222
2323
>>> true_labels = np.array([0, 1, 1, 0, 1])
2424
>>> predicted_probs = np.array([0.2, 0.7, 0.9, 0.3, 0.8])
25-
>>> binary_cross_entropy(true_labels, predicted_probs)
25+
>>> float(binary_cross_entropy(true_labels, predicted_probs))
2626
0.2529995012327421
2727
>>> true_labels = np.array([0, 1, 1, 0, 1])
2828
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -420,7 +420,7 @@ def mean_squared_logarithmic_error(y_true: np.ndarray, y_pred: np.ndarray) -> fl
420420
421421
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
422422
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
423-
>>> mean_squared_logarithmic_error(true_values, predicted_values)
423+
>>> float(mean_squared_logarithmic_error(true_values, predicted_values))
424424
0.0030860877925181344
425425
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
426426
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -459,17 +459,17 @@ def mean_absolute_percentage_error(
459459
Examples:
460460
>>> y_true = np.array([10, 20, 30, 40])
461461
>>> y_pred = np.array([12, 18, 33, 45])
462-
>>> mean_absolute_percentage_error(y_true, y_pred)
462+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
463463
0.13125
464464
465465
>>> y_true = np.array([1, 2, 3, 4])
466466
>>> y_pred = np.array([2, 3, 4, 5])
467-
>>> mean_absolute_percentage_error(y_true, y_pred)
467+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
468468
0.5208333333333333
469469
470470
>>> y_true = np.array([34, 37, 44, 47, 48, 48, 46, 43, 32, 27, 26, 24])
471471
>>> y_pred = np.array([37, 40, 46, 44, 46, 50, 45, 44, 34, 30, 22, 23])
472-
>>> mean_absolute_percentage_error(y_true, y_pred)
472+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
473473
0.064671076436071
474474
"""
475475
if len(y_true) != len(y_pred):
@@ -511,7 +511,7 @@ def perplexity_loss(
511511
... [[0.03, 0.26, 0.21, 0.18, 0.30],
512512
... [0.28, 0.10, 0.33, 0.15, 0.12]]]
513513
... )
514-
>>> perplexity_loss(y_true, y_pred)
514+
>>> float(perplexity_loss(y_true, y_pred))
515515
5.0247347775367945
516516
>>> y_true = np.array([[1, 4], [2, 3]])
517517
>>> y_pred = np.array(

Diff for: machine_learning/mfcc.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def normalize(audio: np.ndarray) -> np.ndarray:
162162
Examples:
163163
>>> audio = np.array([1, 2, 3, 4, 5])
164164
>>> normalized_audio = normalize(audio)
165-
>>> np.max(normalized_audio)
165+
>>> float(np.max(normalized_audio))
166166
1.0
167-
>>> np.min(normalized_audio)
167+
>>> float(np.min(normalized_audio))
168168
0.2
169169
"""
170170
# Divide the entire audio signal by the maximum absolute value
@@ -229,7 +229,8 @@ def calculate_fft(audio_windowed: np.ndarray, ftt_size: int = 1024) -> np.ndarra
229229
Examples:
230230
>>> audio_windowed = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
231231
>>> audio_fft = calculate_fft(audio_windowed, ftt_size=4)
232-
>>> np.allclose(audio_fft[0], np.array([6.0+0.j, -1.5+0.8660254j, -1.5-0.8660254j]))
232+
>>> bool(np.allclose(audio_fft[0], np.array([6.0+0.j, -1.5+0.8660254j,
233+
... -1.5-0.8660254j])))
233234
True
234235
"""
235236
# Transpose the audio data to have time in rows and channels in columns
@@ -281,7 +282,7 @@ def freq_to_mel(freq: float) -> float:
281282
The frequency in mel scale.
282283
283284
Examples:
284-
>>> round(freq_to_mel(1000), 2)
285+
>>> float(round(freq_to_mel(1000), 2))
285286
999.99
286287
"""
287288
# Use the formula to convert frequency to the mel scale
@@ -321,7 +322,7 @@ def mel_spaced_filterbank(
321322
Mel-spaced filter bank.
322323
323324
Examples:
324-
>>> round(mel_spaced_filterbank(8000, 10, 1024)[0][1], 10)
325+
>>> float(round(mel_spaced_filterbank(8000, 10, 1024)[0][1], 10))
325326
0.0004603981
326327
"""
327328
freq_min = 0
@@ -438,7 +439,7 @@ def discrete_cosine_transform(dct_filter_num: int, filter_num: int) -> np.ndarra
438439
The DCT basis matrix.
439440
440441
Examples:
441-
>>> round(discrete_cosine_transform(3, 5)[0][0], 5)
442+
>>> float(round(discrete_cosine_transform(3, 5)[0][0], 5))
442443
0.44721
443444
"""
444445
basis = np.empty((dct_filter_num, filter_num))

Diff for: machine_learning/multilayer_perceptron_classifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
def wrapper(y):
1919
"""
20-
>>> wrapper(Y)
20+
>>> [int(x) for x in wrapper(Y)]
2121
[0, 0, 1]
2222
"""
2323
return list(y)

0 commit comments

Comments
 (0)