3. An Introduction to Classification
Activity 3.01: Increasing the Accuracy of Credit Scoring
Solution:
- Open a new Jupyter Notebook file and execute all the steps from the previous exercise, Exercise 3.04, K-Nearest Neighbors Classification in Scikit-Learn.
- Import
neighbors
fromsklearn
:from sklearn import neighbors
- Create a function called
fit_knn
that takes the following parameters:k
,p
,features_train
,label_train
,features_test
, andlabel_test
. This function will fitKNeighborsClassifier
with the training set and print the accuracy score for the training and testing sets, as shown in the following code snippet:def fit_knn(k, p, features_train, label_train, \             features_test, label_test):     classifier = neighbors.KNeighborsClassifier(n_neighbors=k, p=p)     classifier.fit(features_train, label_train)     return classifier.score...