{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#Final Lab: Classification and Clustering Grab Bag\n", "\n", "In this final lab, we will introduce two methods of classification called Neural Networks and Support Vector Machines, and an additional method of clustering called Hierarchical Agglomerative Clustering. We hope that introducing these methods will broaden your toolkit for tackling problems both for the final project and in the future. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "%matplotlib inline\n", "import numpy\n", "import math\n", "import scipy\n", "import random\n", "import brewer2mpl\n", "import matplotlib.pyplot as plt" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 145 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Neural Networks\n", "\n", "A neural network \"learns\" by solving an optimization problem to choose a set of parameters that minimizes an error function, which is typically a squared error loss. This definition of learning isn't unique to a neural network model. Consider, in the simplest case, a linear model of the form $y = XB$. Given a vector of data $y \\in \\mathbb{R}^m$, we choose $B \\in \\mathbb{R}^n$ that minimizes $||y-XB||_2$, where $X$ is an $m$ by $n$ matrix with \"training data\" on the rows. Solving this least squares minimization problem has a nice well known closed form analytical result: $\\hat{B} = (X^TX)^{-1}X^Ty$. There is, however, a tradeoff between computational ease of finding optimal model parameters and model complexity. This is evident in the linear case since the model is extremely easy to fit but has a very simple form. The neural network attempts to find a \"sweet spot\": while the model is highly non-linear, its particular functional form allows for a computationally slick fitting procedure called \"backpropogation\". \n", "\n", "A \"neural network\" is a function from $f: \\mathbb{R}^m \\rightarrow \\{-1,1\\}$. The input to each neuron is a linear combination of the outputs of each of the neurons in the lower layer. The output of the neuron is a nonlinear threshold applied to its input: it's something that maps the real line to (-1,1) in a 1-1 fashion such that \"most\" of the positive line is mapped pretty close to 1 and and \"most\" of the negative line is mapped pretty close to -1. A common choice is the function $g(x) = \\frac{e^x-e^{-x}}{e^x+e^{-x}}$.The final output of the signal is the sign of the top neuron. Note that the top layer is constrained to have a single neuron.\n", "\n", "The goal of fitting the model is to find a suitable set of \"weights\", which we can compactly refer to as $w$, for the inputs of each of the neurons. One way to do this is to choose a set of weights that minimize the sum of squared errors for training examples we already have. The intuition here is to choose a model that is \"close\" to the true model, just like we would in a linear regression. However, unlike linear regression an analytical solution is not feasible because of the ugly threshold functions, so we need to resort to a computational approach like gradient descent. Gradient descent takes steps in the direction of greatest error decrease in the parameter space, hoping to find a (global) minimum. (Recall that from multivariable calculus, the gradient of a scalar field points in the direction of the greatest increase of the function, and so walking in the opposite direction points in the direction of greatest decrease repeating the argument with the negative of the function.) \n", "\n", "We start by initializing the model with some arbitrary set of weights. Feeding forward, given an input $x \\in \\mathbb{R}^m$, we may compute the output as delineated above. Hence, we may calculate the error $E = (y-f(x))^2$. Now, we compute the gradient of this error function with respect to the weights. \n", "\n", "The beauty of the method is that computing the gradient of the error is computationally slick and can be done recursively using the chain rule. To see this, we'll introduce some notation. Let $k = 1...L$ indicate layers, assume that $s_{jk}$ is the output of the jth neuron in layer $k$, $x_{jk}$ is the input into neuron $j$ in layer $k$, and $w_{ijk}$ is the weight for the signal input into the $j$th neuron in layer $k$ coming from the ith neuron in layer $k-1$, so that $x_{jk} = \\sum_{i=1}^{d_{k-1}}w_{ijk}s_{ik-1}$, $s_{jk} = g(x_{jk})$. Note that $d_{k-1}$ stands for the number of neurons in layer $k-1$. By the chain rule, $$\\frac{\\partial E}{\\partial w_{ijk}} = \\frac{\\partial E}{\\partial s_{jk}}\\frac{\\partial s_{jk}}{\\partial w_{ijk}}$$. Since $s_{jk}$ is linear in the weights, the tricky part is only in computing the former component of the product. We may recursively compute this as \n", "\n", "$$\\frac{\\partial E}{\\partial s_{jk}} = \\frac{\\partial E}{\\partial x_{jk}}\\frac{\\partial x_{jk}}{\\partial s_{jk}} = \\sum_{i=1}^{d_{k+1}} \\frac{\\partial E}{\\partial s_{ik+1}}\\frac{\\partial s_{ik+1}}{\\partial x_{jk}}\\frac{\\partial x_{jk}}{\\partial s_{jk}}$$\n", "\n", "The recursion terminates since $\\frac{\\partial E}{\\partial x_{1L}} = 2(x_{1L}-y)$. We start by computing the gradients from the top layer, and store the gradients as we progress down each layer,so that we need not recompute them. This leads to computational efficiency. \n", "\n", "Thus \"learning\" in a neural network is nothing but switching between computing the error using the training data and updating the weights by calculating the gradient of the error function. In the code block that follows, we write a class for NeuralNetworks, and apply it to performing classification." ] }, { "cell_type": "code", "collapsed": false, "input": [ "#Neural Network Class \n", "class Neural_Net:\n", "\n", "\t#constructor initializes a new neural network with randomly selected weights and pre-specified height, and number of neurons per layer\n", "\tdef __init__(self,non,height):\n", "\t\t#list to store the number of neurons in each layer of the network\n", "\t\tself.num_of_neurons = non\n", "\t\t#height of the network\n", "\t\tself.L = height\n", "\t\t#list to store number of weights in each layer of the network, indexed by layer, output neuron, input neuron\n", "\t\tself.weights = numpy.zeros(shape=(10,10,10))\n", "\t\t#delta_matrix: stores the gradient that is used in backpropagation\n", "\t\tself.deltas = numpy.zeros(shape=(10,10))\n", "\t\t#matrix that stores thresholded signals\n", "\t\tself.signals = numpy.zeros(shape=(10,10))\n", "\t\t#(tunable) learning_rate used in backpropagation\n", "\t\tself.learning_rate = .001\n", "\t\t#initialize weights to be between -2 and 2\n", "\t\tfor i in range(1,self.L+1):\n", "\t\t\tfor j in range(1,self.num_of_neurons[i]+1):\n", "\t\t\t\tfor k in range(self.num_of_neurons[i-1]+1):\n", "\t\t\t\t\tself.weights[i][j][k] = random.random()*4-2\t\t\n", "\t\t\t\t\t\t\t\t\t\t\t\n", "\t#forward_pass computes the output of the neural network given an input\n", "\tdef forward_pass(self,x):\n", "\t\t#(for convenience, we index neurons starting at 1 instead of zero)\n", "\t\tself.signals[0][0] = -1\n", "\t\tfor i in range(1,self.num_of_neurons[0]+1):\n", "\t\t\tself.signals[0][i] = x[i-1]\n", "\t\tfor i in range(1,self.L+1):\n", "\t\t\tself.signals[i][0] = -1\n", "\t\t\tfor j in range(1,self.num_of_neurons[i]+1):\n", "\t\t\t\tself.signals[i][j] = self.compute_signal(i,j)\n", "\t\treturn self.signals[self.L][1]\n", "\t\t\t\t\t\n", "\t#tune_weights performs the backpropagation algorithm given a training example as input\n", "\tdef tune_weights(self,y):\n", "\t\tself.deltas[self.L][1] = 2*(self.signals[self.L][1]-y)*(1-math.pow(self.signals[self.L][1],2))\n", "\t\tfor i in range(self.L-1,0,-1):\n", "\t\t\tfor j in range(1,self.num_of_neurons[i]+1):\n", "\t\t\t\tself.deltas[i][j] = self.compute_delta(i,j)\n", "\t\tfor i in range(1,self.L+1):\n", "\t\t\tfor j in range(1,self.num_of_neurons[i]+1):\n", "\t\t\t\tfor k in range(self.num_of_neurons[i-1]+1):\n", "\t\t\t\t\tself.weights[i][j][k] = self.weights[i][j][k]-self.learning_rate*self.signals[i-1][k]*self.deltas[i][j]\n", "\t\n", "\t#compute_signal: computes the delta for a given neuron at a given level\n", "\tdef compute_signal(self,level,neuron):\n", "\t\ts = 0\n", "\t\tfor i in range(self.num_of_neurons[level-1]+1):\n", "\t\t\ts += self.weights[level][neuron][i]*self.signals[level-1][i]\n", "\t\treturn self.g(s)\n", "\t\n", "\t#compute_delta: computes the signal s for a given neuron at a given level\n", "\tdef compute_delta(self,level,neuron):\n", "\t\ts = 0\n", "\t\tfor j in range(1,self.num_of_neurons[level+1]+1):\n", "\t\t\ts += self.weights[level+1][j][neuron]*self.deltas[level+1][j]\n", "\t\treturn (1-math.pow(self.signals[level][neuron],2))*s\n", "\t\n", "\t#soft threshold function\n", "\tdef g(self,s):\n", "\t\treturn (math.exp(s)-math.exp(-s))/(math.exp(s)+math.exp(-s))\n", "\n" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 146 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's train a neural network and see how well it performs on the test and training sets epoch by epoch. We will use a mock training and test set with two covariates. We instantiate a neural network with one hidden layer with four neurons, and a learning rate of .001. The learning rate is how much we scale the gradient in \"walking\" the parameter space. \n", "\n", "To gain some intuition, try to tweak some of these knobs.\n", "\n", "Note that this will take about a minute to run!" ] }, { "cell_type": "code", "collapsed": false, "input": [ "#read in the train and test dat, assuming csv format\n", "training = numpy.genfromtxt('train.csv',delimiter = ',')\n", "testing = numpy.genfromtxt('test.csv',delimiter = ',')\n", "\n", "#specify the number of neurons in each layer\n", "num_of_neurons = [2,4,1]\n", "\n", "#initialize a new neural network\n", "network = Neural_Net(num_of_neurons,2)\n", "\n", "#store the training error and test error during each epoch\n", "training_error = 0\n", "test_error = 0\n", "\n", "#store the training and test error for all epochs\n", "train = numpy.zeros(shape = (1000))\n", "test = numpy.zeros(shape = (1000))\n", "\n", "for epoch in range(1000):\n", "\ttraining_error = 0\n", "\ttest_error = 0\n", "\t#compute the test errors\n", "\tfor j in range(250):\n", "\t\ttest_error = test_error+math.pow(network.forward_pass(testing[j]) - testing[j][2], 2)\n", "\t#compute the training errors, SEQUENTIALLY. In other words, we perform backpropagation for *every* example\n", "\t#instead of all at once. \n", "\tfor i in range(25):\n", "\t\ttraining_error = training_error+math.pow(network.forward_pass(training[i])- training[i][2], 2)\n", "\t\tnetwork.tune_weights(training[i][2])\t \n", "\ttraining_error = training_error/25\n", "\ttest_error = test_error/250\n", "\ttrain[epoch] = training_error\n", "\ttest[epoch] = test_error" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 147 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now let's compare the training and test error, epoch by epoch. Do we see signs of overfitting?\n" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fig, ax = plt.subplots()\n", "ax.plot(numpy.arange(1000), test, lw=2, label = 'test')\n", "ax.plot(numpy.arange(1000), train, lw=2, label = 'train')\n", "ax.legend(loc=0)\n", "ax.set_xlabel('Epoch')\n", "ax.set_ylabel('MSE')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 151, "text": [ "" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEOCAYAAABmVAtTAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAL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vl1Qnli1bxqOPPsrNN99Mly5dKCsru6QdpkyZ0qjaRlEUVCoV\nkydPbtTtMHLkSCwWC5988gk7d+5k7969jbY9Jk+ezObNm1m7di2FhYVMnDixUbVFUlISubm5bNy4\nscp2Xm7bq9se0nlNCCGEm8/tKQghhPAeCQUhhBBuEgpCCCHcJBSEEEK4SSgIIYRwk1AQQgjhJqEg\nRC0qKytj0aJFHD582NulCFEtPnebCyHq2rp167jzzjv597//jU6n48SJEzRv3pyZM2de97ICAgLY\ntGkTrVq1okuXLh6oVgjPklAQjd4dd9wBcEkIpKSkVHt5AQEBSJ9QUV/J4SMhfmHlypUcPXqU4cOH\n8+KLL9KjRw9++OEHLBYLr7zyCl9++SXTpk0jJycHp9PJggULWLlyJePHj8fhcADw3XffMWXKFJ59\n9lkvb40Q10f2FISo8Oabb2K1Wlm/fj0ff/wxhYWFPPvsswwaNIiEhAQmTJhAixYtuPPOO7FYLMyd\nO5d+/frRs2dPBg0ahMPhcIfCkCFDiI+Pp1+/frz44ote3jIhrp2EghAVZs2aBcBvfvMbFEVBr9cD\n0Lt3b/Ly8khNTaVp06YA9OjRg4ULF6JWq+nbty8A9913n3tZRqMRvV6PxWKp460Qombk8JEQv9C5\nc2fWrFnj/js7O5v+/fvTvXt3kpKSADh//jy9evUiLi6OTz/9FIDjx49TUFAAIOcURL0lewqi0fvy\nyy9RqVS89NJLhIaGcvz4cQ4ePEhWVhYfffQRGRkZvPjii4SHhzNr1iyWLVvG6dOnefbZZ1GpVIwf\nP55+/frx0EMPcf/993Ps2DEOHTpEWFgYhYWFnDt3jtjYWG9vphDXRG6dLcRlnDp1invvvZedO3d6\nuxQh6pQcPhLiMpKSksjOziY9Pd3bpQhRp2RPQQghhJvsKQghhHCTUBBCCOEmoSCEEMJNQkEIIYSb\nhIIQQgi3/weTlF3S8CpwJQAAAABJRU5ErkJggg==\n", "text": [ "" ] } ], "prompt_number": 151 }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Support Vector Machines: Background and Visual Intuition\n", "\n", "Assume your data set $D$ is = ${(x_1,y_1),...(x_n,y_n)}$, where $x_i \\in \\mathbb{R}^k$ and $y_i \\in \\{1,-1\\}$. A support vector machine attempts to find a plane in $\\mathbb{R}^k$, that is, a \"hyperplane\", that seperates the data of either class. While there may exist an infinite number of planes that achieve this goal (or perhaps none), intuitively we want the one which maximizes the distance between the seperating hyperplane and the closest vectors, termed the \"support vectors\". The hope is that this will allow the model to generalize well. It turns out this condition can be codified as a quadratic programming (optimization) problem. \n", "\n", "Denote an arbitrary hyperplane in $\\mathbb{R}^k$ as $w^tx+b = 0$. The support vector machine is the solution to the constrained optimization problem:\n", "$$minimize$$ $$w^tw$$\n", "Subject to constraint:\n", "$$(w^tx_i)+b \\geq 1, y_i = 1$$\n", "$$(w^tx_i)+b \\leq -1, y_i = -1$$\n", "\n", "Note that this method is useful only in the case that the data appear to be linearly seperable to begin with. In the case they are not, we apply a \"Kernel\" function to the data which warps the points with the hope that they become linearly seperable. There are a variety of kernels that one could utilize to achieve this goal, and sci-kit learn supports a number of them. \n", "\n", "In the following example, we visualize a small mock data set to gain some intuition before applying the SVM method of classification. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "#read in svm data\n", "svm_dat = numpy.genfromtxt('svm.csv',delimiter = ',')\n", "class1 = svm_dat[0:5]\n", "class2 = svm_dat[5:10]\n", "plt.figure()\n", "plt.scatter(class1[:,0],class1[:,1], c = 'blue', marker = 'o')\n", "plt.scatter(class2[:,0],class2[:,1], c = 'red', marker = 'x')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 152, "text": [ "" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAEACAYAAABMEua6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAD6NJREFUeJzt3X9s1PUdx/FXaWn50eKktMG0JJjShVkGJeNHUcRbCJw4\nR5qtiBk08heYzC1LDH9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4g6ABhC1AHAkP8DBF5k8LSpvS4AAAAASUVORK5CYII=\n", "text": [ "" ] } ], "prompt_number": 152 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Can you guess what the support vectors are in this data set? (Hopefully it is easy to see.) Let's actually fit a SVM to check our suspicions." ] }, { "cell_type": "code", "collapsed": false, "input": [ "from sklearn import svm\n", "X = np.column_stack((svm_dat[:,0],svm_dat[:,1]))\n", "y = svm_dat[:,2]\n", "clf = svm.SVC(kernel='linear')\n", "clf.fit(X, y)\n", "clf.support_vectors_\n", "plt.scatter(class1[:,0],class1[:,1], c = 'blue', marker = 'o',s=20)\n", "plt.scatter(class2[:,0],class2[:,1], c = 'red', marker = 'x',s=20)\n", "plt.scatter(clf.support_vectors_[0,0],clf.support_vectors_[0,1],c='blue',marker = '*',s=200)\n", "plt.scatter(clf.support_vectors_[1,0],clf.support_vectors_[1,1],c='red',marker = '<', s = 100)\n", "#Get the separating hyperplane\n", "w = clf.coef_[0]\n", "a = -w[0] / w[1]\n", "xx = np.linspace(-15, 10)\n", "yy = a * xx - (clf.intercept_[0]) / w[1]\n", "t = numpy.linspace(-15,10,100) # 100 linearly spaced numbers\n", "plt.plot(xx,yy)" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 155, "text": [ "[]" ] }, { "metadata": {}, "output_type": "display_data", "png": "iVBORw0KGgoAAAANSUhEUgAAAXUAAAEACAYAAABMEua6AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHUtJREFUeJzt3XlwFHX+//Hn5CBAEo4AghIViEEMLuEmyBUFCS4CUUHw\n4Fv79aD0tyi7fhfFo4BQnqsLq+BaKypV67EBFKOIHOsRAgjhkCMcMQqaAGvAGI5MyEyOmd8fI1e4\ncvRMp3tejyrKmZhMv+nRF81nuvvl8Hq9XkRExBZCzB5ARESMo1AXEbERhbqIiI0o1EVEbEShLiJi\nIwp1EREbqXeo5+Tk4PF4zvm60+ms70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n3/+OXfccQdr166lV69eTJgw\ngebNm5OUlESfPn24/vrrzR7xoqrPX1ZWZqn9D1hun4Pvf8rp06fTrVs3cnJySEtLw+FwmD1WjU2d\nOpX8/HxGjx5Nhw4dGDhwoNkj1cjmzZtJTk4mPT2dkSNHWu492Lx5MzfeeCMffPABWVlZtXoPdPGR\niIiN6OIjEREbUaiLiNiIQl1ExEYU6iIiNqJQFxGxEYW6iIiNKNRFRGxEoS4iYiP/H3IVimi2i8zT\nAAAAAElFTkSuQmCC\n", "text": [ "" ] } ], "prompt_number": 155 }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, there are precisely two support vectors from the data set of 10 vectors with one from each class. To play with this example, you may want to consider other kernels for data sets that are not inherently linearly seperable like this example. Sci-kit learn's documentation expounds on various choices of kernel. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Hierarchical Agglomerative Clustering: Background and An Example From Molecular Biology\n", "\n", "Switching gears from classifiation to clustering, we finish by covering hierarchical agglomerative clustering. This is a nice contrast to K-Means which was covered in class becuase one does not need to specify K, the number of clusters in advance. Given a data set $D = {x_1,...x_m}$, hierarchical clustering proceeds by computing the matrix of pearson similiarities (analgously to homework 4). One then builds a binary tree utilizing this matrix with an iterative procedure. Specifically, the leaves of the tree are the initial $m$ data points. At each step of the iteration, we link the two closest nodes, where the distance between nodes $A$ and $B$ is given by\n", "\n", "$$D(A,B) = min(s(a,b): a \\in A, b \\in B)$$.\n", "\n", "where s(.,.) is the familiar pearson similarity from homework 4. Finally, to extract the clusters from this tree, we want to select nodes from which the data is \"highly correlated\". One way to determine this is to check if these pairwise distances within the node are normally distributed, which can be checked with the Anderson-Darling test of normality. \n", "\n", "An area of biology called functional genomics attempts to determine the function(s) of genes, as the name would suggest. One approach to solving this problem is to cluster microarray data, which measures the expression levels of all of the genes in a cell under different time points or experimental conditions. If an unannotated gene ends up in a cluster with many genes of a known function, this lends evidence that the gene may be associated with said function and could prompt additional experiments. In the next example, we will cluster public yeast microarray data, available here: http://rana.lbl.gov/data/yeast/yeastall_public.txt.gz. It contains 6221 genes under 81 experimental conditions. We will utilize scipy's implementation of Hierarchical Clustering for this example. Note that this will take several minutes to run!\n", "\n", "\n", "NOTE: Sadly, the implementation of hierarchical clustering in scipy or sci-kit learn does not utilize the stopping criterion used above. To complete the example, we will use their implementation nonetheless, but please consult reference [3] for more if you would like to implement this stopping criterion. " ] }, { "cell_type": "code", "collapsed": false, "input": [ "from scipy import cluster\n", "from scipy.cluster import hierarchy\n", "#Read in the gene expression data set\n", "gene_expression = numpy.genfromtxt('yeastall_public.txt',delimiter = '\\t',skip_header = 2, usecols = range(2,83))\n", "#Perform hierarchical clustering\n", "C=hierarchy.fclusterdata(gene_expression,1,metric='correlation')" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 170 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, try exploring the clusters and in particular compare this to the clusters found in reference [3]. Do you find any clusters are enirched for a particular gene function?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#References\n", "\n", "1. \"Learning From Data\" by Yaser S. Abu-Mostafa et al.\n", "2. \"Cluster Analysis and Display of Genome-Wide Expression Patterns\" by Eisen at al.\n", "3. \"De-Trending Time Series for Astronomical Variability Surveys\" by Kim et al." ] } ], "metadata": {} } ] }