|
2 | 2 | from sklearn.exceptions import NotFittedError
|
3 | 3 | from sklearn.model_selection import train_test_split
|
4 | 4 |
|
5 |
| -from test.test_utils import triplets_learners, ids_triplets_learners |
| 5 | +from metric_learn import SCML |
| 6 | +from test.test_utils import triplets_learners, ids_triplets_learners, build_triplets |
6 | 7 | from metric_learn.sklearn_shims import set_random_state
|
7 | 8 | from sklearn import clone
|
8 | 9 | import numpy as np
|
@@ -107,3 +108,16 @@ def test_accuracy_toy_example(estimator, build_dataset):
|
107 | 108 | # we force the transformation to be identity so that we control what it does
|
108 | 109 | estimator.components_ = np.eye(X.shape[1])
|
109 | 110 | assert estimator.score(triplets_test) == 0.25
|
| 111 | + |
| 112 | + |
| 113 | +def test_raise_big_number_of_features(): |
| 114 | + triplets, _, _, X = build_triplets(with_preprocessor=False) |
| 115 | + triplets = triplets[:3, :, :] |
| 116 | + estimator = SCML(n_basis=320) |
| 117 | + set_random_state(estimator) |
| 118 | + with pytest.raises(ValueError) as exc_info: |
| 119 | + estimator.fit(triplets) |
| 120 | + assert exc_info.value.args[0] == \ |
| 121 | + "Number of features (4) is greater than the nuber of triplets(3).\n" \ |
| 122 | + "Consider using a dimensionality reduction preprocessing or create " \ |
| 123 | + "a new basis generation scheme." |
0 commit comments