Created
May 28, 2016 18:30
-
-
Save marcodiiga/dcddcc96ca1104747a82519a0040bbc9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Logistic Regression\n", | |
"\n", | |
"There are cases when [linear regression](http://marcodiiga.github.io/linear-regression) simply doesn't cut it. Classification tasks are classical examples for which a linear regression approach wouldn't suffice.\n", | |
"\n", | |
"Consider the following case as a classification task where we're interested in the probability $h_\\theta(x) = P(y=1|x;\\theta)$. If $h_\\theta(x) \\ge 0.5$ we consider the sample as verifying the hypothesis." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEACAYAAABbMHZzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHxJJREFUeJzt3Xt0VeW57/Hvw61EFLYoXsANaEsKpYJiZWO1dqGloEfw\nfgFbWxy2tLXq0LPdIFYJu1pRW6tusA4UrZ6Kl9p6CqdaLwOXbiyUqGi4JARlB0TRAFqhKPfn/PEu\naIxZCcmaWXOtzN9njIyxLm/m+4hZv8y885lzmrsjIiLJ0i7uAkREJP8U/iIiCaTwFxFJIIW/iEgC\nKfxFRBJI4S8ikkCRhL+ZzTKzD8ysopExKTNbbGZLzezFKOYVEZGWsSj6/M3sJOAfwMPuPqiB97sB\nfwW+7e7vmtnB7r4h54lFRKRFItnzd/f5wEeNDBkH/MHd382MV/CLiMQoX2v+pUB3M3vRzMrN7Lt5\nmldERBrQIY/zDAFOAboAC8xsgbu/laf5RUSkjnyF/1pgg7tvBbaa2cvAYOBz4W9mutiQiEgzubs1\nZ3yUyz6W+WrIn4C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rgR3uPjvuWurL7IhMBqbUfTmmcprSATjQ3YcB/0Ho\nwmxUoYT/u0DvOs+PyLxWcDJ/+j8J/B93z3ZeQ9xOBMaY2SrgUWC4mT0cc00NWUvYq3o18/xJwi+D\nQvItYJW7f+juu4A/Al+PuaamfGBmhwJkTr6sjbmeBpnZ9wlLk4X6y/SLQF/gTTP7H0IuvWZmhfiX\n1DuEn03cvRzYbWYHNfYNhRL+5cCXzKxPppPiIsIJZIVon09Yi4u7T3b33u5+FOHfcp67XxJ3XfVl\nlibeMbPSzEunUngHqNcAw8yss5kZocaCOijN5/+623PyJTR+8mU+faZGMxtFWJYc4+7bYqvq8/bW\n6e5L3f0wdz/K3Y8k7Kwc6+6F8Mu0/v/z/wucApD5PHV0942NbaAgwj+zR/VTQgfAMuAxdy+0DxiZ\nE9YuBk4xs8WZdepRcddV5K4EHjGzNwjdPr+IuZ7PcPdFhL9IFgNvEj5wM2Mtqg4zmw38FSg1szVm\nNh6YBowwsxWEX1ZNtv3FUON/AfsDz2c+R/fEWSNkrbMupwCWfbLU+QBwlJktAWYDTe7s6SQvEZEE\nKog9fxERyS+Fv4hIAin8RUQSSOEvIpJACn8RkQRS+IuIJJDCX0QkgRT+IiIJ9P8BSqgBkLF8+dIA\nAAAASUVORK5CYII=\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x40c3cf8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%matplotlib inline\n", | |
"import matplotlib.pyplot as plt\n", | |
"import numpy as np\n", | |
"\n", | |
"def genClassificationData():\n", | |
" x = np.zeros(shape=9)\n", | |
" y = np.zeros(shape=9)\n", | |
"\n", | |
" # Empirically adjusted for clarity's sake\n", | |
" x[0] = 1\n", | |
" x[1] = 2.2\n", | |
" x[2] = 2.7\n", | |
" x[3] = 3\n", | |
" y[0] = y[1] = y[2] = y[3] = 0\n", | |
"\n", | |
" x[4] = 4\n", | |
" x[5] = 5.2\n", | |
" x[6] = 5.7\n", | |
" x[7] = 6\n", | |
" y[4] = y[5] = y[6] = y[7] = 1\n", | |
"\n", | |
" x[8] = 14\n", | |
" y[8] = 1\n", | |
"\n", | |
" return x, y\n", | |
"\n", | |
"def normEquation(x, y):\n", | |
" ll = []\n", | |
" for sample in x:\n", | |
" ll += [[1] + [sample]]\n", | |
" X = np.matrix(ll)\n", | |
" ll = [[sample] for sample in y]\n", | |
" y = np.matrix(ll)\n", | |
" x_trans = X.T\n", | |
" A = (x_trans * X).I\n", | |
" theta = A * x_trans * y\n", | |
" return theta\n", | |
"\n", | |
"def plotLinearPredictor(x, y, theta):\n", | |
" plt.figure()\n", | |
" plt.scatter(x, y)\n", | |
"\n", | |
" y_regression = np.zeros(len(x))\n", | |
" for sample in range(0, len(x)):\n", | |
" y_regression[sample] = theta[0] + theta[1] * x[sample]\n", | |
"\n", | |
" plt.plot(x, y_regression)\n", | |
" plt.show()\n", | |
"\n", | |
"x, y = genClassificationData()\n", | |
"theta_coefficients = normEquation(x, y)\n", | |
"plotLinearPredictor(x,y, theta_coefficients)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Establishing decision boundaries\n", | |
"\n", | |
"Ideally for a well-trained binary classifier we would like to be able to tell if a sample $P$ lies in the region that verifies our hypothesis. For a parametric one-degree polynomial this is trivially $\\theta_0 + \\theta_1 x_1 + \\theta_2 x_2 \\ge 0$.\n", | |
"\n", | |
"Let us define $h_{\\theta}(x) = g(\\theta^{T}x)$ and consider\n", | |
"\n", | |
"$$\n", | |
"g(x) = \\frac{1}{1+e^{-x}}\n", | |
"$$\n", | |
"\n", | |
"this is known as the **sigmoid** or **logistic** function." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhkiAAAA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gjY\nA0wCJjfbZhlwK7Ao94/B/pbm7cWGExGR9mmz3N290cymATV8cirkZjObGl72We6+3MyuNrPthFMh\nb+7c2CIicjRdehGTiIh0jS5Zz93MrjezV82s0cyGN3vth2a2zcw2m9mVXZEnTczsDjOrNbN1uVtV\n7ExJY2ZVZrbFzLaa2fTYeZLOzHaY2UYzW29ma2LnSRozm2tm9Wb2ct5zJ5tZjZm9bmZPmVnvtt6n\nqz6s4xXgq8Dz+U+a2fnAjcD5hKtbZ5rpBL52+Km7D8/dnowdJklyF+nNAK4ChgKTzey8uKkSrwnI\nuPtF7t78tGlp2wOE38d8twNPu/vngGeBH7b1Jl1S7u7+urtvA5oX93hgobsfcvcdwDaOPIde2qZ/\nENvv44v03L0BOHyRnrSfoU95azd3/y2wr9nT44GHcl8/BExo631i/wdo7eInKc40M9tgZnMK+d81\n+ZSWLtLT72DHOPAbM1trZv89dpiUOPXwGYju/g5walvfULKLmMzsN0C//KcI/5F/5O6Pl+rPqURH\n+9kCM4E73d3N7F+BnwLf7vqUIh8b7e57zOwUQslvzu2NSum0eSZMycrd3a9ox7fVAQPzHg/IPSd5\nivjZzgb0D2lx6oAz8x7rd7CD3H1P7v73ZvYrwuhL5d4x9YfX6zKz04D/ausbYoxl8ufDy4BJZnas\nmQ0GzgF0dL0Iuf/Qh00EXo2VJaE+vkjPzI4lXKS3LHKmxDKznmb2mdzXJwJXot/J9jCO7Mqbcl//\nPfBYW2/QJWvLmNkE4OdAX+AJM9vg7uPc/TUzewR4DWgAbtGawEW718yGEc5Q2AFMjRsnWVq7SC9y\nrCTrB/wqt9RID+AX7l4TOVOimNl8IAP8pZm9DdwB3A08ambfAnYSzjI8+vuoS0VE0if22TIiItIJ\nVO4iIimkchcRSSGVu4hICqncRURSSOUuIpJCKncRkRRSuYuIpND/ByTjFOvgW+4bAAAAAElFTkSu\nQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x40b3f60>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"sigmoid = lambda x: 1.0 / (1.0 + np.exp(-x))\n", | |
"plt.figure()\n", | |
"x = [float(i)/10 for i in range(-100, 100)]\n", | |
"y = [sigmoid(i) for i in x]\n", | |
"plt.plot(x, y)\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"We can now interpret the hypothesis' output as a function of the sigmoid parametrized by $\\theta$." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Convexity of the cost function\n", | |
"\n", | |
"Applying gradient descent or another method that relies on the convexity of the search function will not work with logistic regression if we're to use the same cost function\n", | |
"\n", | |
"$$\n", | |
"J(h_\\theta(x), y)=\\sum^{m}_{i=1}{(h_\\theta(x^{(i)}) - y^{(i)})^2}\n", | |
"$$\n", | |
"\n", | |
"since we're now using a nonlinear function. We need to encode two considerations into a mathematical expression:\n", | |
"\n", | |
"* if $P(y=1|x;\\theta) = 0$ and $y = 1$, a penalty process has to take place (large cost)\n", | |
"* conversely if $P(y=1|x;\\theta) = 1$ and $y = 0$, a similar penalty is needed\n", | |
"\n", | |
"Therefore\n", | |
"\n", | |
"$$\n", | |
"J(h_\\theta(x), y)=-\\frac{1}{m}\\sum^{m}_{i=1}{y^{(i)}log(h_\\theta(x^{(i)})) + (1 - y^{(i)})log(1 - h_\\theta(x^{(i)}))}\n", | |
"$$\n", | |
"\n", | |
"This formulation has the following additional advantage\n", | |
"\n", | |
"$$\n", | |
"\\frac{\\partial}{\\partial \\theta_j}J(h_\\theta(x), y) = \\frac{1}{m} \\sum^{m}_{i=1}{(h_\\theta(x^{(i)}) - y^{(i)}) x_j^{(i)}}\n", | |
"$$\n", | |
"\n", | |
"this grants us the same formulation as the linear case." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Multiclass classification\n", | |
"\n", | |
"Classification can occur among many different classes. Two approaches are commonly used:\n", | |
"\n", | |
"* One vs. all\n", | |
"* One vs. many\n", | |
"\n", | |
"In the first approach the problem is decomposed into a number of binary classification problems that can in turn be solved via logistic regression. Given $k$ classes a problem needs to be solved via binary classification $k$ times. In the latter approach a classifier is constructed for each binary subset (generally slower).\n", | |
"\n", | |
"Suppose we have the following multiclass training set data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAEACAYAAACnJV25AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAFEFJREFUeJzt3X+QXXV9xvHn2SRLFmgg6pJUorvSjtFSKTKDpaWduVZS\no7aEsTPW2GnBbjv8UYRqxwHpONlxbEeYaayt8oeyMsGRFaW1kI4/gMGrgx0wFaKJxOiM3UDUXVeF\nVCC4S/LpH+ds2KS7m3vuPXfPPd+8XzN39tyz95zzETfPfvdzvuccR4QAAOnoq7oAAEC5CHYASAzB\nDgCJIdgBIDEEOwAkhmAHgMQUDnbbfbYfsX1P/n6t7Xtt77f9ZdtnlV8mAKBV7YzYr5P02Lz3N0i6\nPyI2SnpA0vvKKAwA0J5CwW57g6Q3S7p13uotknbkyzskXVFOaQCAdhQdsX9Y0nslzb9cdV1ETElS\nRExKOqek2gAAbWg52G2/RdJUROyW5CU+yj0KAKBCKwt89lJJl9t+s6QBSb9i+1OSJm2vi4gp2+sl\n/WShjW0T+ADQhohYajD9/7Q8Yo+IGyPi5RFxnqS3S3ogIv5c0k5JV+Ufu1LS3Uvso7avbdu2VV7D\nqVp/nWun/upfda+/HWXMY/+QpE2290t6Q/4eAFCRIq2YYyLiq5K+mi//XNJlZRYFAGgfV562qNFo\nVF1CR+pcf51rl6i/anWvvx1ut4dT+EB2LNexACAVthXdOnkKAKgHgh0AEkOwA0BiCHYASAzBDgCJ\nIdgBIDEEOwAkhmAHgMQQ7ACQGII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, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import copy\n", | |
"\n", | |
"def generateMulticlassClassificationData():\n", | |
"\n", | |
" x = [np.zeros(shape=4), np.zeros(shape=4), np.zeros(shape=4), np.zeros(shape=4)]\n", | |
" y = copy.deepcopy(x)\n", | |
"\n", | |
" for i in range(0, len(x)):\n", | |
" x_offset = (i % 2) * 10\n", | |
" y_offset = i * 10\n", | |
" x1 = x[i]\n", | |
" y1 = y[i]\n", | |
" x1[0] = 1 + x_offset + np.random.uniform(0, 2) - 1\n", | |
" y1[0] = 2 + y_offset + np.random.uniform(0, 2) - 1\n", | |
" x1[1] = 2 + x_offset + np.random.uniform(0, 2) - 1\n", | |
" y1[1] = 3 + y_offset + np.random.uniform(0, 2) - 1\n", | |
" x1[2] = 2 + x_offset + np.random.uniform(0, 2) - 1\n", | |
" y1[2] = 1 + y_offset + np.random.uniform(0, 2) - 1\n", | |
" x1[3] = 3 + x_offset + np.random.uniform(0, 2) - 1\n", | |
" y1[3] = 3 + y_offset + np.random.uniform(0, 2) - 1\n", | |
"\n", | |
" return x, y\n", | |
"\n", | |
"def plotScatterData(x, y):\n", | |
" color = {\n", | |
" 0: 'r',\n", | |
" 1: 'b',\n", | |
" 2: 'g',\n", | |
" 3: 'y'\n", | |
" }\n", | |
" for i in range(0, len(x)):\n", | |
" plt.scatter(x[i], y[i], color=color[i])\n", | |
" plt.show()\n", | |
"\n", | |
"x, y = generateMulticlassClassificationData()\n", | |
"plotScatterData(x, y)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The following code implements a *one vs. all* logistic regression approach" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAEACAYAAACwB81wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AA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IStWrGDKlCmEhIQQFhZG\namoqf//9d4H3hoaGMm7cON555x1OnDhRoCZeFoMGDWLXrl18/fXXPP300047rl3e/+V96r9aH4B9\nY/fxWp/XbI7I85T5KR1jTE2gh4iMBBCRdOCUMWYgcE1WsXAgAusiUOnUqFGDrVu3Ftjv5+eX872I\n0KdPH2bPnp2vzPbt24t1e16aQSd5j5s3lhYtWrB161a+/fZbnn76aa677rpSJ5S8xz2f6tWr5/wc\nKSkp/Pvf/2br1q1ceOGFPPvss4V28FarVg2wOsfT09OLLAMlb+5YtmwZ69atY8mSJbz44ovs2LED\nEWHhwoW0aNEiX9lNmzbl237iiSfo378/y5YtIzQ0lBUrVtCyZctCz9WoUaN8F47Dhw/TqFGjIuO7\n6qqrOHDgAPHx8dStW7dEP5srOJt2Fr+X/BCEm1vdzFdDCzarqYrhjOpIM+CYMeZTY8xWY8yHxpga\nQKCIxACISDTQ0AnnckmFJZi8+7t3787GjRvZv38/YLUR7927l1atWhEVFZXzJMycOXMcHqtXr15M\nn27NIZKZmUlCQgIBAQGcPn06p0yPHj348ssvyczMJC4ujvXr19O1a9cCxzp69Ci+vr7ccccdjB8/\n3uHFKq8ePXrw9ddfk5ycTFJSEosWLaJHjx5F/uwANWvWJCEhweHvIzk5GWMM9erVIzExkQULFhQZ\nQ0lknyc0NJSFCxciIsTExBAREeGw7N9//80111zDlClTSEhIICkpieuvv5633347p9y2bdsAqx8i\n78904MAB2rZty+OPP06XLl3YvXt3kbF16dIlp48nNTWVuXPnMmDAAADee++9nM84++8EYOvWraSm\nprplsl+yZwk1XqqBIGz+12ZN9jZzxnP4VYCOwL9F5FdjzJtYNflzM4F79zIVobDad9799evXZ+bM\nmQwbNoyUlBSMMbzwwgu0aNGCGTNmcMMNN+Dn50ePHj1ITEwscKy33nqLe++9l48//pgqVarw/vvv\n061bN6688krat29Pv379mDp1Kj/99BPBwcF4eXnx6quv0rBhQ3bt2pXvWDt27GD8+PF4eXnh4+Nz\n3kc7Q0JCGDlyJF26d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/98aYICBI\nRLYZY/yBLVjjhUbhBp9BEfEPpQSfgW01fBHZIyJ7yWr3z8NdB22500jirsBeEYkSkTRgLtbv3Z0Y\n3GguKBHZAJx7cRoIhGd9Hw4MqtCgSqCQ+MFN/u5FJFpEtmV9nwjswqpQusVnUEj82WObiv0ZuOJ/\nGHcdtPWQMWabMeZ/rnpbmMe5v+PDuMfvOC8BVhpjfjHGjLE7mFJqKCIxYP2HBhraHE9puNPfPQDG\nmKZAB2ATEOhun0Ge+LMfcy/2Z1CuCd8Ys9IY83uerx1Z/95UnuctD+f5WaYDl4hIByAacPlb3Eog\nVEQ6AjcA/85qcnB3LttsWQi3+7vPag5ZADycVVM+93fu0p+Bg/hL9Bk487HMAkSkNKNwjwCN82xn\nD+iyVQl+lo+ApeUZixMcAS7Os+0Sv+OSEJGjWf/GGWMWYTVTbbA3qhKLMcYEikhMVhttrN0BlYSI\nxOXZdPm/e2NMFaxk+ZmILM7a7TafgaP4S/oZuEqTTt42qCXA7cYYH2NMM+BSwKWfwsj6Q8k2GPjD\nrliK6RfgUmNME2OMD3A71u/dLRhjamTVdDDG+AF9cP3fOVh/5+f+rY/M+n4EsPjcN7iYfPG74d/9\nJ8BOEZmWZ587fQYF4i/pZ2DnUzqDgHeA+sBJYJuI9Mt6bSIwGmvQ1sMissKWIIvJGDMLq00tE4gE\n7stuF3RVWY9vTcO66H+cPQ2GO8iqCCzCuv2uAsx29fiNMV8AYUA9IAaYBHwNzMe6o40ChojISbti\nLEoh8ffETf7ujTGhwDpgB9bfjWDNBbYZmIeLfwZFxH8HJfgMdOCVUkp5CFdp0lFKKVXONOErpZSH\n0ISvlFIeQhO+Ukp5CE34SinlITThK6WUh9CEr5RSHkITvlJKeYj/B4NM8nvWNa8CAAAAAElFTkSu\nQmCC\n", | |
"text/plain": [ | |
"<matplotlib.figure.Figure at 0x6eed6d8>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"def gradientDescentMC(x, y, setIndex, alphaFactor, numIterations):\n", | |
" theta = np.ones(3)\n", | |
" x_transposed = np.array([item for sublist in x for item in sublist]).transpose()\n", | |
" y_transposed = np.array([item for sublist in y for item in sublist]).transpose()\n", | |
"\n", | |
" yl = [int(set == setIndex) for set, sublist in enumerate(y) for _ in sublist]\n", | |
" n_samples = sum([len(set) for set in x])\n", | |
"\n", | |
" np.seterr(all='raise') # Watch out for over/underflows\n", | |
"\n", | |
" for i in range(0, numIterations):\n", | |
"\n", | |
" sigmoid = lambda x: 1.0 / (1.0 + np.exp(-x))\n", | |
"\n", | |
" hypothesis = np.zeros(n_samples)\n", | |
" offset = 0\n", | |
" for set in range(0, len(x)): # We're keeping this verbose for readability's sake\n", | |
" for sample in range(0, len(x[set])):\n", | |
" hypothesis[offset + sample] = sigmoid(theta[0] + theta[1] * x[set][sample] + theta[2] * y[set][sample])\n", | |
" offset += len(x[set])\n", | |
"\n", | |
" error_vector = hypothesis - yl\n", | |
"\n", | |
" gradient = np.zeros(3)\n", | |
" gradient[0] = np.sum(error_vector) / n_samples\n", | |
" gradient[1] = np.dot(x_transposed, error_vector) / n_samples\n", | |
" gradient[2] = np.dot(y_transposed, error_vector) / n_samples\n", | |
"\n", | |
" theta = theta - alphaFactor * gradient\n", | |
"\n", | |
" return theta\n", | |
"\n", | |
"'''\n", | |
" Boilerplate plotting helpers\n", | |
"'''\n", | |
"def drawMCPredictors(theta_vector):\n", | |
" color = {\n", | |
" 0: 'r',\n", | |
" 1: 'b',\n", | |
" 2: 'g',\n", | |
" 3: 'y'\n", | |
" }\n", | |
" plt.text(-5, 60, \"Predictors for training sets [0;\" + str(len(x) - 1) + \"]\")\n", | |
" for i in range(0, len(x)): # Graph all predictors\n", | |
" y_regression = np.zeros(25)\n", | |
" x_regression = np.zeros(25)\n", | |
" for sample in range(-5, 20):\n", | |
" x_regression[sample] = sample\n", | |
" y_regression[sample] = -(theta_vector[i][0] + theta_vector[i][1] * sample) / theta_vector[i][2]\n", | |
" plt.plot(x_regression, y_regression, color=color[i])\n", | |
"\n", | |
"def getMCThetaVector(x, y):\n", | |
" theta_vector = []\n", | |
" for i in range(0, len(x)):\n", | |
" theta_vector.append(gradientDescentMC(x, y, i, 0.01, 30000))\n", | |
" return theta_vector\n", | |
"\n", | |
"def plotScatterData(x, y):\n", | |
" color = {\n", | |
" 0: 'r',\n", | |
" 1: 'b',\n", | |
" 2: 'g',\n", | |
" 3: 'y'\n", | |
" }\n", | |
" for i in range(0, len(x)):\n", | |
" plt.scatter(x[i], y[i], color=color[i])\n", | |
" plt.show()\n", | |
"\n", | |
"x, y = generateMulticlassClassificationData()\n", | |
"theta_vector = getMCThetaVector(x, y)\n", | |
"drawMCPredictors(theta_vector)\n", | |
"plotScatterData(x, y)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"New samples will be classified according to\n", | |
"\n", | |
"$$\n", | |
"\\max_{i} h_\\theta^{(i)}(x)\n", | |
"$$\n", | |
"\n", | |
"where $i$ is the class that maximizes $h_\\theta(x)$." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Considerations\n", | |
"\n", | |
"Other advanced algorithms are available for logistic regression tasks, for instance *conjugate gradient* or *BFGS* to solve unconstrained nonlinear optimization problems. Upside is speed and no need to choose an $\\alpha$ parameter, downside is usually the added complexity to implement them." | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment