Python – NameError: name ‘sklearn’ is not defined

anacondajupyter-notebookpythonscikit-learn

I am running a feed forward neural network and want to get a confusion matrix with the line

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

But when I am running it, it gives me the error message in the headline.
I installed scikit-learn and sklearn. WhenI am running 'pip list', sklearn is listed, but with the version 0.0. When I am running conda install sklearn it gives me the following:

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. 

Best Solution

The error is nothing to do with installing. It is telling you that you have not imported the library into the place you are calling it in your code.

Edit You're importing confusion_matrix directly, so you need to reference it directly, not via sklearn.

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

and the same with your other calls.

Related Question