Skip to content

PLSRegression not working with VotingRegressor #26549

Closed
@michaelsimmler

Description

@michaelsimmler

Hi,

Unfortunately, PLSRegression does not work in VotingRegressor. Likely related to PLSRegression returning predictions in shape of (n_samples, 1) instead of (n_samples,) like other single-target regressors.

thanks!

import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.cross_decomposition import PLSRegression
from sklearn.ensemble import VotingRegressor

r1 = LinearRegression()
r2 = PLSRegression()

X = np.array([[1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36]])
y = np.array([2, 6, 12, 20, 30, 42])

r1.fit(X, y).predict(X).shape
(6,)
r2.fit(X, y).predict(X).shape
(6, 1)
er = VotingRegressor([('lr', r1), ('plsr', r2)])
er.fit(X, y).predict(X)
Traceback (most recent call last):
  Cell In[25], line 1
    er.fit(X, y).predict(X)
  File ~/code/scikit-learn/sklearn/ensemble/_voting.py:625 in predict
    return np.average(self._predict(X), axis=1, weights=self._weights_not_none)
  File ~/code/scikit-learn/sklearn/ensemble/_voting.py:69 in _predict
    return np.asarray([est.predict(X) for est in self.estimators_]).T
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (2, 6) + inhomogeneous part.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions