k-Nearest Neighbors: Fit
In this exercise, you will build your first classification model using the churn_df dataset, which has been preloaded for the remainder of the chapter.
The target, "churn", needs to be a single column with the same number of observations as the feature data. The feature data has already been converted into numpy arrays.
"account_length" and "customer_service_calls" are treated as features because account length indicates customer loyalty, and frequent customer service calls may signal dissatisfaction, both of which can be good predictors of churn.
Latihan ini adalah bagian dari kursus
Supervised Learning with scikit-learn
Petunjuk latihan
- Import
KNeighborsClassifierfromsklearn.neighbors. - Instantiate a
KNeighborsClassifiercalledknnwith6neighbors. - Fit the classifier to the data using the
.fit()method.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Import KNeighborsClassifier
from ____.____ import ____
y = churn_df["churn"].values
X = churn_df[["account_length", "customer_service_calls"]].values
# Create a KNN classifier with 6 neighbors
knn = ____(____=____)
# Fit the classifier to the data
knn.____(____, ____)