Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

KNN with sklearn

# Import KNeighborsClassifier from sklearn.neighbors
from sklearn.neighbors import KNeighborsClassifier 

# Create arrays for the features and the response variable
y = df['features'].values
X = df.drop('features', axis=1).values

# Create a k-NN classifier with 6 neighbors
knn = KNeighborsClassifier(n_neighbors=6)

# Fit the classifier to the data
knn.fit(X, y)
Source by campus.datacamp.com #
 
PREVIOUS NEXT
Tagged: #KNN #sklearn
ADD COMMENT
Topic
Name
9+5 =