CNTK/Tutorials/CNTK_101_LogisticRegression...

835 строки
91 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.display import Image"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# CNTK 101: Logistic Regression and ML Primer\n",
"\n",
"This tutorial is targeted to individuals who are new to CNTK and to machine learning. In this tutorial, you will train a simple yet powerful machine learning model that is widely used in industry for a variety of applications. The model trained below scales to massive data sets in the most expeditious manner by harnessing computational scalability leveraging the computational resources you may have (one or more CPU cores, one or more GPUs, a cluster of CPUs or a cluster of GPUs), transparently via the CNTK library.\n",
"\n",
"The following notebook uses Python APIs. If you are looking for this example in BrainScript, please look [here](https://github.com/Microsoft/CNTK/tree/release/2.5/Tutorials/HelloWorld-LogisticRegression). \n",
"\n",
"## Introduction\n",
"\n",
"**Problem**:\n",
"A cancer hospital has provided data and wants us to determine if a patient has a fatal [malignant](https://en.wikipedia.org/wiki/Malignancy) cancer vs. a benign growth. This is known as a classification problem. To help classify each patient, we are given their age and the size of the tumor. Intuitively, one can imagine that younger patients and/or patients with small tumors are less likely to have a malignant cancer. The data set simulates this application: each observation is a patient represented as a dot (in the plot below), where red indicates malignant and blue indicates benign. Note: This is a toy example for learning; in real life many features from different tests/examination sources and the expertise of doctors would play into the diagnosis/treatment decision for a patient. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://www.cntk.ai/jup/cancer_data_plot.jpg\" width=\"400\" height=\"400\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 1\n",
"Image(url=\"https://www.cntk.ai/jup/cancer_data_plot.jpg\", width=400, height=400)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Goal**:\n",
"Our goal is to learn a classifier that can automatically label any patient into either the benign or malignant categories given two features (age and tumor size). In this tutorial, we will create a linear classifier, a fundamental building-block in deep networks."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://www.cntk.ai/jup/cancer_classify_plot.jpg\" width=\"400\" height=\"400\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 2\n",
"Image(url= \"https://www.cntk.ai/jup/cancer_classify_plot.jpg\", width=400, height=400)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the figure above, the green line represents the model learned from the data and separates the blue dots from the red dots. In this tutorial, we will walk you through the steps to learn the green line. Note: this classifier does make mistakes, where a couple of blue dots are on the wrong side of the green line. However, there are ways to fix this and we will look into some of the techniques in later tutorials. \n",
"\n",
"**Approach**: \n",
"Any learning algorithm typically has five stages. These are Data reading, Data preprocessing, Creating a model, Learning the model parameters, and Evaluating the model (a.k.a. testing/prediction). \n",
"\n",
">1. Data reading: We generate simulated data sets with each sample having two features (plotted below) indicative of the age and tumor size.\n",
">2. Data preprocessing: Often, the individual features such as size or age need to be scaled. Typically, one would scale the data between 0 and 1. To keep things simple, we are not doing any scaling in this tutorial (for details look here: [feature scaling](https://en.wikipedia.org/wiki/Feature_scaling).\n",
">3. Model creation: We introduce a basic linear model in this tutorial. \n",
">4. Learning the model: This is also known as training. While fitting a linear model can be done in a variety of ways ([linear regression](https://en.wikipedia.org/wiki/Linear_regression), in CNTK we use Stochastic Gradient Descent a.k.a. [SGD](https://en.wikipedia.org/wiki/Stochastic_gradient_descent).\n",
">5. Evaluation: This is also known as testing, where one evaluates the model on data sets with known labels (a.k.a. ground-truth) that were never used for training. This allows us to assess how a model would perform in real-world (previously unseen) observations.\n",
"\n",
"## Logistic Regression\n",
"[Logistic regression](https://en.wikipedia.org/wiki/Logistic_regression) is a fundamental machine learning technique that uses a linear weighted combination of features and generates the probability of predicting different classes. In our case, the classifier will generate a probability in [0,1] which can then be compared to a threshold (such as 0.5) to produce a binary label (0 or 1). However, the method shown can easily be extended to multiple classes. \n",
"\n",
"[softmax]: https://en.wikipedia.org/wiki/Multinomial_logistic_regression"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://www.cntk.ai/jup/logistic_neuron.jpg\" width=\"300\" height=\"200\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 3\n",
"Image(url= \"https://www.cntk.ai/jup/logistic_neuron.jpg\", width=300, height=200)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the above figure, contributions from different input features are linearly weighted and aggregated. The resulting sum is mapped to a (0, 1) range via a [sigmoid]( https://en.wikipedia.org/wiki/Sigmoid_function) function. For classifiers with more than two output labels, one can use a [softmax](https://en.wikipedia.org/wiki/Softmax_function) function."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Import the relevant components\n",
"from __future__ import print_function\n",
"import numpy as np\n",
"import sys\n",
"import os\n",
"\n",
"import cntk as C\n",
"import cntk.tests.test_utils\n",
"cntk.tests.test_utils.set_device_from_pytest_env() # (only needed for our build system)\n",
"C.cntk_py.set_fixed_random_seed(1) # fix the random seed so that LR examples are repeatable"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Generation\n",
"Let us generate some synthetic data emulating the cancer example using the `numpy` library. We have two input features (represented in two-dimensions) and two output classes (benign/blue or malignant/red). \n",
"\n",
"In our example, each observation (a single 2-tuple of features - age and size) in the training data has a label (blue or red). Because we have two output labels, we call this a binary classification task. "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define the network\n",
"input_dim = 2\n",
"num_output_classes = 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Input and Labels\n",
"\n",
"In this tutorial we are generating synthetic data using the `numpy` library. In real-world problems, one would use a [reader](https://docs.microsoft.com/en-us/cognitive-toolkit/brainscript-and-python---understanding-and-extending-readers), that would read feature values (`features`: *age* and *tumor size*) corresponding to each observation (patient). The simulated *age* variable is scaled down to have a similar range to that of the other variable. This is a key aspect of data pre-processing that we will learn more about in later tutorials. Note: in general, observations and labels can reside in higher dimensional spaces (when more features or classifications are available) and are then represented as [tensors](https://en.wikipedia.org/wiki/Tensor) in CNTK. More advanced tutorials introduce the handling of high dimensional data. "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Ensure that we always get the same results\n",
"np.random.seed(0)\n",
"\n",
"# Helper function to generate a random data sample\n",
"def generate_random_data_sample(sample_size, feature_dim, num_classes):\n",
" # Create synthetic data using NumPy. \n",
" Y = np.random.randint(size=(sample_size, 1), low=0, high=num_classes)\n",
"\n",
" # Make sure that the data is separable \n",
" X = (np.random.randn(sample_size, feature_dim)+3) * (Y+1)\n",
" \n",
" # Specify the data type to match the input variable used later in the tutorial \n",
" # (default type is double)\n",
" X = X.astype(np.float32) \n",
" \n",
" # convert class 0 into the vector \"1 0 0\", \n",
" # class 1 into the vector \"0 1 0\", ...\n",
" class_ind = [Y==class_number for class_number in range(num_classes)]\n",
" Y = np.asarray(np.hstack(class_ind), dtype=np.float32)\n",
" return X, Y"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create the input variables denoting the features and the label data. Note: the input \n",
"# does not need additional info on the number of observations (Samples) since CNTK creates only \n",
"# the network topology first \n",
"mysamplesize = 32\n",
"features, labels = generate_random_data_sample(mysamplesize, input_dim, num_output_classes)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us visualize the input data.\n",
"\n",
"**Note**: If the import of `matplotlib.pyplot` fails, please run `conda install matplotlib`, which will fix the `pyplot` version dependencies. If you are on a python environment different from Anaconda, then use `pip install matplotlib`."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEKCAYAAAARnO4WAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl4VPXZ//H3nQSBBEGRQN0QtValrhBXxAWwagW3Yq2t\n1FYrT23rUrWWap/Lq1qf1qfWn0sXy4P71rpvWBGraKtIDYsIilvRCi5EQYWAkMD9++M7aRYmyQnM\nmTMz5/O6rrmSOTnLPYHcc+a73F9zd0REpPSVJR2AiIjkhxK+iEhKKOGLiKSEEr6ISEoo4YuIpIQS\nvohISijhi4ikhBK+iEhKKOGLiKRERdIBtNSvXz8fNGhQ0mGIiBSNmTNnfuTu1VH2LaiEP2jQIGpr\na5MOQ0SkaJjZO1H3VZOOiEhKKOGLiKSEEr6ISErEmvDN7Bwzm2dm883s3DivJSIiHYst4ZvZbsAZ\nwL7AnsBoM/tiXNcTEZGOxXmHvysww91Xunsj8AxwQozXE5E0e/ppOPBA6NsX9tsPpk5NOqKCE2fC\nnwcMN7MtzKwS+CqwbYzXE5G0mjIFjj4apk+HZcvgn/+EY4+FRx5JOrKCElvCd/dXgSuAJ4DHgTnA\n2rb7mdl4M6s1s9q6urq4whGRUnb++bBqVettq1bBeeclE0+BirXT1t1vcPeh7n4wsAx4Pcs+E929\nxt1rqqsjTRYTEWltwYLs2998E9aty28sBSzuUTr9M18HEtrv74zzeiKSUl/4Qvbt1dVQptHnTeL+\nTdxnZq8AjwA/dPdPYr6eiKTRz38OlZWtt1VWwkUXJRNPgYq1lo67D4/z/CIiAPzXf8GKFfDLX8Lq\n1dCtG0yYAOeck3RkBcXcPekY/qOmpsZVPE1ENlhjIyxdGoZmVhRUbcjYmNlMd6+Jsm86fiMikg4V\nFdC/f9JRFCz1ZoiIpIQSvohISijhi4ikhBK+iEhKKOGLiKSEEr6ISEoo4YuIpIQSvohIS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ZOISyQk16UgxGQvc5u7bufsgd98W\nWEho9ngO+FqmLX8AocAVwGtAddNasmbWzcy+nOXcrwJfzOxTBmzr7k8DPwX6AL2AqcAPmw7I1H/v\nTahz/2nmukdlOfcLwDAzazp/lZl9CVgADDKzHTP7te2E/hIwD5EcUcKXYnIy8ECbbfdltt9HqD//\nCnA7oWLjp5nlMscCV5jZS8Acstdo/yvhjh7CJ4fbzexlQsXHazNLE/4S2DyzQPdLwGHu/lJmnwWE\nET7PtT2xu9cB3wHuMrO5ZJpz3P1zQhPO5Eynbds66ocRRuuI5ISqZUrJMLNe7r7CzLYA/gkMy9Sk\nj3r8A8CFTW3qScp8WrjT3UcmHYuUDiV8KRlmNg3YjNAp+r/ufnMXj9+ZsD7ps7mPrmvMbB+gwd3n\ndLqzSERK+CIiKaE2fBGRlFDCFxFJCSV8EZGUUMIXEUkJJXwRkZRQwhcRSYn/D09lwZpzAc7BAAAA\nAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x23c9c93b710>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Plot the data \n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"# let 0 represent malignant/red and 1 represent benign/blue \n",
"colors = ['r' if label == 0 else 'b' for label in labels[:,0]]\n",
"\n",
"plt.scatter(features[:,0], features[:,1], c=colors)\n",
"plt.xlabel(\"Age (scaled)\")\n",
"plt.ylabel(\"Tumor size (in cm)\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Model Creation\n",
"\n",
"A logistic regression (a.k.a. LR) network is a simple building block, but has powered many ML \n",
"applications in the past decade. LR is a simple linear model that takes as input a vector of numbers describing the properties of what we are classifying (also known as a feature vector, $\\bf{x}$, the blue nodes in the figure below) and emits the *evidence* ($z$) (output of the green node, also known as \"activation\"). Each feature in the input layer is connected to an output node by a corresponding weight $w$ (indicated by the black lines of varying thickness). "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"https://www.cntk.ai/jup/logistic_neuron2.jpg\" width=\"300\" height=\"200\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Figure 4\n",
"Image(url= \"https://www.cntk.ai/jup/logistic_neuron2.jpg\", width=300, height=200)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first step is to compute the evidence for an observation. \n",
"\n",
"$$z = \\sum_{i=1}^n w_i \\times x_i + b = \\textbf{w} \\cdot \\textbf{x} + b$$ \n",
"\n",
"where $\\bf{w}$ is the weight vector of length $n$ and $b$ is known as the [bias](https://www.quora.com/What-does-the-bias-term-represent-in-logistic-regression) term. Note: we use **bold** notation to denote vectors. \n",
"\n",
"The computed evidence is mapped to a (0, 1) range using a `sigmoid` (when the outcome can be in one of two possible classes) or a `softmax` function (when the outcome can be in one of more than two possible classes).\n",
"\n",
"Network input and output: \n",
"- **input** variable (a key CNTK concept): \n",
">An **input** variable is a user-code-facing container where user-provided code fills in different observations (a data point or sample of data points, equivalent to (age, size) tuples in our example) as inputs to the model function during model learning (a.k.a.training) and model evaluation (a.k.a. testing). Thus, the shape of the `input` must match the shape of the data that will be provided. For example, if each data point was a grayscale image of height 10 pixels and width 5 pixels, the input feature would be a vector of 50 floating-point values representing the intensity of each of the 50 pixels, and could be written as `C.input_variable(10*5, np.float32)`. Similarly, in our example the dimensions are age and tumor size, thus `input_dim` = 2. More on data and their dimensions to appear in separate tutorials. "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"feature = C.input_variable(input_dim, np.float32)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Network setup\n",
"\n",
"The `linear_layer` function is a straightforward implementation of the equation above. We perform two operations:\n",
"0. multiply the weights ($\\bf{w}$) with the features ($\\bf{x}$) using the CNTK `times` operator,\n",
"1. add the bias term ($b$).\n",
"\n",
"These CNTK operations are optimized for execution on the available hardware and the implementation hides the complexity away from the user. "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define a dictionary to store the model parameters\n",
"mydict = {}\n",
"\n",
"def linear_layer(input_var, output_dim):\n",
" \n",
" input_dim = input_var.shape[0]\n",
" weight_param = C.parameter(shape=(input_dim, output_dim))\n",
" bias_param = C.parameter(shape=(output_dim))\n",
" \n",
" mydict['w'], mydict['b'] = weight_param, bias_param\n",
"\n",
" return C.times(input_var, weight_param) + bias_param"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"`z` will be used to represent the output of the network."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"output_dim = num_output_classes\n",
"z = linear_layer(feature, output_dim)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Learning model parameters\n",
"\n",
"Now that the network is set up, we would like to learn the parameters $\\bf w$ and $b$ for our simple linear layer. To do so we convert, the computed evidence ($z$) into a set of predicted probabilities ($\\textbf p$) using a `softmax` function.\n",
"\n",
"$$ \\textbf{p} = \\mathrm{softmax}(z)$$ \n",
"\n",
"The `softmax` is an activation function that normalizes the accumulated evidence into a probability distribution over the classes (Details of [softmax](https://www.cntk.ai/pythondocs/cntk.ops.html#cntk.ops.softmax)). Other choices of activation function can be [here](https://cntk.ai/pythondocs/cntk.layers.layers.html#cntk.layers.layers.Activation)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Training\n",
"The output of the `softmax` is the probabilities of an observation belonging each of the respective classes. For training the classifier, we need to determine what behavior the model needs to mimic. In other words, we want the generated probabilities to be as close as possible to the observed labels. We can accomplish this by minimizing the difference between our output and the ground-truth labels. This difference is calculated by the *cost* or *loss* function.\n",
"\n",
"[Cross entropy](http://cntk.ai/pythondocs/cntk.ops.html#cntk.ops.cross_entropy_with_softmax) is a popular loss function. It is defined as:\n",
"\n",
"$$ H(p) = - \\sum_{j=1}^{| \\textbf y |} y_j \\log (p_j) $$ \n",
"\n",
"where $p$ is our predicted probability from `softmax` function and $y$ is the ground-truth label, provided with the training data. In the two-class example, the `label` variable has two dimensions (equal to the `num_output_classes` or $| \\textbf y |$). Generally speaking, the label variable will have $| \\textbf y |$ elements with 0 everywhere except at the index of the true class of the data point, where it will be 1. Understanding the [details](http://colah.github.io/posts/2015-09-Visual-Information/) of the cross-entropy function is highly recommended."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"label = C.input_variable(num_output_classes, np.float32)\n",
"loss = C.cross_entropy_with_softmax(z, label)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Evaluation\n",
"\n",
"In order to evaluate the classification, we can compute the [classification_error](https://www.cntk.ai/pythondocs/cntk.metrics.html#cntk.metrics.classification_error), which is 0 if our model was correct (it assigned the true label the most probability), otherwise 1."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"eval_error = C.classification_error(z, label)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Configure training\n",
"\n",
"The trainer strives to minimize the `loss` function using an optimization technique. In this tutorial, we will use [Stochastic Gradient Descent](https://en.wikipedia.org/wiki/Stochastic_gradient_descent) (`sgd`), one of the most popular techniques. Typically, one starts with random initialization of the model parameters (the weights and biases, in our case). For each observation, the `sgd` optimizer can calculate the `loss` or error between the predicted label and the corresponding ground-truth label, and apply [gradient descent](http://www.statisticsviews.com/details/feature/5722691/Getting-to-the-Bottom-of-Regression-with-Gradient-Descent.html) to generate a new set of model parameters after each observation. \n",
"\n",
"The aforementioned process of updating all parameters after each observation is attractive because it does not require the entire data set (all observations) to be loaded in memory and also computes the gradient over fewer datapoints, thus allowing for training on large data sets. However, the updates generated using a single observation at a time can vary wildly between iterations. An intermediate ground is to load a small set of observations into the model and use an average of the `loss` or error from that set to update the model parameters. This subset is called a *minibatch*.\n",
"\n",
"With minibatches we often sample observations from the larger training dataset. We repeat the process of updating the model parameters using different combinations of training samples, and over a period of time minimize the `loss` (and the error). When the incremental error rates are no longer changing significantly, or after a preset maximum number of minibatches have been processed, we claim that our model is trained.\n",
"\n",
"One of the key parameters of [optimization](https://en.wikipedia.org/wiki/Category:Convex_optimization) is the `learning_rate`. For now, we can think of it as a scaling factor that modulates how much we change the parameters in any iteration. We will cover more details in later tutorials. \n",
"With this information, we are ready to create our trainer. "
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Instantiate the trainer object to drive the model training\n",
"learning_rate = 0.5\n",
"lr_schedule = C.learning_rate_schedule(learning_rate, C.UnitType.minibatch) \n",
"learner = C.sgd(z.parameters, lr_schedule)\n",
"trainer = C.Trainer(z, (loss, eval_error), [learner])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, let us create some helper functions that will be needed to visualize different functions associated with training. Note: these convenience functions are for understanding what goes on under the hood."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define a utility function to compute the moving average.\n",
"# A more efficient implementation is possible with np.cumsum() function\n",
"def moving_average(a, w=10):\n",
" if len(a) < w: \n",
" return a[:] \n",
" return [val if idx < w else sum(a[(idx-w):idx])/w for idx, val in enumerate(a)]\n",
"\n",
"\n",
"# Define a utility that prints the training progress\n",
"def print_training_progress(trainer, mb, frequency, verbose=1):\n",
" training_loss, eval_error = \"NA\", \"NA\"\n",
"\n",
" if mb % frequency == 0:\n",
" training_loss = trainer.previous_minibatch_loss_average\n",
" eval_error = trainer.previous_minibatch_evaluation_average\n",
" if verbose: \n",
" print (\"Minibatch: {0}, Loss: {1:.4f}, Error: {2:.2f}\".format(mb, training_loss, eval_error))\n",
" \n",
" return mb, training_loss, eval_error"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run the trainer\n",
"\n",
"We are now ready to train our Logistic Regression model. We want to decide what data we need to feed into the training engine.\n",
"\n",
"In this example, each iteration of the optimizer will work on 25 samples (25 dots w.r.t. the plot above) a.k.a. `minibatch_size`. We would like to train on 20000 observations. If the number of samples in the data is only 10000, the trainer will make 2 passes through the data. This is represented by `num_minibatches_to_train`. Note: in a real world scenario, we would be given a certain amount of labeled data (in the context of this example, (age, size) observations and their labels (benign / malignant)). We would use a large number of observations for training, say 70%, and set aside the remainder for the evaluation of the trained model.\n",
"\n",
"With these parameters we can proceed with training our simple feedforward network."
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Initialize the parameters for the trainer\n",
"minibatch_size = 25\n",
"num_samples_to_train = 20000\n",
"num_minibatches_to_train = int(num_samples_to_train / minibatch_size)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Minibatch: 0, Loss: 0.6931, Error: 0.32\n",
"Minibatch: 50, Loss: 1.9350, Error: 0.36\n",
"Minibatch: 100, Loss: 1.0764, Error: 0.32\n",
"Minibatch: 150, Loss: 0.4856, Error: 0.20\n",
"Minibatch: 200, Loss: 0.1319, Error: 0.08\n",
"Minibatch: 250, Loss: 0.1330, Error: 0.08\n",
"Minibatch: 300, Loss: 0.1012, Error: 0.04\n",
"Minibatch: 350, Loss: 0.1091, Error: 0.04\n",
"Minibatch: 400, Loss: 0.3094, Error: 0.08\n",
"Minibatch: 450, Loss: 0.3230, Error: 0.12\n",
"Minibatch: 500, Loss: 0.3986, Error: 0.20\n",
"Minibatch: 550, Loss: 0.6744, Error: 0.24\n",
"Minibatch: 600, Loss: 0.3004, Error: 0.12\n",
"Minibatch: 650, Loss: 0.1676, Error: 0.12\n",
"Minibatch: 700, Loss: 0.2777, Error: 0.12\n",
"Minibatch: 750, Loss: 0.2311, Error: 0.04\n"
]
}
],
"source": [
"from collections import defaultdict\n",
"\n",
"# Run the trainer and perform model training\n",
"training_progress_output_freq = 50\n",
"plotdata = defaultdict(list)\n",
"\n",
"for i in range(0, num_minibatches_to_train):\n",
" features, labels = generate_random_data_sample(minibatch_size, input_dim, num_output_classes)\n",
" \n",
" # Assign the minibatch data to the input variables and train the model on the minibatch\n",
" trainer.train_minibatch({feature : features, label : labels})\n",
" batchsize, loss, error = print_training_progress(trainer, i, \n",
" training_progress_output_freq, verbose=1)\n",
" \n",
" if not (loss == \"NA\" or error ==\"NA\"):\n",
" plotdata[\"batchsize\"].append(batchsize)\n",
" plotdata[\"loss\"].append(loss)\n",
" plotdata[\"error\"].append(error)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAACgCAYAAAAPbNcqAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHvFJREFUeJzt3XmYFOXV9/HvT9YRkD2oAQKKmiAqKgENbiHuGtCYEEh8\nxD2Je3wUUZK8mrgnmphEY1zQuEAEjYpm0cQN9XUDUVBxQXBBRRiURRYFOc8fp9rpmQwz00z3dPX0\n+VxXX9NdVV11umfm1F33VjIzQgghNH+bFDuAEEIITSMSfgghlIlI+CGEUCYi4YcQQpmIhB9CCGUi\nEn4IIZSJSPhlQNK1kn6e67aS9pG0oLDRfXHctyTt2xTHag6S383L+d52I+J4QtLRhdh3yL+WxQ4g\nbDxJbwFbAluaWWXW8pnAQKCvmb1lZj9u6D5z2bae2PoA84FWZrYuH/ssVZL2BP6ZeQlsCqzM2qS/\nmb2Tyz7N7FFg+3xvG5q3KOGXvvnA6MwLSTvgCaVsSEp1wcXMHjez9mbWnqrE2ymzrGayl7SJpPjf\nDHkXf1Sl71bgqKzXY4BbsjeQdLOkC5Pn+0haIOl/JS2S9IGkY2rbNmvZeZIqk2qXH2YtP0TSTEnL\nJb0r6fyst01Lfi6V9Imk3ZP3nCBpjqQVkl6RtEvWewZKmiVpmaQ7JLWt7QNLOlrSk5J+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2ZvULVtLQ1/dvMlpjZauBveJIGT/IvAk/jk1xtU8t7hwFTzKwyie2jHI8938xeSJ7PSD5XfR4x\nsxVmthhYBtyXLJ9d4/2TkpimAZsl8w3tD4yTTyX9KNAW6J1s/+8a8YcA+FSlIRTTVOA3+Nw0XevY\n7tOs59rANjXnCTFJ+wD74jekWCXpUTw55qIhx87e5nMg0zaxjqqCVc3jZr9nfdbr9VT/3/yvz5XE\ncYSZvZa9QtIQvH0khP8SJfxQbBOAC8xsdh72tZ/8vqMVwGHAk/gdlj5Okv1X8VsmZqyVTxkN8DBe\nDdQV/B6weYgH/O5TuybPN7aB+fsAkvYAlpnZMvyuSqcms6AiaedGxhnKQCT8UFRmtsDMfp+n3T2L\nz/c/C7jLzKYD/wJaSpqD178/nbX9dcAsSbeb2ct4PfpjSfXPleTHb4CfSJoJdNvIfaxJ3n8tPgsr\nwK/w+/7OkvRy8jqEOsVsmSGEUCaihB9CCGUiEn4IIZSJSPghhFAmIuGHEEKZiIQfQghlIhJ+CCGU\niUj4IYRQJiLhhxBCmfg/2GcBDJbY0y4AAAAASUVORK5CYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x23c9d8e0eb8>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAACgCAYAAADjNXB5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXeYFeX1xz9fwBVBmkAUBQR7sESRYFfsGv2JLYktdo0Y\nIsaIilhjjCYx0WAjikaNihq7xq4x9gKKKCKKCgEFCxZQ0KWc3x9n7jJcdu/eLbfs7vk8zzx35p13\n3vnOvXPnzNvOkZkRBEEQBACtSi0gCIIgKB/CKARBEARVhFEIgiAIqgijEARBEFQRRiEIgiCoIoxC\nEARBUEUYhTJH0mhJZ9c1r6RBkmYWVl3VeadJ2qUY52pqSDJJ6xT72IaSPndd7sFqyvlG0lqNqy4o\nJGEUSk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Vdm5zjsYyxS7/pS+qWuMfIXN+9iU/+aZKGSjolcRD3kqRVUqf4RaLzLUkDk+Pby+N3vJIc\nMzhV7v2SnsInWQVBFWEUgnLnNtw1QFt8NvPLOfL2wGdk7w3UVIMYCByQlPXTVLPL0Wa2OTAAOElS\nVzM7A1hgZpua2aGSNgTOAnYysx8Bw+p47nWBK81sQ+CrREdtbATsD/wYuBCYb+4g7kXg8FS+dubO\n7U4Erk/SRuIuNgYCOwJ/TlxagPsROtDMdshDQ9CCCKMQlDVmNhGPP3EwXmvIxb1mtsTM3mapu+Js\nHjezOWa2ALgbf5CDG4I3gJdwp2XrVnPsTsC/zOzzRNsXdTz3h2Y2IVkfn1xXbfzHzOaZ2WfA18AD\nSfqbWcePTTQ9A3RM/EPtBpwhdzP+NNAW6J3kfzxLfxAA7p42CMqd+4FLcD9CXXPk+z61rhryZPt1\nMUmDgF3wgCfzJT2NP0DrQj7nTudZDGT6Shax9AUt+7zpY5aktpew7P93uetKdBxgZlPSOyRtgffX\nBMFyRE0haApcD5xvZm82Qlm7ymPorgTsCzyPR/n6MjEIG+DhPTMslLsSB3gKb3LqCh7PuBH0gEdA\n2zxZr2+n+M8BJG0LfG1mX+ORvX6deL5F0mYN1Bm0AMIoBGWPmc00s1GNVNwreKyIicBdZjYOeARo\nI2ky3h/wUir/NcBESbeY2SS8Xf+/SVPTX2kcLgGGSHod6FbPMr5Ljh+Ne94FuACPYz1R0qRkOwhy\nEl5SgyAIgiqiphAEQRBUEUYhCIIgqCKMQhAEQVBFGIUgCIKgijAKQRAEQRVhFIIgCIIqwigEQRAE\nVYRRCIIgCKr4f6kqPUTTus2BAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x23c9d9041d0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Compute the moving average loss to smooth out the noise in SGD\n",
"plotdata[\"avgloss\"] = moving_average(plotdata[\"loss\"])\n",
"plotdata[\"avgerror\"] = moving_average(plotdata[\"error\"])\n",
"\n",
"# Plot the training loss and the training error\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.figure(1)\n",
"plt.subplot(211)\n",
"plt.plot(plotdata[\"batchsize\"], plotdata[\"avgloss\"], 'b--')\n",
"plt.xlabel('Minibatch number')\n",
"plt.ylabel('Loss')\n",
"plt.title('Minibatch run vs. Training loss')\n",
"\n",
"plt.show()\n",
"\n",
"plt.subplot(212)\n",
"plt.plot(plotdata[\"batchsize\"], plotdata[\"avgerror\"], 'r--')\n",
"plt.xlabel('Minibatch number')\n",
"plt.ylabel('Label Prediction Error')\n",
"plt.title('Minibatch run vs. Label Prediction Error')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Run evaluation / Testing \n",
"\n",
"Now that we have trained the network, let us evaluate the trained network on data that hasn't been used for training. This is called **testing**. Let us create some new data and evaluate the average error and loss on this set. This is done using `trainer.test_minibatch`. Note the error on this previously unseen data is comparable to the training error. This is a **key** check. Should the error be larger than the training error by a large margin, it indicates that the trained model will not perform well on data that it has not seen during training. This is known as [overfitting](https://en.wikipedia.org/wiki/Overfitting). There are several ways to address overfitting that are beyond the scope of this tutorial, but the Cognitive Toolkit provides the necessary components to address overfitting.\n",
"\n",
"Note: we are testing on a single minibatch for illustrative purposes. In practice, one runs several minibatches of test data and reports the average. \n",
"\n",
"**Question** Why is this suggested? Try plotting the test error over several set of generated data sample and plot using plotting functions used for training. Do you see a pattern?"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.12"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Run the trained model on a newly generated dataset\n",
"test_minibatch_size = 25\n",
"features, labels = generate_random_data_sample(test_minibatch_size, input_dim, num_output_classes)\n",
"\n",
"trainer.test_minibatch({feature : features, label : labels})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Checking prediction / evaluation \n",
"For evaluation, we softmax the output of the network into a probability distribution over the two classes, the probability of each observation being malignant or benign. "
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"out = C.softmax(z)\n",
"result = out.eval({feature : features})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us compare the ground-truth label with the predictions. They should be in agreement.\n",
"\n",
"**Question:** \n",
"- How many predictions were mislabeled? Can you change the code below to identify which observations were misclassified? "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Label : [1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1]\n",
"Predicted: [1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1]\n"
]
}
],
"source": [
"print(\"Label :\", [np.argmax(label) for label in labels])\n",
"print(\"Predicted:\", [np.argmax(x) for x in result])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Visualization\n",
"It is desirable to visualize the results. In this example, the data can be conveniently plotted using two spatial dimensions for the input (patient age on the x-axis and tumor size on the y-axis), and a color dimension for the output (red for malignant and blue for benign). For data with higher dimensions, visualization can be challenging. There are advanced dimensionality reduction techniques, such as [t-sne](https://en.wikipedia.org/wiki/T-distributed_stochastic_neighbor_embedding) that allow for such visualizations."
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[ 8.00007153 -8.00006485]\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xd4k/UWwPHv6aADKBtkozjbssuQIbJlCCgyRESZAiLD\nvbhe98B1RUC2qIiKoiAoCAiyZJVVyhJE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DDG\nnAJuAw4YY1YDGGNOG2MSgUBgnCOfaVgHLaX3O+ju+H2uBIo4crgLmGqMSTLG7Ad+v+x1h/F8F5nK\nYbRJqOwUb4ypmjogIndj7VB5pzEmTkQWAZkdZSjA28aYMZe9VwXgQqpQElYrIzOfA+2NMRtE5FGs\n/WOu+frpSBQRP2NMsjFmu4hUxxo3eENEFgA/ZvC6ocAhrFPL/IDzGeTwhDFmbpqgSKtMcgoG4jN5\njvJy2iJQOU0B4ISjCNyOdQRnigTHttuXmwv0dJzLgIiUFpHi6TwvtTNA/gy+lx844LjWQ6niK7C6\ndCDt8YpZvf424CbHc0oBccaYr4DhWFtObwNKikhNx3PyO/rvC2C1FJKxNhn0T+e95wL9U34/InKr\nWAfbLAY6O8YQSgKNLnvdrVjdb8qHaYtA5TRzgH4isgXrD+OKVN8bC2wUkbXGGOcfaGPMbyJyB/Cn\niACcBbphtQAy8jnwmYjEY7U+Un8qHobVvXLE8TWlYAwBvhKRlxx5nsrk+pfvPT8bq3WxA6gEDBeR\nZCABa3zkomPQeIRjADseq3U0CvhBRLo7rnsunZ9nPFa311qxkjiCdSzij0BjrC2t9wB/prxAREpg\ntcoOXuX3pHyA7j6qVBY5Zg/FG2OMiHTBGjjO8jnYjk/kXxhjmrktyWsgIkOB08aYCZk+WXk1bREo\nlXU1gE8dn7hPAj2v5cXGmAOOqaxhJmesJTgJfGl3Esp+2iJQSikfp4PFSinl47QQKKWUj9NCoJRS\nPk4LgVJK+TgtBEop5eO0ECillI/7P2Yk1HTbQIeMAAAAAElFTkSuQmCC\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x23c9d928ba8>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Model parameters\n",
"print(mydict['b'].value)\n",
"\n",
"bias_vector = mydict['b'].value\n",
"weight_matrix = mydict['w'].value\n",
"\n",
"# Plot the data \n",
"import matplotlib.pyplot as plt\n",
"\n",
"# let 0 represent malignant/red, and 1 represent benign/blue\n",
"colors = ['r' if label == 0 else 'b' for label in labels[:,0]]\n",
"plt.scatter(features[:,0], features[:,1], c=colors)\n",
"plt.plot([0, bias_vector[0]/weight_matrix[0][1]], \n",
" [ bias_vector[1]/weight_matrix[0][0], 0], c = 'g', lw = 3)\n",
"plt.xlabel(\"Patient age (scaled)\")\n",
"plt.ylabel(\"Tumor size (in cm)\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"**Exploration Suggestions** \n",
"- Try exploring how the classifier behaves with different data distributions - e.g., changing the `minibatch_size` parameter from 25 to 64. Why is the error increasing?\n",
"- Try exploring different activation functions\n",
"- Try exploring different learners \n",
"- You can explore training a [multiclass logistic regression](https://en.wikipedia.org/wiki/Multinomial_logistic_regression) classifier. "
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"### Appendix\n",
"\n",
"Many of the terminologies in machine learning literature can be difficult to map to. Each toolkit / book / paper have their way of referring to the synonymous terminologies. Here are a few CNTK terminologies and their equivalent terms in literature:\n",
"\n",
"- a sequence (in CNTK) is also referred to as an instance\n",
"- a sample (in CNTK) is also referred to as a feature\n",
"- input stream(s) (in CNTK) is also referred to as feature column or a feature\n",
"- the criterion (in CNTK) is also referred to as the loss\n",
"- the evalutaion error (in CNTK) is also referred to as a metric"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3.0
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}