KNN¶
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as ply
import seaborn as sns
%matplotlib inline
In [2]:
iris = sns.load_dataset("iris")
In [5]:
sns.lmplot("petal_length", "petal_width", data=iris, hue="species", fit_reg=False)
Out[5]:
<seaborn.axisgrid.FacetGrid at 0x10fc2acf8>
In [10]:
from sklearn import neighbors
knn = neighbors.KNeighborsClassifier(n_neighbors=1)
X = iris[["petal_length", "petal_width"]]
y = iris.species.astype("category").cat.codes
knn.fit(X, y)
knn
Out[10]:
KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',
metric_params=None, n_jobs=1, n_neighbors=1, p=2,
weights='uniform')
In [12]:
knn.get_params()
Out[12]:
{'algorithm': 'auto',
'leaf_size': 30,
'metric': 'minkowski',
'metric_params': None,
'n_jobs': 1,
'n_neighbors': 1,
'p': 2,
'weights': 'uniform'}
In [ ]:
In [ ]:
In [ ]: