Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Created on Cognitive Class Labs
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"<a href=\"https://www.bigdatauniversity.com\"><img src = \"https://ibm.box.com/shared/static/cw2c7r3o20w9zn8gkecaeyjhgw3xdgbj.png\" width = 400, align = \"center\"></a>\n",
"# <center>K-Nearest Neighbors</center>"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"In this Lab you will load a customer dataset, fit the data, and use K-Nearest Neighbors to predict a data point. But what is **K-Nearest Neighbors**?"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"**K-Nearest Neighbors** is an algorithm for supervised learning. Where the data is 'trained' with data points corresponding to their classification. Once a point is to be predicted, it takes into account the 'K' nearest points to it to determine it's classification."
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Here's an visualization of the K-Nearest Neighbors algorithm.\n",
"\n",
"<img src = \"https://ibm.box.com/shared/static/mgkn92xck0z05v7yjq8pqziukxvc2461.png\">"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"In this case, we have data points of Class A and B. We want to predict what the star (test data point) is. If we consider a k value of 3 (3 nearest data points) we will obtain a prediction of Class B. Yet if we consider a k value of 6, we will obtain a prediction of Class A."
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"In this sense, it is important to consider the value of k. But hopefully from this diagram, you should get a sense of what the K-Nearest Neighbors algorithm is. It considers the 'K' Nearest Neighbors (points) when it predicts the classification of the test point."
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Lets load requiered libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [],
"source": [
"import itertools\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.ticker import NullFormatter\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.ticker as ticker\n",
"from sklearn import preprocessing\n",
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### About dataset"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Imagine a telecommunications provider has segmented its customer base by service usage patterns, categorizing the customers into four groups. If demographic data can be used to predict group membership, the company can customize offers for individual prospective customers. It is a classification problem. That is, given the dataset, with predefined labels, we need to build a model to be used to predict class of a new or unknown case. \n",
"\n",
"The example focuses on using demographic data, such as region, age, and marital, to predict usage patterns. \n",
"\n",
"The target field, called __custcat__, has four possible values that correspond to the four customer groups, as follows:\n",
" 1- Basic Service\n",
" 2- E-Service\n",
" 3- Plus Service\n",
" 4- Total Service\n",
"\n",
"Our objective is to build a classifier, to predict the class of unknown cases. We will use a specific type of classification called K nearest neighbour.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Lets download the dataset. To download the data, we will use !wget to download it from IBM Object Storage."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2019-08-15 19:34:22-- https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/teleCust1000t.csv\n",
"Resolving s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)... 67.228.254.193\n",
"Connecting to s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)|67.228.254.193|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 37048 (36K) [text/csv]\n",
"Saving to: ‘teleCust1000t.csv’\n",
"\n",
"teleCust1000t.csv 100%[===================>] 36.18K --.-KB/s in 0.03s \n",
"\n",
"2019-08-15 19:34:22 (1.20 MB/s) - ‘teleCust1000t.csv’ saved [37048/37048]\n",
"\n"
]
}
],
"source": [
"!wget -O teleCust1000t.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/teleCust1000t.csv"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"__Did you know?__ When it comes to Machine Learning, you will likely be working with large datasets. As a business, where can you host your data? IBM is offering a unique opportunity for businesses, with 10 Tb of IBM Cloud Object Storage: [Sign up now for free](http://cocl.us/ML0101EN-IBM-Offer-CC)"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Load Data From CSV File "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>region</th>\n",
" <th>tenure</th>\n",
" <th>age</th>\n",
" <th>marital</th>\n",
" <th>address</th>\n",
" <th>income</th>\n",
" <th>ed</th>\n",
" <th>employ</th>\n",
" <th>retire</th>\n",
" <th>gender</th>\n",
" <th>reside</th>\n",
" <th>custcat</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2</td>\n",
" <td>13</td>\n",
" <td>44</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>64.0</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>2</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>3</td>\n",
" <td>11</td>\n",
" <td>33</td>\n",
" <td>1</td>\n",
" <td>7</td>\n",
" <td>136.0</td>\n",
" <td>5</td>\n",
" <td>5</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>6</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>68</td>\n",
" <td>52</td>\n",
" <td>1</td>\n",
" <td>24</td>\n",
" <td>116.0</td>\n",
" <td>1</td>\n",
" <td>29</td>\n",
" <td>0.0</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2</td>\n",
" <td>33</td>\n",
" <td>33</td>\n",
" <td>0</td>\n",
" <td>12</td>\n",
" <td>33.0</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2</td>\n",
" <td>23</td>\n",
" <td>30</td>\n",
" <td>1</td>\n",
" <td>9</td>\n",
" <td>30.0</td>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>0.0</td>\n",
" <td>0</td>\n",
" <td>4</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" region tenure age marital address income ed employ retire gender \\\n",
"0 2 13 44 1 9 64.0 4 5 0.0 0 \n",
"1 3 11 33 1 7 136.0 5 5 0.0 0 \n",
"2 3 68 52 1 24 116.0 1 29 0.0 1 \n",
"3 2 33 33 0 12 33.0 2 0 0.0 1 \n",
"4 2 23 30 1 9 30.0 1 2 0.0 0 \n",
"\n",
" reside custcat \n",
"0 2 1 \n",
"1 6 4 \n",
"2 2 3 \n",
"3 1 1 \n",
"4 4 3 "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv('teleCust1000t.csv')\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"# Data Visualization and Anylisis \n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"#### Let’s see how many of each class is in our data set "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"3 281\n",
"1 266\n",
"4 236\n",
"2 217\n",
"Name: custcat, dtype: int64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['custcat'].value_counts()"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"#### 281 Plus Service, 266 Basic-service, 236 Total Service, and 217 E-Service customers\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can easily explore your data using visualization techniques:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7ffaf600d400>]],\n",
" dtype=object)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEICAYAAAC9E5gJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAASIUlEQVR4nO3dfbBcdX3H8feHYMES5aFgJk2iN9SUEWTqwy3qoPam0IKihNpi41AbKk7qFDva2qlBOq39g05sp452kDqpMEaxXFKQISPDKJN6q51qkSBPAVOiBAjEpCIIUUsb/PaPPddu0nuTu7m7e3fh/Zq5s2d/+ztnP3tY7ueesw9JVSFJem47bK4DSJLmnmUgSbIMJEmWgSQJy0CShGUgScIy0LNMki1JxuY6hzRs4ucMJEkeGUiSLAM9uyTZnuTMJB9OsiHJZ5I81Zw+Gm2btyTJ55P8Z5LHklzejB+W5M+SPJhkd7P+0c1tI0kqye8leTjJ40nek+SXk9yV5InJ7bTdz7uS3NfM/WKSl/R3j0gzYxno2excYBw4BtgITP7Cnwd8AXgQGAEWNfMALmx+lgMnAvMn12vzGmAZ8NvAx4BLgTOBU4C3J/mV5n7OAz4EvA04AfgqcE2XH6PUFb5moGeVJNuBdwOvB15fVWc24ycDm6vq+UleR6scFlbV3v3W3wRcX1VXNNdPAu4Bng8sBh4AFlfVI83tjwF/UFXXNtevB75aVR9LcjNwXVVd2dx2GLAHeFlVPdjL/SB1yiMDPZt9t235R8CRSQ4HlgAP7l8EjZ+ndcQw6UHgcGBB29iutuUfT3F9frP8EuDjzemjJ4DvA6F1JCINFMtAz0UPAy9uimF/j9L6JT7pxcBe9v2F38n9/H5VHdP28/yq+rdD2JbUU5aBnotuBXYCa5McleTIJKc3t10D/FGSpUnmA38FXDvNUcTBfBK4JMkpAEmOTnJ+Nx6A1G2WgZ5zquoZ4K3AS4GHgB20XgwGuAr4LPAVWq8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SuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"df.hist(column='income', bins=50)"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Feature set"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Lets defind feature sets, X:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['region', 'tenure', 'age', 'marital', 'address', 'income', 'ed',\n",
" 'employ', 'retire', 'gender', 'reside', 'custcat'],\n",
" dtype='object')"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To use scikit-learn library, we have to convert the Pandas data frame to a Numpy array:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2., 13., 44., 1., 9., 64., 4., 5., 0., 0., 2.],\n",
" [ 3., 11., 33., 1., 7., 136., 5., 5., 0., 0., 6.],\n",
" [ 3., 68., 52., 1., 24., 116., 1., 29., 0., 1., 2.],\n",
" [ 2., 33., 33., 0., 12., 33., 2., 0., 0., 1., 1.],\n",
" [ 2., 23., 30., 1., 9., 30., 1., 2., 0., 0., 4.]])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = df[['region', 'tenure','age', 'marital', 'address', 'income', 'ed', 'employ','retire', 'gender', 'reside']] .values #.astype(float)\n",
"X[0:5]\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"What are our lables?"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 4, 3, 1, 3])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"y = df['custcat'].values\n",
"y[0:5]"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"## Normalize Data "
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Data Standardization give data zero mean and unit variance, it is good practice, especially for algorithms such as KNN which is based on distance of cases:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.02696767, -1.055125 , 0.18450456, 1.0100505 , -0.25303431,\n",
" -0.12650641, 1.0877526 , -0.5941226 , -0.22207644, -1.03459817,\n",
" -0.23065004],\n",
" [ 1.19883553, -1.14880563, -0.69181243, 1.0100505 , -0.4514148 ,\n",
" 0.54644972, 1.9062271 , -0.5941226 , -0.22207644, -1.03459817,\n",
" 2.55666158],\n",
" [ 1.19883553, 1.52109247, 0.82182601, 1.0100505 , 1.23481934,\n",
" 0.35951747, -1.36767088, 1.78752803, -0.22207644, 0.96655883,\n",
" -0.23065004],\n",
" [-0.02696767, -0.11831864, -0.69181243, -0.9900495 , 0.04453642,\n",
" -0.41625141, -0.54919639, -1.09029981, -0.22207644, 0.96655883,\n",
" -0.92747794],\n",
" [-0.02696767, -0.58672182, -0.93080797, 1.0100505 , -0.25303431,\n",
" -0.44429125, -1.36767088, -0.89182893, -0.22207644, -1.03459817,\n",
" 1.16300577]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X = preprocessing.StandardScaler().fit(X).transform(X.astype(float))\n",
"X[0:5]"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Train Test Split \n",
"Out of Sample Accuracy is the percentage of correct predictions that the model makes on data that that the model has NOT been trained on. Doing a train and test on the same dataset will most likely have low out-of-sample accuracy, due to the likelihood of being over-fit.\n",
"\n",
"It is important that our models have a high, out-of-sample accuracy, because the purpose of any model, of course, is to make correct predictions on unknown data. So how can we improve out-of-sample accuracy? One way is to use an evaluation approach called Train/Test Split.\n",
"Train/Test Split involves splitting the dataset into training and testing sets respectively, which are mutually exclusive. After which, you train with the training set and test with the testing set. \n",
"\n",
"This will provide a more accurate evaluation on out-of-sample accuracy because the testing dataset is not part of the dataset that have been used to train the data. It is more realistic for real world problems.\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train set: (800, 11) (800,)\n",
"Test set: (200, 11) (200,)\n"
]
}
],
"source": [
"from sklearn.model_selection import train_test_split\n",
"X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=4)\n",
"print ('Train set:', X_train.shape, y_train.shape)\n",
"print ('Test set:', X_test.shape, y_test.shape)"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"# Classification "
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"## K nearest neighbor (K-NN)"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"#### Import library "
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"Classifier implementing the k-nearest neighbors vote."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [],
"source": [
"from sklearn.neighbors import KNeighborsClassifier"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Training\n",
"\n",
"Lets start the algorithm with k=4 for now:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
" metric_params=None, n_jobs=None, n_neighbors=4, p=2,\n",
" weights='uniform')"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"k = 4\n",
"#Train Model and Predict \n",
"neigh = KNeighborsClassifier(k).fit(X_train,y_train)\n",
"neigh"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Predicting\n",
"we can use the model to predict the test set:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 1, 3, 2, 4])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"yhat = neigh.predict(X_test)\n",
"yhat[0:5]"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"### Accuracy evaluation\n",
"In multilabel classification, __accuracy classification score__ function computes subset accuracy. This function is equal to the jaccard_similarity_score function. Essentially, it calculates how match the actual labels and predicted labels are in the test set."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train set Accuracy: 0.5475\n",
"Test set Accuracy: 0.32\n"
]
}
],
"source": [
"from sklearn import metrics\n",
"print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh.predict(X_train)))\n",
"print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, yhat))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice\n",
"Can you build the model again, but this time with k=6?"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Train set Accuracy: 0.51625\n",
"Test set Accuracy: 0.31\n"
]
}
],
"source": [
"# write your code here\n",
"k = 6\n",
"neigh = KNeighborsClassifier(k).fit(X_train,y_train)\n",
"neigh\n",
"y6 = neigh.predict(X_test)\n",
"print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh.predict(X_train)))\n",
"print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, y6))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Double-click __here__ for the solution.\n",
"\n",
"<!-- Your answer is below:\n",
" \n",
" \n",
"k = 6\n",
"neigh6 = KNeighborsClassifier(n_neighbors = k).fit(X_train,y_train)\n",
"yhat6 = neigh6.predict(X_test)\n",
"print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh6.predict(X_train)))\n",
"print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, yhat6))\n",
"\n",
"-->"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"#### What about other K?\n",
"K in KNN, is the number of nearest neighbors to examine. It is supposed to be specified by User. So, how we choose right K?\n",
"The general solution is to reserve a part of your data for testing the accuracy of the model. Then chose k =1, use the training part for modeling, and calculate the accuracy of prediction using all samples in your test set. Repeat this process, increasing the k, and see which k is the best for your model.\n",
"\n",
"We can calucalte the accuracy of KNN for different Ks."
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"text/plain": [
"array([0.3 , 0.29 , 0.315, 0.32 , 0.315, 0.31 , 0.335, 0.325, 0.34 ])"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Ks = 10\n",
"mean_acc = np.zeros((Ks-1))\n",
"std_acc = np.zeros((Ks-1))\n",
"ConfustionMx = [];\n",
"for n in range(1,Ks):\n",
" \n",
" #Train Model and Predict \n",
" neigh = KNeighborsClassifier(n).fit(X_train,y_train)\n",
" yhat=neigh.predict(X_test)\n",
" mean_acc[n-1] = metrics.accuracy_score(y_test, yhat) #Test Set Accuracy Check\n",
"\n",
" \n",
" std_acc[n-1]=np.std(yhat==y_test)/np.sqrt(yhat.shape[0])\n",
"\n",
"mean_acc"
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"#### Plot model accuracy for Different number of Neighbors "
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXhU5fXA8e+ZLSGBsImyKii44AKEAK5Yd1RkqVpA6r62itrd/rS21VarrXVXREDrBgoKLlWgLri0FUkCLiAqixaQTfYAyWRmzu+PexOHEGCSzGTuTM7neXjI3Llz75kQ5uTdziuqijHGGOM1vnQHYIwxxtTGEpQxxhhPsgRljDHGkyxBGWOM8SRLUMYYYzwpkO4AkmmfffbRrl27pjsMY4wxdVBSUvKdqrareTyrElTXrl0pLi5OdxjGGGPqQES+qe24dfEZY4zxJEtQxhhjPMkSlDHGGE/KqjEoY4xJpsrKSlasWEF5eXm6Q8kKubm5dO7cmWAwmND5lqCMMWY3VqxYQYsWLejatSsiku5wMpqqsn79elasWEG3bt0Seo118RljzG6Ul5fTtm1bS05JICK0bdu2Tq1RS1DGGLMHlpySp67fS0tQxhhjPMkSlDHGeNy0adMQERYtWpTuUBqVJShjjPG4SZMmcfzxxzN58uSU3icajSZ8rqoSjcVSGI0lKGOM8bSysjL+/e9/M2HChF0S1N13382RRx5Jr169uOmmmwBYvHgxp556Kr169aKwsJAlS5Ywe/ZsBg8eXP266667jieffBJwSsTddtttHH/88UyZMoXHH3+cfv360atXL84991y2b98OwJo1axg+fDi9evWiV69evP/Bv/nd727l/vvvr77uzTffzAMPPJC0927TzI0xJgE3zriR+avnJ/Wavdv35r5B9+3xnOnTpzNo0CAOPvhg2rRpQ2lpKYWFhbzxxhtMnz6dOXPmkJeXx4YNGwAYPXo0N910E8OHD6e8vJxYLMby5cv3eI/c3Fw++OADANavX8+VV14JwC233MKECRMYM2YM119/PQMHDmTqiy9SGYlSVlZGh44dGXH+edxwww3EYjEmT57MRx99lITvjMMSlDHGeNikSZO48cYbARg5ciSTJk2isLCQN998k0svvZS8vDwA2rRpw9atW1m5ciXDhw8HnMSTiBEjRlR//dlnn3HLLbewadMmysrKOOOMMwB4++23mfDEk8QU/H4/LVu2pGXLlrRt25Z58+axZs0a+vTpQ9u2bZP23i1BGWNMAvbW0kmF9evX8/bbb/PZZ58hIkSjUUSEu+++G1XdZdq2qtZ6nUAgQCxuvKjmWqT8/Pzqry+55BKmT59Or169ePLJJ5k9e/Yex5quuOIKnnzySVavXs1ll11Wn7e5WzYGZYwxHjV16lQuuugivvnmG77++muWL19Ot27d+OCDDzj99NOZOHFi9RjRhg0bKCgooHPnzkyfPh2AiooKtm/fzgEHHMDChQupqKhg8+bNvPXWW7u959atW+nQoQOVlZU88+yzxF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ntAJaqOp/3EPP1bj0W6q6WVXLcerlHeAejwHPu18/AxzvJv9Wqvque/wfNeJ/Pu7rfwNPisiVQG1dnR1wWobxFgOC872taS1OJW/ThFkT2mSy+3DqlT0RdyyC+4uXW2gzfhwn/rf3WNzjGDv/X6hZ/0txPkjHqOrM+CdE5Ac420vURvb6DvbsDpzK4FVdZj5gk7uVye7s7Z7x34Mou/8MSKQGWvX7VtVrRGQATqtzvoj0VtX1cefuAGpuW74GGA28JSLrVTV+wkiu+xrThFkLymQsVd0AvIDT/Vbla6Cv+/VQnB196+p8EfG541IHAl8AM4GfiLPdCSJysOx9U745wIkiso/bVTcKp/ssIaq6CKeVM9h9vAVYJiLnuzGIiPSq8ZqNwFYROdo9NDLB2/mAqrG7C4APVHUzsFFETnCPX7i7+EXkIFWdo6q3At+x6+Z1X7JzK7Uq3i9xKmE/IyLxifdgYEGCsZssZS0ok+nuAa6Le/w48LKIfIQz0WB3rZs9+QLng3g/nLGcchEZj/MBW+q2zNYBw/Z0EVVdJSK/Bd7Badm8rqov1zGWP+NUs64yGnhURG7BSb6TcTaLi3c58LiIbMPZj2tzAvfZBhwuIiXu+SPc4xfjjMPlsecq5X91p4YLzvd9p5hUdZuILBGR7qq6uMZzc0XkUuAVETkJKAN2qOqqBOI2WcyqmRuTZUSkedWkAxG5CeigqjekOSxEZDjQV1Vv2ct5PwO2eHTLG9OIrAVlTPY52225BYBvgEvSG45DVaeJs3/Q3mwCnk51PMb7rAVljDHGk2yShDHGGE+yBGWMMcaTLEEZY4zxJEtQxhhjPMkSlDHGGE/6fxxTi/9H7iPRAAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(range(1,Ks),mean_acc,'g')\n",
"plt.fill_between(range(1,Ks),mean_acc - 1 * std_acc,mean_acc + 1 * std_acc, alpha = 0.10)\n",
"plt.legend(('Accuracy ', '+/- 3xstd'))\n",
"plt.ylabel('Accuracy ')\n",
"plt.xlabel('Number of Neighbors (K)')\n",
"plt.tight_layout()\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The best accuracy was with 0.34 with k = 9\n"
]
}
],
"source": [
"print( \"The best accuracy was with\", mean_acc.max(), \"with k =\", mean_acc.argmax()+1) "
]
},
{
"cell_type": "markdown",
"metadata": {
"button": false,
"deletable": true,
"new_sheet": false,
"run_control": {
"read_only": false
}
},
"source": [
"## Want to learn more?\n",
"\n",
"IBM SPSS Modeler is a comprehensive analytics platform that has many machine learning algorithms. It has been designed to bring predictive intelligence to decisions made by individuals, by groups, by systems – by your enterprise as a whole. A free trial is available through this course, available here: [SPSS Modeler](http://cocl.us/ML0101EN-SPSSModeler).\n",
"\n",
"Also, you can use Watson Studio to run these notebooks faster with bigger datasets. Watson Studio is IBM's leading cloud solution for data scientists, built by data scientists. With Jupyter notebooks, RStudio, Apache Spark and popular libraries pre-packaged in the cloud, Watson Studio enables data scientists to collaborate on their projects without having to install anything. Join the fast-growing community of Watson Studio users today with a free account at [Watson Studio](https://cocl.us/ML0101EN_DSX)\n",
"\n",
"### Thanks for completing this lesson!\n",
"\n",
"Notebook created by: <a href = \"https://ca.linkedin.com/in/saeedaghabozorgi\">Saeed Aghabozorgi</a>\n",
"\n",
"<hr>\n",
"Copyright &copy; 2018 [Cognitive Class](https://cocl.us/DX0108EN_CC). This notebook and its source code are released under the terms of the [MIT License](https://bigdatauniversity.com/mit-license/).​"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment