Skip to content

Commit 740b00e

Browse files
ceriottmrosecers
authored andcommitted
Force y to be 2D in pcov selection routines
1 parent 2393e77 commit 740b00e

6 files changed

+140
-26
lines changed

examples/FeatureSelection.ipynb

Lines changed: 47 additions & 8 deletions
Large diffs are not rendered by default.

examples/PCovR_Scaling.ipynb

Lines changed: 54 additions & 9 deletions
Large diffs are not rendered by default.

examples/Selectors-Pipelines.ipynb

Lines changed: 31 additions & 5 deletions
Large diffs are not rendered by default.

skcosmo/_selection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ def fit(self, X, y=None, warm_start=False):
142142
force_all_finite=not tags.get("allow_nan", True),
143143
multi_output=True,
144144
)
145+
if len(y.shape) == 1:
146+
# force y to have multi_output 2D format even when it's 1D, since
147+
# many functions, most notably PCov routines, assume an array storage
148+
# format, most notably to compute (y @ y.T)
149+
y = y.reshape((len(y), 1))
145150
else:
146151
X = check_array(
147152
X,
@@ -761,7 +766,6 @@ def _compute_pi(self, X, y=None):
761766
rank=None,
762767
)
763768

764-
print(self.k, pcovr_distance[0, 0], pcovr_distance.shape)
765769
if self.k < pcovr_distance.shape[0] - 1:
766770
v, U = eigsh(pcovr_distance, k=self.k, tol=1e-12)
767771
else:

tests/test_sample_pcov_cur.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class TestPCovCUR(unittest.TestCase):
1212
def setUp(self):
1313
self.X, self.y = load_boston(return_X_y=True)
14-
self.idx = [488, 283, 183, 380, 41, 438, 368, 374, 123, 353]
14+
self.idx = [492, 450, 183, 199, 380, 228, 399, 126, 412, 368]
1515

1616
def test_known(self):
1717
"""
@@ -50,7 +50,7 @@ def test_non_it(self):
5050
"""
5151
This test checks that the model can be run non-iteratively
5252
"""
53-
self.idx = [488, 492, 491, 374, 398, 373, 386, 400, 383, 382]
53+
self.idx = [492, 488, 491, 489, 374, 373, 386, 398, 383, 382]
5454
selector = PCovCUR(n_to_select=10, iterative=False)
5555
selector.fit(self.X, self.y)
5656

tests/test_sample_pcov_fps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class TestPCovFPS(unittest.TestCase):
99
def setUp(self):
1010
self.X, self.y = load_boston(return_X_y=True)
11-
self.idx = [39, 410, 492, 102, 54, 413, 34, 346, 126, 134, 433, 380]
11+
self.idx = [39, 410, 492, 102, 54, 413, 34, 126, 346, 134, 433, 380]
1212

1313
def test_restart(self):
1414
"""

0 commit comments

Comments
 (0)