当我尝试导入“ sklearn”并使用它时,出现“属性错误”,
## Modeling
# Multiple Linear REgression (Least Square fitting)
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
Jupyter笔记本电脑的错误如下,
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-33-9fc361c79a41> in <module>()
2 # Multiple Linear REgression (Least Square fitting)
3
----> 4 from sklearn.model_selection import cross_val_score
5 from sklearn.linear_model import LinearRegression
6 #from sklearn.model_selection.train_test_split import train_test_split
D:\Anaconda_details\lib\site-packages\sklearn\model_selection\__init__.py in <module>()
17 from ._split import check_cv
18
---> 19 from ._validation import cross_val_score
20 from ._validation import cross_val_predict
21 from ._validation import cross_validate
D:\Anaconda_details\lib\site-packages\sklearn\model_selection\_validation.py in <module>()
29 from ..utils._joblib import logger
30 from ..externals.six.moves import zip
---> 31 from ..metrics.scorer import check_scoring, _check_multimetric_scoring
32 from ..exceptions import FitFailedWarning
33 from ._split import check_cv
D:\Anaconda_details\lib\site-packages\sklearn\metrics\__init__.py in <module>()
5
6
----> 7 from .ranking import auc
8 from .ranking import average_precision_score
9 from .ranking import coverage_error
D:\Anaconda_details\lib\site-packages\sklearn\metrics\ranking.py in <module>()
34 from ..utils.sparsefuncs import count_nonzero
35 from ..exceptions import UndefinedMetricWarning
---> 36 from ..preprocessing import label_binarize
37
38 from .base import _average_binary_score
D:\Anaconda_details\lib\site-packages\sklearn\preprocessing\__init__.py in <module>()
4 """
5
----> 6 from ._function_transformer import FunctionTransformer
7
8 from .data import Binarizer
D:\Anaconda_details\lib\site-packages\sklearn\preprocessing\_function_transformer.py in <module>()
3 from ..base import BaseEstimator, TransformerMixin
4 from ..utils import check_array
----> 5 from ..utils.testing import assert_allclose_dense_sparse
6 from ..externals.six import string_types
7
D:\Anaconda_details\lib\site-packages\sklearn\utils\testing.py in <module>()
758 import pytest
759
--> 760 skip_if_32bit = pytest.mark.skipif(_IS_32BIT,
761 reason='skipped on 32bit platforms')
762 skip_travis = pytest.mark.skipif(os.environ.get('TRAVIS') == 'true',
AttributeError: module 'pytest' has no attribute 'mark'
我尝试使用pip安装/卸载 pip卸载scikit-learn pip install scikit-学习
(基本)C:\ Users \ shashi> pip install scikit-learn
我无法卸载sckit-learn软件包,这似乎是一些路径问题,
(base) C:\Users\shashi>pip uninstall scikit-learn
Uninstalling scikit-learn-0.20.0:
Would remove:
d:\anaconda_details\lib\site-packages\scikit_learn-0.20.0-py3.5.egg-info
d:\anaconda_details\lib\site-packages\sklearn
Proceed (y/n)? y
Exception:
Traceback (most recent call last):
File "D:\Anaconda_details\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
OSError: [WinError 17] The system cannot move the file to a different disk drive: 'd:\\anaconda_details\\lib\\site-packages\\sklearn' -> 'C:\\Users\\sh289528\\AppData\\Local\\Temp\\pip-uninstall-w3d2aqtz\\anaconda_details\\lib\\site-packages\\sklearn'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Anaconda_details\lib\site-packages\pip\_internal\basecommand.py", line 228, in main
status = self.run(options, args)
File "D:\Anaconda_details\lib\site-packages\pip\_internal\commands\uninstall.py", line 68, in run
auto_confirm=options.yes, verbose=self.verbosity > 0,
File "D:\Anaconda_details\lib\site-packages\pip\_internal\req\req_install.py", line 661, in uninstall
uninstalled_pathset.remove(auto_confirm, verbose)
File "D:\Anaconda_details\lib\site-packages\pip\_internal\req\req_uninstall.py", line 219, in remove
renames(path, new_path)
File "D:\Anaconda_details\lib\site-packages\pip\_internal\utils\misc.py", line 273, in renames
shutil.move(old, new)
File "D:\Anaconda_details\lib\shutil.py", line 556, in move
rmtree(src)
File "D:\Anaconda_details\lib\shutil.py", line 494, in rmtree
return _rmtree_unsafe(path, onerror)
File "D:\Anaconda_details\lib\shutil.py", line 384, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "D:\Anaconda_details\lib\shutil.py", line 389, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
File "D:\Anaconda_details\lib\shutil.py", line 387, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'd:\\anaconda_details\\lib\\site-packages\\sklearn\\feature_extraction\\_hashing.cp35-win_amd64.pyd'
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
尝试安装Pip时再次出现错误。
(base) C:\Users\shashi>pip install scikit-learn
Collecting scikit-learn
Downloading https://files.pythonhosted.org/packages/d3/fa/b50821115c16e9b8ca307d3788e3dd1ec71cade3e564953ed7330a1fa3e0/scikit_learn-0.20.3-cp35-cp35m-win_amd64.whl (4.8MB)
100% |################################| 4.8MB 546kB/s
Requirement already satisfied: scipy>=0.13.3 in d:\anaconda_details\lib\site-packages (from scikit-learn) (1.1.0)
Requirement already satisfied: numpy>=1.8.2 in d:\anaconda_details\lib\site-packages (from scikit-learn) (1.15.2)
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
Installing collected packages: scikit-learn
Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'D:\\Anaconda_details\\Lib\\site-packages\\sklearn\\feature_extraction\\_hashing.cp35-win_amd64.pyd'
Consider using the `--user` option or check the permissions.
You are using pip version 18.0, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
我尝试使用conda进行卸载和安装。但这也无济于事。
(base) C:\Users\shashi>conda update scikit-learn
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.5
latest version: 4.6.9
Please update conda by running
$ conda update -n base -c defaults conda