{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Machine Learning - 1**\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Table of Contents:\n", "\n", "1. [Artificial Intelligence](#Artificial-Intelligence)\n", "1. [Machine Learning](#Machine-Learning)\n", "1. [Supervised Learning](#Supervised-Learning)\n", "1. [Unsupervised Learning](#Unsupervised-Learning)\n", "1. [Reinforcement Learning](#Reinforcement-Learning)\n", "1. [Deep Learning](#Deep-Learning)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Artificial Intelligence" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AI is making computers behave intelligently. Computers, who are not capable of intelligent behavior on their own, are made to simulate intelligent behavior using some algorithm." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Behind all AI robots/computers, there is an algorithm that makes it look that way." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AI is a broad field that encompasses all such algorithms, inclusing hard-coded rules to simulate intelligence." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Computer science defines AI research as the study of **intelligent agents**: any device that perceives its environment and takes actions that maximize its chance of successfully achieving its goals." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AI does not mean another human with a computer as their brain. Current AI models are task-specific or domain-specific." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**The traditional problems (or goals) of AI research include:**\n", "- Knowledge representation.\n", "- Reasoning.\n", "- Planning.\n", "- Machine learning.\n", "- Natural language processing.\n", "- Computer Vision.\n", "- Artificial General Intelligence." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Knowledge Representation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is abput representing knowledge in a way that a computer can do something about it. Complex problems like conversing in Natural language need to be able to represent natural language in a way that a computer can understand and possibly be able to generate, so that it can be converted back into language." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The language barrier is the best way to understand the need for knowledge representation. Just like we need a translator to help us in a foreign country, in order to be able to communicate, machines and humans need a translator too. Designing the translator is the primary goal of this subfield." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Knowledge Representation](https://www.tutorialride.com/images/artificial-intelligence/inheretance-knowledge-representation.jpeg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above figure is an example of being able to represent the knowledge we have in a for that a computer can use. We use the concept of inheritance, classes, objects and attributes to model the world of IPL Cricketers." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Reasoning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is all about enabling computers to reason, use facts and knowledge to reason. An example would be automated theorem proving." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Automated Reasoning](https://res.infoq.com/presentations/cryptography-reasoning/en/slides/sl13.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Planning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Planning refers to realization of strategies or a sequence of actions. For instance, an unmanned vehicle needs to plan it's movement so that it can perform it's job.\n", "\n", "The need for planning is in cases like chess, where an action we take is irreversible. Thus, we need to plan ahead." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Natural Language Processing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The art of processing natural language is key to human-computer conversation. When we look at AI, we see the need for computers to understand language. There are various methods of trying to process and understand natural language, all of these come under the broad domain of NLP." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![NLP](https://miro.medium.com/max/1036/1*z_EFTnhzxA3FJROcjOqNXg.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Computer Vision" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Just like computers need to understand language, computers should also be able to see. Given pictures, being able to infer and process that data is a crucial step in AI." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![CV](https://www.nvidia.com/content/dam/en-zz/Solutions/research/research-home-areas-computer-vision-407-ud@2X.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Artificial General Intelligence" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AGI is different area of research because most algorithms are task specific. AGI deals with creating one algorithm that can be applied to all domains. It is about being able to behave exactly like a human. The AI that all science fiction portrays is AGI. It is a far dream that is extremely tough to achieve, so a robot apocalype won't come in our lifetime." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Approaches:**\n", "- Symbolic : Symbolic representations of problems, logic, search.\n", "- Connectionist : Models the brain functions (Neural Networks)\n", "- Evolutionary : Genetic algorithms that model the human genes (survival of the fittest)\n", "- Bayesian : Modelling uncertainity using probability and Bayes Theorem." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Symbolic" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This has to deal with representing knowledge symbolically and is based on manipulation of symbols. The most prominent example of Symbolic AI is Expert Systems, which use production rules. The expert system processes the rules to make deductions and to determine what additional information it needs, i.e. what questions to ask, using human-readable symbols." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Symbolic AI was intended to produce general, human-like intelligence in a machine, whereas most modern research is directed at specific sub-problems. Research into general intelligence is now studied in the sub-field of artificial general intelligence. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Symbolic AI](https://image.slidesharecdn.com/lnn-140709055654-phpapp01/95/cognitive-vision-after-the-hype-21-638.jpg?cb=1404886613)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Connectionist" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These try to replicate the function of the human brain, using the neuron as the basic unit of computation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Connectionist AI](https://image.slidesharecdn.com/introductionofa-151209075829-lva1-app6891/95/introduction-to-ai-19-638.jpg?cb=1449652757)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Evolutionary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These model biological evolution (survival of the fittest). Concepts like mutation, reproduction and recombination and selection are modelled." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Evolutionary AI](https://image.slidesharecdn.com/introductiontogeneticalgorithms-131007181934-phpapp01/95/introduction-to-genetic-algorithms-22-638.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Bayesian" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A group of scientists, called Bayesians, perceived that uncertainty was the key aspect to keep an eye on and that learning wasn’t assured but rather took place as a continuous updating of previous beliefs that grew more and more accurate.\n", "\n", "This perception led the Bayesians to adopt statistical methods and, in particular, derivations from Bayes’ theorem, which helps you calculate probabilities under specific conditions (for instance, seeing a card of a certain seed, the starting value for a pseudo-random sequence, drawn from a deck after three other cards of same seed)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Bayesian AI](https://i.stack.imgur.com/nHnqk.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### The ultimate goal of artificial intelligence is to combine the technologies and strategies to create a single algorithm (the master algorithm) that can learn anything. That is AGI." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Machine Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Machine Learning is a subfield of AI. Here, we try to make the machine learn by itself. Naturally, there is an algorithm involved, but here, instead of telling the computer what to look for, you tell it how to learn.\n", "\n", "There are no hard-coded rules. We do not use the computer just to speed up something we do, or to memorize a bunch of rules that we cannot. Instead, the machine simulates \"learning\" on the given \"data\".\n", "\n", "We mathematically model the problem and use the computer to perform calculations on the data, so as to arrive at the optimal solution to that problem.\n", "\n", "Machine learning can be summarized as learning a function (f) that maps input variables (X) to output variables (Y).\n", "$$y = f(x)$$\n", "\n", "One aspect that separates machine learning from the knowledge graphs and expert systems is its ability to modify itself when exposed to more data; i.e. machine learning is dynamic and does not require human intervention to make certain changes.\n", "\n", "Generally, there are 2 types of algorithms:\n", "- Parametric : Those algorithms that make an assumption about the learning process, they assume that f follows a standard form. These have a finite number of parameters.\n", "- Non-Parametric : Those algorithms that do not make an assumption about f. Non-parametric methods seek to best fit the training data in constructing the mapping function, whilst maintaining some ability to generalize to unseen data. As such, they are able to fit a large number of functional forms." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> 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." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider Online Shopping: The computer program will learn and recommend items for purchase based on your shopping history and searches and shopping history of other customers — this is termed as experience E and online shopping is Task T. Performance P is a measure of how well the site displays the right items or products you may be interested in." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Machine-learning programs, in a sense, adjust themselves in response to the data they’re exposed to (like a child that is born knowing nothing adjusts its understanding of the world in response to experience)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The “learning” part of machine learning means that ML algorithms attempt to optimize along a certain dimension; i.e. they usually try to minimize error or maximize the likelihood of their predictions being true. This has three names: an error function, a loss function, or an objective function, because the algorithm has an objective…\n", "\n", "When someone says they are working with a machine-learning algorithm, you can get to the gist of its value by asking: What’s the objective function?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![ML](https://2s7gjr373w3x22jf92z99mgm5w-wpengine.netdna-ssl.com/wp-content/uploads/2018/09/WD_3.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In ML, we have task specific algorithms. They are \"trained\" on some data, that is to say we define the loss function and try to minimize that loss. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The data you provide to the algorithm so that it can learn what to do, is called the 'training data'.\n", "\n", "The data on which the algorithm is tested, where we check it's performance is called the 'test data'.\n", "\n", "Generally, we would want the training and test data to be different. Why?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is so that we do not 'cheat' the system. You have trained the model on the training data. The real test for the model is to be tested on unseen data. So if it has chosen the wrong things to look at and base it's decision upon, we will know." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are 3 major types of Machine Learning:\n", "- Supervised Learning\n", "- Unsupervised Learning\n", "- Reinforcement Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Supervised Machine Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When we know what we want to predict and have the target variable (output) for each input available, we use Supervised Learning. \n", "\n", "Supervised means we guide the algorithm to get the right behavior. The algorithm predicts, we give it explicit feedback as to how wrong it's prediction is, and it adjusts itself(Machine Learning!) to try to get it right the next time while also not affecting all other examples it has seen." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Most Machine Learning that you have seen comes under Supervised Learning.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are generally 2 types of tasks:\n", "- Regression: Where we predict a continuous valued number, like the price of a house.\n", "- Classification: Where we try to classify the data into 1 of many predefined classes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![Supervised Ml](https://cdn.datafloq.com/cms/2018/01/23/supervised-learning.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://s3-ap-south-1.amazonaws.com/av-blog-media/wp-content/uploads/2017/09/20182516/dataiku-hadoop-summit-semisupervised-learning-with-hadoop-for-understanding-user-web-behaviours-12-638.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Steps:\n", "\n", "- Determine the type of training examples.\n", "- Gather a training set. The training set needs to be representative of the real-world use of the function. Thus, a set of input objects is gathered and corresponding outputs are also gathered, either from human experts or from measurements.\n", "- Determine a corresponding learning algorithm. For example, the engineer may choose to use support vector machines or decision trees.\n", "- Complete the design. Run the learning algorithm on the gathered training set. Some supervised learning algorithms require the user to determine certain control parameters. These parameters may be adjusted by optimizing performance on a subset (called a validation set) of the training set, or via cross-validation.\n", "- Evaluate the accuracy of the learned function. After parameter adjustment and learning, the performance of the resulting function should be measured on a test set that is separate from the training set." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Train Set, Test Set and Validation Set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Most Machine Learning algorithms have some parameters that we have to manually provide. These parameters are not adjusted by the algorithm itself, but they affect the function we are trying to predict. Hence, we need to also at times choose these parameters wisely.\n", "\n", "In most literature, these parameters are called **hyperparameters.**\n", "\n", "The model's choice of normal parameters will depend on the training set. To check if we are really doing well, we use the test set. Now, this is also affeccted by the hyperparameters! Hence, we will choose those hyperparameters that perform best on the test set. But, this can lead to false ideas of how the algorithm may actually perform! Hence, we create another set called the **validation set.** This will tell us how well our model will perform in the real world." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Overfitting and Underfitting" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When the training set performance is much better than the test set performance, we call this overfitting." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When the training set and test set performance are lesser than our expectations, we call this underfitting." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://cdn-images-1.medium.com/max/1600/1*SBUK2QEfCP-zvJmKm14wGQ.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://cdn-images-1.medium.com/max/1200/1*cdvfzvpkJkUudDEryFtCnA.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Examples of Supervised ML algorithms:\n", "- K Nearest Neighbours\n", "- Linear Reggression\n", "- Logistic Regression\n", "- Suppport Vector Machines\n", "- Decision Trees" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### K Nearest Neighbours" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This algorithm is the simplest ML algorithm. Here, we compute similarity between a given example and all examples we have seen in the training set, and based on the labels of the 'k' closest training examples, we decide the label of the given example." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![KNN](https://cdn-images-1.medium.com/max/1600/0*Sk18h9op6uK9EpT8.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is used to classify the data. It is a non-parametric algorithm." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Linear Regression" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we assume a stright line as the form of our function *f*. \n", "$$ y = \\beta_{0} + \\beta_{1} \\mathrm{X}_{1} + \\beta_{2} \\mathrm{X}_{2} + ...$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use the traning data to determine the appropriate values of the parameters $$\\beta_{0}, \\beta_{1}, \\beta_{2}...$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![LR](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Linear_regression.svg/1200px-Linear_regression.svg.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a regression algorithm. It is parametric." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Logistic Regression" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Earlier, we were predicting a value using a line. Here, we try to draw a line separating the 2 classes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$ y = sigmoid(\\beta_{0} + \\beta_{1} \\mathrm{X}_{1} + \\beta_{2} \\mathrm{X}_{2} + ...)$$\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$sigmoid(x) = \\frac{1}{1 + e^{-x}}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![LR](https://res.cloudinary.com/dyd911kmh/image/upload/f_auto,q_auto:best/v1534281070/linear_vs_logistic_regression_edxw03.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We define a threshold (usually 0.5) to separate the 2 classes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![LR2](https://camo.githubusercontent.com/f663cd4f29335972950dded4d422c07aeee8af55/68747470733a2f2f63646e2d696d616765732d312e6d656469756d2e636f6d2f6d61782f313630302f312a34473067737539327250684e2d636f397076315035414032782e706e67)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a classfier. It is parametric." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Decision Tree" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we create a tree based on the values of certain attributes. These attributes and their values are determined by the algorithm." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![DT](https://www.xoriant.com/blog/wp-content/uploads/2017/08/Decision-Trees-modified-1.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a non-parametric algorithm. It is a classifier." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also use this for regression tasks, by allowing the leaf nodes to have different values. But, the decision tree will predict only a finite number of values. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Performance Metrics" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We have to use a performance metric to judge the performace of the algorithm. Let us go over a few of these:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Regression" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Mean Absoute Error**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the mean of the absolute value of the error for each prediction." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Mean Squared Error**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the mean of the squared error for each prediction." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$ e_{t} = \\hat{y}_{t} - y_{t}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://i.stack.imgur.com/83BUy.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Classification" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Confusion Matrix: Used for classification problems.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://scikit-learn.org/stable/_images/sphx_glr_plot_confusion_matrix_002.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](http://rasbt.github.io/mlxtend/user_guide/evaluate/confusion_matrix_files/confusion_matrix_1.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "True Positive: Positive is correctly predicted as positive.\n", "\n", "True Negative: Negative is correctly predicted as negative.\n", "\n", "False Positive: Negative is predicted as positive.\n", "\n", "False Negative: Positive is predicted as negative." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Accuracy**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is the percentage of correctly predicted items out of the total number of items." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Precision**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Out of the total number of positives, what was the number of predicted positives?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- **Recall**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Out of the total number of predicted positives, what was the actual number of positives?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://3.bp.blogspot.com/--jLXutUe5Ss/VvPIO6ZH2tI/AAAAAAAACkU/pvVL4L-a70gnFEURcfBbL_R-GnhBR6f1Q/s1600/ConfusionMatrix.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Unsupervised Machine Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we do not provide the output labels. This focuses on pattern detection in data. All we have are input data from which we need to extract some valuable insights." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The 2 types of these algorithms are clustering and association." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "- Clustering : K-Means to dicover clusters of data\n", "- Association : Apriori algorithm to fins association between data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The goal for unsupervised learning is to model the underlying structure or distribution in the data in order to learn more about the data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://www.iotforall.com/wp-content/uploads/2018/01/Screen-Shot-2018-01-17-at-8.10.14-PM.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://vitalflux.com/wp-content/uploads/2018/02/Screen-Shot-2018-02-04-at-8.09.33-PM.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reinforcement Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a fundamentally different area of ML. Here, we try to model the world and achieve a particular objective, by receiving feedback from our modelled world about our choice of actions." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reinforcement learning refers to goal-oriented algorithms, which learn how to attain a complex objective (goal) or maximize along a particular dimension over many steps; for example, maximize the points won in a game over many moves. They can start from a blank slate, and under the right conditions they achieve superhuman performance. Like a child incentivized by spankings and candy, these algorithms are penalized when they make the wrong decisions and rewarded when they make the right ones – this is reinforcement." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reinforcement learning can be understood using the following concepts:\n", "- Agents : The person/robot we are modelling. This is the object that learns how to behave to achieve its goal.\n", "- Environments : The model of the world which is relevant to the given task.\n", "- States : The positions that the agent can find itself in, inn the environment.\n", "- Actions : The moves available to the agent to affect it's current state.\n", "- Rewards : The feedback from the environment to the agent." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For example, in the case of a self-driving car,\n", "- The agent is the car.\n", "- The environment is the model of the world it is going to drive in.\n", "- The states are the situations that the car can be in. This could be considered to be it's internal state, i.e. it's speed, direction, state of the car, etc.\n", "- The actions are the things that the car can do, like change the steering direction, accelerating, breaking, etc.\n", "- The rewards have to be defined by the programmer. Here, we could consider rewards like not getting in an accident, driving safely, and other things." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![RL](https://i1.wp.com/enhancedatascience.com/wp-content/uploads/2017/07/reinforcementLearning.png?fit=437%2C450)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://www.kdnuggets.com/images/reinforcement-learning-fig1-700.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, as all Machine Learning, we mathematically model this scenario, and develop models to help us figure out the optimal policy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we can simulate the environment, and thus have the agent learn the optimal policy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Deep Learning" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Deep Learning is a subfield of Machine Learning. It is to do with Neural Networks, algorithms that are inspired by the human brain. \n", "\n", "Deep learning is all artificial neural networks which have more than 1 hidden layer." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Artificial Neural Network" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://icdn5.digitaltrends.com/image/artificial_neural_network_1-791x388.jpg)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://cdn-images-1.medium.com/max/1600/1*0UxcK0BoePVAeIdzeqEhzQ.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Thus, each neuron takes in certain inputs, mutiplies them by certain weights, sums them up and applies a non-linear function to the result." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An ANN has a lot of these neurons, and each neuron in one layer is connected to each neuron of the following layer. Within a layer, all neurons are not connected to each other." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://3qeqpr26caki16dnhd19sv6by6v-wpengine.netdna-ssl.com/wp-content/uploads/2016/08/Why-Deep-Learning-1024x742.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Deep Learning methods perform better with more and more training data. They are also compute intensive." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "![](https://cdn-images-1.medium.com/max/1200/1*TiORvHgrJPme_lEiX3olVA.png)" ] } ], "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.5" } }, "nbformat": 4, "nbformat_minor": 2 }