You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When using sklearn.cross_decomposition.PLSRegression as the regressor, the MapieRegressor.fit method raises a shape mismatch error. The problem is that even when y has one feature, PLSRegression makes predictions of shape (n, 1), and MAPIE does not handle this case.
Traceback (with personal path info removed):
File [site-packages/mapie/estimator/estimator.py:364], in EnsembleRegressor.predict_calib(self, X)
[358] pred_matrix = np.full(
[359] shape=(n_samples, cv.get_n_splits(X)),
[360] fill_value=np.nan,
[361] dtype=float,
[362] )
[363] for i, ind in enumerate(indices):
--> [364] pred_matrix[ind, i] = np.array(
[365] predictions[i], dtype=float
[366] )
[367] self.k_[ind, i] = 1
[368] check_nan_in_aposteriori_prediction(pred_matrix)
ValueError: shape mismatch: value array of shape (50,1) could not be broadcast to indexing result of shape (50,)
To Reproduce
This code, closely based on the "Quick Start with MAPIE" in the documentation but using PLSRegression, will reproduce the error.
import numpy as np
from sklearn.cross_decomposition import PLSRegression
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from mapie.regression import MapieRegressor
regressor = PLSRegression()
X, y = make_regression(n_samples=500, n_features=20, noise=20, random_state=59)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)
mapie_regressor = MapieRegressor(regressor)
mapie_regressor.fit(X_train, y_train)
Expected behavior
I expect MAPIE to handle cases where an extra dimension is appended to the predictions. I am able to work around this by subclassing the PLSRegression class and overriding the predict method, but this is not ideal. Perhaps most scikit learn methods for univariate regression are more consistent but in my experience there are going to be methods that use an extra dimension in the output for various reasons so it should be handled internally by MAPIE.
The text was updated successfully, but these errors were encountered:
A similar one has been raised on scikit-learn (scikit-learn/scikit-learn#26549) and a modification was made such that PLSRegression returns an array of shape (n_samples, ) if y is one-dimensional. To have access to this modification, you have to upgrade your scikit-learn version to 1.3.2.
As sklearn changed its behavior, we will continue to require a 1D prediction for the moment but we might consider changing our behavior if other sklearn models acte the same way.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
When using
sklearn.cross_decomposition.PLSRegression
as the regressor, theMapieRegressor.fit
method raises a shape mismatch error. The problem is that even wheny
has one feature,PLSRegression
makes predictions of shape (n, 1), and MAPIE does not handle this case.Traceback (with personal path info removed):
To Reproduce
This code, closely based on the "Quick Start with MAPIE" in the documentation but using
PLSRegression
, will reproduce the error.Expected behavior
I expect MAPIE to handle cases where an extra dimension is appended to the predictions. I am able to work around this by subclassing the
PLSRegression
class and overriding thepredict
method, but this is not ideal. Perhaps most scikit learn methods for univariate regression are more consistent but in my experience there are going to be methods that use an extra dimension in the output for various reasons so it should be handled internally by MAPIE.The text was updated successfully, but these errors were encountered: