rasbt / python-machine-learning-book

The "Python Machine Learning (1st edition)" book code repository and info resource
MIT License
12.18k stars 4.39k forks source link

Windows 10, ImportError: cannot import name 'plot_decision_regions' #49

Closed Megaloxantha closed 7 years ago

Megaloxantha commented 7 years ago

Hello,

I was trying to execute the code:

%matplotlib inline
from sklearn.linear_model import LogisticRegression 
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
from mlxtend.evaluate import plot_decision_regions

iris = load_iris()
y, X = iris.target, iris.data[:, [0, 2]]  # only use 2 features
lr = LogisticRegression(C=100.0, 
                        class_weight=None, 
                        dual=False, 
                        fit_intercept=True,
                        intercept_scaling=1, 
                        max_iter=100, 
                        multi_class='multinomial', 
                        n_jobs=1,
                        penalty='l2', 
                        random_state=1, 
                        solver='newton-cg', 
                        tol=0.0001,
                        verbose=0, 
                        warm_start=False)
lr.fit(X, y)
plot_decision_regions(X=X, y=y, clf=lr, legend=2)
plt.xlabel('sepal length')
plt.ylabel('petal length')
plt.show()

but it returned following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-9b78ac9a656a> in <module>()
      3 from sklearn.datasets import load_iris
      4 import matplotlib.pyplot as plt
----> 5 from mlxtend.evaluate import plot_decision_regions
      6 
      7 iris = load_iris()

ImportError: cannot import name 'plot_decision_regions'

I installed mlxtend package. What am I doing wrong? Could You help me? Thanks in advance!

rasbt commented 7 years ago

Thanks for the note and sorry about that. I moved mlxtend.evaluate.plot_decision_regions to mlxtend.plotting.plot_decision_regions a while back and forgot to adjust the references in this repo. So, replacing evaluate by plotting should solve the issue -- let me know if you have further troubles. (The references in this repo should be all updated now.)

Megaloxantha commented 7 years ago

Works like charm now :) Thank You!