scikit-learn / scikit-learn

scikit-learn: machine learning in Python
https://scikit-learn.org
BSD 3-Clause "New" or "Revised" License
59.45k stars 25.27k forks source link

No module named 'sklearn.exceptions' #6968

Closed mikepqr closed 8 years ago

mikepqr commented 8 years ago

Description

No module named 'sklearn.exceptions'

Steps/Code to Reproduce

Tried on both Linux and OS X, and with both virtualenv and anaconda:

pip install scikit-learn (or pip install --no-use-wheel scikit-learn, or conda install scikit-learn), then from sklearn.exceptions import NotFittedError

Expected Results

sklearn.exceptions is imported, per e.g. http://scikit-learn.org/dev/modules/generated/sklearn.exceptions.NotFittedError.html

Actual Results

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-098ac4f586a2> in <module>()
----> 1 from sklearn.exceptions import NotFittedError

ImportError: No module named 'sklearn.exceptions'

Note that sklearn.__file__ points to a directory containing a scikit-learn installation that, as far as I can tell, works in all other ways. But exceptions.py is missing:

>>> import sklearn
>>> sklearn.__file__
'/home/user/directory/venv/lib/python3.4/site-packages/sklearn/__init__.py'
$ ls /home/user/directory/venv/lib/python3.4/site-packages/sklearn/
base.py                   feature_selection/         naive_bayes.py
_build_utils.py           gaussian_process/          neighbors/
calibration.py            grid_search.py             neural_network/
__check_build/            __init__.py                pipeline.py
cluster/                  _isotonic.cpython-34m.so*  preprocessing/
covariance/               isotonic.py                __pycache__/
cross_decomposition/      kernel_approximation.py    qda.py
cross_validation.py       kernel_ridge.py            random_projection.py
datasets/                 lda.py                     semi_supervised/
decomposition/            learning_curve.py          setup.py
discriminant_analysis.py  linear_model/              svm/
dummy.py                  manifold/                  tests/
ensemble/                 metrics/                   tree/
externals/                mixture/                   utils/
feature_extraction/       multiclass.py

Versions

Have tried this on several platforms (including python 2.7 and python 3.5), but here's an example:

In [3]: import sys; print("Python", sys.version)
Python 3.4.3 (default, Mar 26 2015, 22:03:40)
[GCC 4.9.2]

In [4]: import numpy; print("NumPy", numpy.__version__)
NumPy 1.11.0

In [5]: import scipy; print("SciPy", scipy.__version__)
SciPy 0.17.1

In [6]: import sklearn; print("Scikit-Learn", sklearn.__version__)
Scikit-Learn 0.17.1
nelson-liu commented 8 years ago

the exceptionsmodule isn't in 0.17.1 Notice that the URL of the docs you link to have "dev" in them, indicating that theyre for version 0.18.dev0. You have version 0.17.1, so you should install scikit-learn from the master branch of this repo (e.g. with pip or with setup,py )and it should work.

mikepqr commented 8 years ago

Ah, of course!

Is there any way to access the exceptions defined by sklearn without upgrading to unstable code?

maniteja123 commented 8 years ago

I suppose some of the base exceptions are in utils.validation.py while the others are inheriting them like NeighborsWarning. They probably should be accessible. Cheers.

nelson-liu commented 8 years ago

@williamsmj Also, I wouldn't say that just because it's in the 'dev' version, it is "unstable" or anything. The code pushed to master passes the same test suite that 0.17.1 does, it's just that there's been no release since the code was added.

mikepqr commented 8 years ago

Understood, but I'm in an environment where I need to deploy tagged releases rather than track master.