NameError:名称“ sklearn”未定义

时间:2019-08-05 18:34:02

标签: python scikit-learn jupyter-notebook anaconda

我正在运行前馈神经网络,并希望获得一条线的混淆矩阵

sklearn.metrics.confusion_matrix(goldLabel_array, predictions, sample_weight=None, labels=None)

但是当我运行它时,它在标题中显示了错误消息。 我安装了scikit-learn和sklearn。当我运行“点列表”时,将列出sklearn,但版本为0.0。当我运行conda install sklearn时,它会为我提供以下信息:

Collecting package metadata (current_repodata.json): done
Solving environment: failed with current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - sklearn

Current channels:

  - https://conda.anaconda.org/loopbio/win-64
  - https://conda.anaconda.org/loopbio/noarch
  - https://repo.anaconda.com/pkgs/main/win-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/win-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/msys2/win-64
  - https://repo.anaconda.com/pkgs/msys2/noarch
  - https://conda.anaconda.org/conda-forge/win-64
  - https://conda.anaconda.org/conda-forge/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page. 

1 个答案:

答案 0 :(得分:1)

该错误与安装无关。它告诉您尚未将库导入到在代码中调用它的位置。

编辑是直接导入confusion_matrix,因此需要直接引用,而不是通过sklearn引用。

confusion_matrix(goldLabel_array, predictions, sample_weight=None, labels=None)

与您的其他通话相同。