Author - Mohit Rathore mrmohitrathoremr@gmail.com - markroxor.in
Licensed under The MIT License - https://opensource.org/licenses/MIT
import numpy as np
from sklearn import datasets
from sklearn.utils import shuffle
from fromscratchtoml.neighbors import KNeighborsClassifier
from fromscratchtoml.toolbox import binary_visualize
%matplotlib inline
iris = datasets.load_iris()
X = iris.data[:, :2]
Y = iris.target[:]
X, Y = shuffle(X, Y, random_state=10)
Xtrain = X[:120]
Ytrain = Y[:120]
Xtest = X[120:]
Ytest = Y[120:]
knn = KNeighborsClassifier()
knn.fit(Xtrain, Ytrain)
knn.predict(Xtest)
binary_visualize(X, Y, coarse=50, color_seed=1980)
binary_visualize(np.array(X), clf=knn, draw_contour=True, coarse=50, color_seed=1980)