April 2018
Beginner to intermediate
282 pages
6h 52m
English
Again, we follow a similar process for KNN as we did to create the previous models. We import the KNeighborsClassifier method from scikit-learn's library to use the KNN algorithm for modeling. Next, we import the HR attrition dataset using the pandas library and split the dataset into train and test sets:
import numpy as npimport pandas as pdfrom sklearn.metrics import accuracy_scorefrom sklearn.neighbors import KNeighborsClassifierhr_data = pd.read_csv('data/hr.csv', header=0)hr_data.head()hr_data = hr_data.dropna()print(" Data Set Shape ", hr_data.shape)print(list(hr_data.columns))print(" Sample Data ", hr_data.head())data_trnsf = pd.get_dummies(hr_data, columns =['salary', 'sales'])data_trnsf.columns ...