PLOTTING KNN DECISION REGIONS

feb. 25, 2020
·
samuel mignot
In [26]:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
from mlxtend.plotting import plot_decision_regions
from sklearn.decomposition import PCA
In [27]:
X, y = load_iris(return_X_y=True)
In [28]:
X=PCA(2).fit_transform(X)
In [29]:
knn = KNeighborsClassifier()
knn.fit(X,y)
Out[29]:
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
                     metric_params=None, n_jobs=None, n_neighbors=5, p=2,
                     weights='uniform')
In [30]:
plot_decision_regions(clf=knn, X=X, y=y)
/Users/samuelmignot/.pyenv/versions/3.8.0/lib/python3.8/site-packages/mlxtend/plotting/decision_regions.py:249: MatplotlibDeprecationWarning: Passing unsupported keyword arguments to axis() will raise a TypeError in 3.3.
  ax.axis(xmin=xx.min(), xmax=xx.max(), y_min=yy.min(), y_max=yy.max())
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0x134e0d7c0>
In [ ]: