-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
LogisticRegression does not accept multiple targets in output #12342
Copy link
Copy link
Closed
Description
Description
According to documentation, LogisticRegression can accept multiple output targets:
X : {array-like, sparse matrix}, shape (n_samples, n_features)
Training vector, where n_samples is the number of samples and n_features is the number of features.y : array-like, shape (n_samples,) or (n_samples, n_targets)
Target vector relative to X.
Yet passing an (n_samples, n_targets) array like to fit causes a ValueError: bad input shape exception.
Steps/Code to Reproduce
Test case:
import sklearn.linear_model as sklm
import numpy as np
X=np.array([[0.809843, 0.784541, 0.58678 , 0.770611],
[0.829087, 0.596997, 0.500606, 0.726285],
[0.697035, 0.441521, 0.488789, 0.592827],
[0.647602, 0.622782, 0.644802, 0.731291]])
y = np.array([[ 0.05041462, 0.03427447, 0.08056339],
[ 0.0495809 , 0.07450889, 0.202567 ],
[-0.15796176, -0.14194441, 0.10968024],
[-0.15796176, -0.14194441, 0.10968024]])
regressor = sklm.LogisticRegression(multi_class='multinomial', solver='lbfgs')
regressor.fit(X, y)Expected Results
No exception is thrown, a fitted logistic regressor is returned.
Actual Results
Results in:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-313-79cea356b42d> in <module>()
1 regressor = sklm.LogisticRegression(multi_class='multinomial', solver='lbfgs')
----> 2 regressor.fit(X, y)
/usr/local/lib/python3.6/dist-packages/sklearn/linear_model/logistic.py in fit(self, X, y, sample_weight)
1282
1283 X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1284 accept_large_sparse=solver != 'liblinear')
1285 check_classification_targets(y)
1286 self.classes_ = np.unique(y)
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
750 dtype=None)
751 else:
--> 752 y = column_or_1d(y, warn=True)
753 _assert_all_finite(y)
754 if y_numeric and y.dtype.kind == 'O':
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py in column_or_1d(y, warn)
786 return np.ravel(y)
787
--> 788 raise ValueError("bad input shape {0}".format(shape))
789
790
ValueError: bad input shape (4, 3)
Versions
System
------
python: 3.6.3 (default, Oct 3 2017, 21:45:48) [GCC 7.2.0]
executable: /usr/bin/python3
machine: Linux-3.10.0-327.4.5.el7.x86_64-x86_64-with-Ubuntu-17.10-artful
BLAS
----
macros:
lib_dirs:
cblas_libs: cblas
Python deps
-----------
pip: 10.0.1
setuptools: 36.2.7
sklearn: 0.20.0
numpy: 1.15.2
scipy: 1.1.0
Cython: 0.28.5
pandas: 0.23.4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels