StinkySocks
StinkySocks

Reputation: 932

Cannot import 'KBinsDiscretizer'

Scikit-Learn gives an error: "cannot import name 'KBinsDiscretizer'". Run on Jupyter notebook with Anaconda distribution.

Minimal working example:

from sklearn.preprocessing import KBinsDiscretizer
X = [[-2, 1, -4,   -1],
     [-1, 2, -3, -0.5],
     [ 0, 3, -2,  0.5],
     [ 1, 4, -1,    2]]
est = KBinsDiscretizer(n_bins=3, encode='ordinal', strategy='uniform').fit(X)  
Xt = est.transform(X)
Xt  

-All the other functions within sklearn.preprocessing have worked fine.

Solution

It was a package management issue.

Open "Anaconda prompt" as the administrator

  1. Check the environments.
  2. Check the package version.
  3. Install the package in the environment.

Code:

conda env list #only base is listed
conda list -n base #scikit-learn 0.19.1  
conda install --name base scikit-learn=0.20.0 #install new version  

Upvotes: 4

Views: 3073

Answers (1)

Just type in the following command in anaconda prompt

conda update scikit-learn

It should upgrade to version 0.20

Upvotes: 2

Related Questions