导入Sklearn错误



,所以我一直在尝试安装numpy,scipy和sklearn,以进行我参加的课程。经过许多问题和无数次尝试,我安装了Pycharm,并使用了内置的包装管理器来获得Numpy和Scipy。我还安装了Sklearn,但是当我在代码中导入它时,我会收到以下错误:

Traceback (most recent call last):
  Python Shell, prompt 1, line 3
  File "C:UsersBergesAppDataLocalProgramsPythonPython35Libsite-packagessklearn__init__.py", line 57, in <module>
    from .base import clone
  File "C:UsersBergesAppDataLocalProgramsPythonPython35Libsite-packagessklearnbase.py", line 12, in <module>
    from .utils.fixes import signature
  File "C:UsersBergesAppDataLocalProgramsPythonPython35Libsite-packagessklearnutils__init__.py", line 11, in <module>
    from .validation import (as_float_array,
  File "C:UsersBergesAppDataLocalProgramsPythonPython35Libsite-packagessklearnutilsvalidation.py", line 18, in <module>
    from ..utils.fixes import signature
  File "C:UsersBergesAppDataLocalProgramsPythonPython35Libsite-packagessklearnutilsfixes.py", line 406, in <module>
    if np_version < (1, 12, 0):
builtins.TypeError: unorderable types: str() < int()

(我使用的是Python 3.5.2,当您在bash上运行Python3时,我可以很好地导入Sklearn,但似乎正在使用Python 3.4.3)

更新:

我安装了Anaconda,并试图从Wing IDE和ATOM运行以下代码:

import numpy as np
X = np.array([[-1,-1],[-2,-1],[-3.-2],[1,1],[2,1],[3,2]])
Y = np.array([1,1,1,2,2,2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X,Y)
print(clf.predict([[-0.8,-1]]))

i然后得到以下错误:

Traceback (most recent call last):
  File "C:UsersBergesDownloadstest.py", line 6, in <module>
    clf.fit(X,Y)
  File "C:UsersBergesAnaconda3libsite-packagessklearnnaive_bayes.py", line 173, in fit
    X, y = check_X_y(X, y)
  File "C:UsersBergesAnaconda3libsite-packagessklearnutilsvalidation.py", line 510, in check_X_y
    ensure_min_features, warn_on_dtype, estimator)
  File "C:UsersBergesAnaconda3libsite-packagessklearnutilsvalidation.py", line 373, in check_array
    array = np.array(array, dtype=dtype, order=order, copy=copy)
ValueError: setting an array element with a sequence.

如果您只想让某些内容启动并运行一门课程,并且想在Windows上工作。然后,我建议您安装Anaconda软件包管理器。它的工作方式就像在Windows上的微风一样,非常容易安装,并且包含所有必要的软件包(您不必担心版本不匹配和所有内容)。

安装Anaconda Manager后,将Pycharm解释器位置更改为Anaconda安装的Python解释器。

链接:https://www.continuum.io/downloads可用软件包列表:https://docs.continuum.io/anaconda/pkg-docs

您错过了导致此错误的小细节。

在X数组中您键入[-3. -2]而不是[-3, -2]

所以您错过了逗号。

以下工作正常:

import numpy as np
X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
Y = np.array([1, 1, 1, 2, 2, 2])
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(X, Y)
print(clf.predict([[-0.8, -1]]))

结果:

[1]

相关内容

  • 没有找到相关文章

最新更新