Skip to content

Commit cf38241

Browse files
authored
Update dimensionality_reduction.py
1 parent bed9512 commit cf38241

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

machine_learning/dimensionality_reduction.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,25 @@ def test_linear_discriminant_analysis() -> None:
407407
features = np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 6, 7]])
408408
labels = np.array([0, 0, 0, 1, 1])
409409
classes = 2
410-
dimensions = 2
410+
dimensions = 1 # Changed to 1 since classes=2 and dimensions must be < classes
411411

412-
# Assert that the function raises an AssertionError if dimensions > classes
413-
with pytest.raises(AssertionError):
414-
linear_discriminant_analysis(features, labels, classes, dimensions)
412+
try:
413+
# This should work since dimensions < classes
414+
lda_result = linear_discriminant_analysis(features, labels, classes, dimensions)
415+
assert lda_result.shape == (dimensions, features.shape[1])
416+
logging.info("LDA test passed")
417+
except Exception as e:
418+
logging.error(f"LDA test failed: {e}")
419+
raise
415420

416421

417422
def test_principal_component_analysis() -> None:
418423
"""Test function for Principal Component Analysis."""
419424
features = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
420425
dimensions = 2
421-
expected_output = np.array([[6.92820323, 8.66025404, 10.39230485], [3.0, 3.0, 3.0]])
426+
expected_output = np.array(
427+
[[6.92820323, 8.66025404, 10.39230485], [3.0, 3.0, 3.0]]
428+
)
422429

423430
output = principal_component_analysis(features, dimensions)
424431
if not np.allclose(expected_output, output):

0 commit comments

Comments
 (0)