-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
LinearDiscriminantAnalysis.fit() fails if #samples == #labels. #12374
Copy link
Copy link
Closed
Description
Description
The LinearDiscriminantAnalysis.fit() method throws an exception if number of samples and number of labels is the same, i.e. each label has exactly one sample.
Steps/Code to Reproduce
>>> import sklearn.discriminant_analysis
>>> import numpy
>>> X = numpy.array([[0.5, 0.6], [0.6, 0.5]])
>>> y = numpy.array(["a", "b"])
>>> lda = sklearn.discriminant_analysis.LinearDiscriminantAnalysis()
>>> lda.fit(X, y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/…/lib/python3.6/site-packages/sklearn/discriminant_analysis.py", line 455, in fit
self._solve_svd(X, y)
File "/…/lib/python3.6/site-packages/sklearn/discriminant_analysis.py", line 379, in _solve_svd
fac = 1. / (n_samples - n_classes)
ZeroDivisionError: float division by zeroExpected Results
No exception, and a successful call to fit().
Actual Results
Exception, see above.
Versions
>>> sklearn.show_versions()
System
------
python: 3.6.6 (default, Jun 28 2018, 05:50:42) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
executable: /…/bin/python
machine: Darwin-15.6.0-x86_64-i386-64bit
BLAS
----
macros: NO_ATLAS_INFO=3, HAVE_CBLAS=None
lib_dirs:
cblas_libs: cblas
Python deps
-----------
pip: 18.0
setuptools: 28.8.0
sklearn: 0.20.0
numpy: 1.15.2
scipy: 1.1.0
Cython: None
pandas: None
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels