我在IBM BlueMix上运行ipython笔记本,默认版本sklearn是版本0.11 - 我想升级到sklearn-0.18。
编辑:我的意思是我要升级到sklearn-0.17。
import sklearn
print sklearn.__version__
0.11
BlueMix文档说要使用:
!pip install -U --user sklearn
这是输出:
You are using pip version 7.1.0, however version 8.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already up-to-date: sklearn in /gpfs/global_fs01/sym_shared/YPProdSpark/user/s3b2-519e0ce881616c-546ab68fb1ed/.local/lib/python2.7/site-packages
Collecting scikit-learn (from sklearn)
Using cached scikit-learn-0.17.tar.gz
Installing collected packages: scikit-learn
Running setup.py install for scikit-learn
Successfully installed scikit-learn-0.11
这似乎不起作用。也许它与老版本的pip有关...
!pip install --upgrade --user pip
You are using pip version 7.1.0, however version 8.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting pip
Using cached pip-8.0.2-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-7.1.0
import pip
print pip.__version__
7.1.0
好的,所以它不仅仅是sklearn。问题似乎是某些升级的软件包没有安装在正确的路径中。
经过一番调查后,我发现:
!ls -al ~/.local/lib/python2.7/site-packages
total 0
drwx------ 8 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 18:06 .
drwx------ 3 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 15:30 ..
drwxr-xr-x 10 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 15:46 pip
drwxr-xr-x 2 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 15:53 pip-8.0.1.dist-info
drwxr-xr-x 2 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 18:40 pip-8.0.2.dist-info
drwxr-xr-x 2 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 18:06 scikit_learn-0.17-py2.7.egg-info
drwxr-xr-x 25 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 18:06 sklearn
drwxr-xr-x 2 s3b2-519e0ce881616c-546ab68fb1ed users 4096 Jan 22 15:48 sklearn-0.0-py2.7.egg-info
所以,试试吧......
import sys
sys.path.insert(0, '/gpfs/fs01/user/s3b2-519e0ce881616c-546ab68fb1ed/.local/lib/python2.7/site-packages/')
reload(sklearn)
print sklearn.__version__
0.17
现在看起来版本是正确的,所以尝试从sklearn-0.17导入一些新函数。
from sklearn.metrics import roc_auc_score
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-169-8985e3efac9f> in <module>()
----> 1 from sklearn.metrics import roc_auc_score
ImportError: cannot import name roc_auc_score
我在版本0.17中应该出现同样的错误。在尝试导入时,似乎python正在引用旧的sklearn版本0.11。
感谢任何帮助。
答案 0 :(得分:0)
问题解决了!
BlueMix似乎每次登录时都会将iPython环境初始化为sklearn-0.11。显然,一旦我导入sklearn verison 0.11,使用0.17版本的新路径重新加载sklearn并不会改变任何内容。
在进行初始导入之前,我需要修改指向版本0.17的路径,然后初始导入将引用更新版本,如此...
import sys
sys.path.insert(0, '/gpfs/fs01/user/s3b2-519e0ce881616c-546ab68fb1ed/.local/lib/python2.7/site-packages/')
import sklearn
print sklearn.__version__
0.17
现在,我可以成功执行以下操作而不会出错:
from sklearn.metrics import roc_auc_score
from sklearn.ensemble import RandomForestClassifier