{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Machine Learning\n", "-----------------------------" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "#### Preface\n", "-------\n", "- What is Machine Learning?\n", "\n", "\n", "> “A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.”\n", "\n", "This is how [Tom Mitchelle] defines Machine Learning. It is essentially art and science of designing adaptive algorithms. In other words, Designing algorithms that ingest data and learn a (hypothesized) model of the data. This model can then be used to detect patterns, predict future data points, help in decision making, etc.\n", "\n", "\n", "- When to use Machine Learning?\n", "\n", "\n", "When there is no closed form solution, has too many ways to solve problem, a need for automation. That means sometimes it is infeasible for humans to write a normal computer program or cannot specify a rigid rule to solve the problem. \n", "\n", "For example, finding spelling mistake is not a Machine Learning problem, however, suggesting correct spelling can be a good ML problem\n", "\n", "[Tom Mitchelle]: #" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Features\n", "---------------\n", "\n", "Finally, when we give problems to computer, it should be nice set of numbers. So be it any problem, we need to convert it into set of numbers so that computer can process. In ML we call it features. Most ML Algorithms use numerical vectors to represent features. Lets look at an example of this.\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Problem statement: To identify incoming email as spam or not\n", "\n", "Let's understand the problem first. To identify a new email as spam or not system should know how a normal mail and a spam mail look like. Now is a good time to understand *Training Data* and *Test Data*. Email that we already have can be used to teach computer how normal email and spam email look like. These are our Training Data. Any new incoming email would be Test Data. Job of ML trained computer is to predict this new email as spam or not.\n", "\n", "Example: Consider following three email headings: -\n", "\n", "- Good Email: Do you want to go for dinner?\n", "- Spam Email: Do you want to win a million dollars?\n", "- Good Email: I have a million things to do today!\n", "\n", "For computers to start its job, we need to convert these emails to numbers. More precisely a __feature vector__. One way to do it is called __bag of words__. We encode the emails as shown below: -\n", "\n", "| Email | Do|You|Want|Go|Million|Dollars|Dinner|Today|\n", "|----------|-----|---|----|--|-------|-------|------|-----|\n", "| Email1 | 1 |1 |1 |1 |0 |0 |1 |0 |\n", "| Email2 | 1 |1 |1 |0 |1 |1 |0 |0 |\n", "| Email3 | 1 |0 |0 |0 |1 |0 |0 |1 |\n", "\n", "\n", "Programmatically, the things would approximately look like as given below. (Certainly not the best way, but this is for demonstration purpose only): -\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "email1 = \"Do you want to go for dinner?\"\n", "email2 = \"Do you want to win a million dollars?\"\n", "email3 = \"I have a million things to do today!\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import re" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Creating bag of words for the given three emails\n", "bagOfWords = []\n", "for email in [email1, email2, email3]:\n", " for string in set(email.split(' ')):\n", " if string not in bagOfWords:\n", " bagOfWords.append(re.sub(r'[\\W_]', '', string))" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['you', 'want', 'Do', 'dinner', 'to', 'for', 'go', 'million', 'dollars', 'win', 'a', 'things', 'do', 'I', 'have', 'today']\n" ] } ], "source": [ "# So this is our bag of words.\n", "print(bagOfWords)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "[nltk_data] Downloading package stopwords to /home/rahul/nltk_data...\n", "[nltk_data] Unzipping corpora/stopwords.zip.\n" ] } ], "source": [ "# But we need to clean up the stop words from this list, since it does not give much information about nature of mail.\n", "import nltk\n", "nltk.download('stopwords')\n", "from nltk.corpus import stopwords" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "for string in bagOfWords:\n", " if string.lower() in set(stopwords.words('english')):\n", " bagOfWords.remove(string)" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['want', 'dinner', 'go', 'million', 'dollars', 'win', 'things', 'today']\n" ] } ], "source": [ "print(bagOfWords)" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "# Now we will convert each email to a vector as follows: -\n", "v = [0] * len(bagOfWords) # initialize vector v\n", "for string in bagOfWords:\n", " if string in [re.sub(r'[\\W_]','', s) for s in email1.split(' ')]:\n", " v[bagOfWords.index(string)] = 1\n", "e1 = v # Saving vector to variable e1 for email1" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 1, 1, 0, 0, 0, 0, 0]" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e1" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "v = [0] * len(bagOfWords)\n", "for string in bagOfWords:\n", " if string in [re.sub(r'[\\W_]','', s) for s in email2.split(' ')]:\n", " v[bagOfWords.index(string)] = 1\n", "e2 = v" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[1, 0, 0, 1, 1, 1, 0, 0]" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e2" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "v = [0] * len(bagOfWords)\n", "for string in bagOfWords:\n", " if string in [re.sub(r'[\\W_]','', s) for s in email3.split(' ')]:\n", " v[bagOfWords.index(string)] = 1\n", "e3 = v" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0, 0, 0, 1, 0, 0, 1, 1]" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "e3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see the emails have been encoded as vectors now. Final result will be as follows\n", "\n", "\n", "| email | plain_text | vectorized_format |\n", "|-------|:------------:|-------------------|\n", "|email1 | \"Do you want to go for dinner?\" |[1, 1, 1, 0, 0, 0, 0, 0]|\n", "|email2 | \"Do you want to win a million dollars?\" | [1, 0, 0, 1, 1, 1, 0, 0] |\n", "|email3 | \"I have a million things to do today!\" |[0, 0, 0, 1, 0, 0, 1, 1]|\n", "\n", "This is easier said than done. We have the vectors. But as you can notice, they are 1 X 8 dimensions. In other words you can say each email has 8 features and each of them is a dimension of that datapoint(email in this case). Visualizing beyond three dimension is a skill and is not possessed by all. So let us see a technique to reduce the dimension to 2 or 3 from any higher dimension so that visualization fairly represent the same as that in the higher dimension. This will help us appreciate better." ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[-869.4694 , 834.6181 ],\n", " [-406.4485 , 931.1655 ],\n", " [-554.34845, 481.90427]], dtype=float32)" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Here we use method called t-distributed Stochastic Neighbor Embedding or simply t-SNE\n", "import numpy as np\n", "from sklearn.manifold import TSNE\n", "X = np.array([e1, e2, e3])\n", "X_embedded = TSNE(n_components=2).fit_transform(X)\n", "X_embedded" ] }, { "cell_type": "code", "execution_count": 83, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAFL1JREFUeJzt3XuUXeV53/HvM1ddQQgNQoCwuJqCbTAMFC/Ht8gXwBcR26UkqVEwjmIXp45xqKFdy3HjdBVfulw7qWmFcZbUpjb4koVWIC6gFidpFsIjzB1syRiMZNAFgWRLSJrL0z/OVhhkxJzROWfOzKvvZ62zznve8+6t57yMfrN59z5bkZlIksrV0e4CJEmtZdBLUuEMekkqnEEvSYUz6CWpcAa9JBXOoJekwhn0klQ4g16SCtfV7gIA5s2bl4sWLWp3GZI0paxd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1DwcaA4i4rXUzkHcX91U7jjg3upCjebnQrtPRhwKD+BR4K1VezGwtmq/m5eedLknXzzp8jNqJ1yOqNpz2/05mjAPFwA/2K/vDF568u1xaifeuqr2Cbx48u2Mdn+GJszBR4E/rdqnUvtf8TgE52HBqPYnqa3LH3I/D6Pm4AlePBnb9FzwiH5i/D7wleqIdjewrOq/jdoZ9vXALuBygMzcFhGfA35YjfvTzNw2sSW3xKXst2yTmQ9HxM3AI8AQcGVmDgNExMepXZHQCXwjMx+e4Hpb4RvANyLiIWAvsDRrf4sPtXn4QkScRW3p5gngD+CQ/Hl4OU3PBb8ZK0mF86obSSqcQS9JhTPoJalwBr0kFc6gl6TCGfSSVDiDXpIKZ9BLUuH+PzbgE8cbYlJ8AAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "from matplotlib import pyplot as plt\n", "colors = np.random.rand(3)\n", "area = 300\n", "plt.scatter(X_embedded.T[0],X_embedded.T[1],s=area, c=colors)\n", "plt.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Above picture represent the emails that we have discussed earlier. These are data points which will be inputs for computers for training. Obvisouly we have converted the 8 dimensional vector on to a 2D to visualize. However, computers will see as is in the 8 dimensions. In upcoming series we will see that we will be handling dimensions go as high as hundreds or thousands and computers will have no problems handling in such higher dimension. But due to [curse of dimensionality](https://en.wikipedia.org/wiki/Curse_of_dimensionality), we often tend to come down to lower dimensions. We will discuss this in future posts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Author\n", " - Name: Rahul Raj\n", " - Website: [rahulrajpl.github.io](http://rahulrajpl.github.io)\n", " - Published date: 03 Aug, 19" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### License\n", "----------------\n", "~~~\n", "Permission is granted to copy, distribute and/or modify this\n", "document under the terms of the GNU Free Documentation License,\n", "Version 1.3 or any later version published by the Free Software\n", "Foundation; with no Invariant Sections, no Front-Cover Texts, and\n", "no Back-Cover Texts. A copy of the license is included in the\n", "section entitled \"GNU Free Documentation License\".\n", "~~~" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }