<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://machinelearning.subwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Vipul</id>
	<title>Machinelearning - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://machinelearning.subwiki.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Vipul"/>
	<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/wiki/Special:Contributions/Vipul"/>
	<updated>2026-04-19T04:12:31Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.2</generator>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3619</id>
		<title>MediaWiki:Sitenotice</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3619"/>
		<updated>2024-10-06T17:46:27Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Want site search autocompletion? See [[Project:Enabling site search autocompletion|here]]&amp;lt;br/&amp;gt;&lt;br /&gt;
Encountering 429 Too Many Requests errors when browsing the site? See [[Project:429 Too Many Requests error|here]]&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3618</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3618"/>
		<updated>2024-10-06T17:45:53Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* &amp;lt;math&amp;gt;(7 + 2)^\sqrt{9} = 729&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;5^{1 + 2} = 125&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;6^{2 + 1} = 216&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;(3 + 4)^3 = 343&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;(4/2)^{10} = 1024&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3617</id>
		<title>MediaWiki:Sitenotice</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3617"/>
		<updated>2024-09-30T01:20:22Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This site is in the process of being migrated to a new server. Edits made until this notice has been removed may be lost.&#039;&#039;&#039;&amp;lt;br/&amp;gt;&lt;br /&gt;
Want site search autocompletion? See [[Project:Enabling site search autocompletion|here]]&amp;lt;br/&amp;gt;&lt;br /&gt;
Encountering 429 Too Many Requests errors when browsing the site? See [[Project:429 Too Many Requests error|here]]&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3616</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3616"/>
		<updated>2024-09-06T00:35:53Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* &amp;lt;math&amp;gt;(7 + 2)^\sqrt{9} = 729&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;5^{1 + 2} = 125&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;6^{2 + 1} = 216&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;(3 + 4)^3 = 343&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3615</id>
		<title>MediaWiki:Sitenotice</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3615"/>
		<updated>2024-09-06T00:31:25Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Want site search autocompletion? See [[Project:Enabling site search autocompletion|here]]&amp;lt;br/&amp;gt;&lt;br /&gt;
Encountering 429 Too Many Requests errors when browsing the site? See [[Project:429 Too Many Requests error|here]]&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Machinelearning:Enabling_site_search_autocompletion&amp;diff=3614</id>
		<title>Machinelearning:Enabling site search autocompletion</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Machinelearning:Enabling_site_search_autocompletion&amp;diff=3614"/>
		<updated>2024-09-06T00:30:42Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;Content copied from Ref:Ref:Enabling site search autocompletion. Images used are specific to this site (Machinelearning).  Site search autocompletion is currently broken by default on this site. This page includes details on how to get it to work, and what&amp;#039;s going on.  ==What&amp;#039;s wrong with site search autocompletion and how to fix it==  ===What&amp;#039;s wrong===  When you start typing something in the site search bar, you&amp;#039;ll see it stuck at &amp;quot;Loading search suggestions&amp;quot; as sh...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Content copied from [[Ref:Ref:Enabling site search autocompletion]]. Images used are specific to this site (Machinelearning).&lt;br /&gt;
&lt;br /&gt;
Site search autocompletion is currently broken by default on this site. This page includes details on how to get it to work, and what&#039;s going on.&lt;br /&gt;
&lt;br /&gt;
==What&#039;s wrong with site search autocompletion and how to fix it==&lt;br /&gt;
&lt;br /&gt;
===What&#039;s wrong===&lt;br /&gt;
&lt;br /&gt;
When you start typing something in the site search bar, you&#039;ll see it stuck at &amp;quot;Loading search suggestions&amp;quot; as shown in the screenshot below:&lt;br /&gt;
&lt;br /&gt;
[[File:Site search autocompletion broken.png]]&lt;br /&gt;
&lt;br /&gt;
Note that the actual search is still working -- you just have to hit Enter after typing the search query and it&#039;ll go to the search results page. It&#039;s the autocompletion before you hit Enter that is broken.&lt;br /&gt;
&lt;br /&gt;
===How to fix it===&lt;br /&gt;
&lt;br /&gt;
To fix it, you need to follow these steps:&lt;br /&gt;
&lt;br /&gt;
* Write to vipulnaik1@gmail.com asking for a login to the site. Please include the following with your request: preferred username, preferred initial password (you can change it after logging in), real name (if you want it entered), email address to use (if you want an actual email address by which you can be contacted), and whether you want edit access as well. You don&#039;t need edit access for enabling site search autocompletion.&lt;br /&gt;
* Log in to the site. Then go to [[Special:Preferences]]. Go to the Appearance section and switch the Skin from &amp;quot;Vector (2022)&amp;quot; to &amp;quot;Vector legacy (2010)&amp;quot;.&lt;br /&gt;
* Make sure to hit &amp;quot;Save&amp;quot; at the bottom.&lt;br /&gt;
* Now you can reload the page or load a new page.&lt;br /&gt;
&lt;br /&gt;
Site search autocompletion should now work. Here&#039;s an example:&lt;br /&gt;
&lt;br /&gt;
[[File:Site search autocompletion working.png]]&lt;br /&gt;
&lt;br /&gt;
==More background==&lt;br /&gt;
&lt;br /&gt;
We&#039;ve recently upgraded the MediaWiki version of this wiki from 1.35.13 to 1.41.2 (see [[Special:Version]]). The upgrade allows us to migrate the wiki to a more modern operating system version running PHP 8. With the current setup for MediaWiki 1.41.2, we&#039;re in this situation:&lt;br /&gt;
&lt;br /&gt;
* The &amp;quot;Vector legacy (2010)&amp;quot; skin has site search autocompletion working, but it doesn&#039;t render well on small screens. Specifically, even on small mobile screens, it still shows the left menu, and doesn&#039;t properly use the MobileFrontend extension settings.&lt;br /&gt;
* The &amp;quot;Vector (2022)&amp;quot; skin doesn&#039;t have site search autocompletion working (see screenshots in preceding section) but it does render fine on mobile devices.&lt;br /&gt;
&lt;br /&gt;
It is possible to set only one default skin (that is applicable to all non-logged-in users and is the default for logged-in users who have not configured a skin for themselves). So, the selection of default skin comes down to whether it&#039;s more important for casual users to have the mobile experience working or to have site search autocompletion working. Based on a general understanding of user behavior, we believe that having a usable mobile experience is more important for casual users than having site search autocompletion.&lt;br /&gt;
&lt;br /&gt;
However, for power users who are using the site extensively, site search autocompletion may be important. That&#039;s why we&#039;ve written this page giving guidance on how to set up site search autocompletion.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=File:Site_search_autocompletion_working.png&amp;diff=3613</id>
		<title>File:Site search autocompletion working.png</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=File:Site_search_autocompletion_working.png&amp;diff=3613"/>
		<updated>2024-09-06T00:30:33Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=File:Site_search_autocompletion_broken.png&amp;diff=3612</id>
		<title>File:Site search autocompletion broken.png</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=File:Site_search_autocompletion_broken.png&amp;diff=3612"/>
		<updated>2024-09-06T00:30:12Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Machinelearning:429_Too_Many_Requests_error&amp;diff=3611</id>
		<title>Machinelearning:429 Too Many Requests error</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Machinelearning:429_Too_Many_Requests_error&amp;diff=3611"/>
		<updated>2024-09-06T00:27:24Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;This content is copied from Ref:Ref:429 Too Many Requests error.  If you get a 429 Too Many Requests error when browsing this site, read on.  You&amp;#039;re probably seeing this error because a large number of requests have been made from your IP address over a short period of time. That&amp;#039;s probably a lot of requests from you or others who share your IP address (such as your home wi-fi network). Waiting a minute and then retrying should generally work.  If you are an actual h...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This content is copied from [[Ref:Ref:429 Too Many Requests error]].&lt;br /&gt;
&lt;br /&gt;
If you get a 429 Too Many Requests error when browsing this site, read on.&lt;br /&gt;
&lt;br /&gt;
You&#039;re probably seeing this error because a large number of requests have been made from your IP address over a short period of time. That&#039;s probably a lot of requests from you or others who share your IP address (such as your home wi-fi network). Waiting a minute and then retrying should generally work.&lt;br /&gt;
&lt;br /&gt;
If you are an actual human being with a legitimate reason to be browsing the site heavily, first, thank you and sorry about this! We set rate limits to prevent bots, spiders, spammers, and malicious actors from consuming too much of our server&#039;s resources so that our server&#039;s resources can be devoted to real humans like you. Consider writing to vipulnaik1@gmail.com with your IP address to have the IP address whitelisted. You can get your IP address by [https://www.google.com/search?q=my+ip+address Googling &amp;quot;my IP address&amp;quot;] (scroll down a little bit to where Google includes the IP address in a box). NOTE: If you have both an IPv4 address and an IPv6 address, you should send both; the server supports both IPv4 and IPv6, so either may end up getting used. To check if you have an IPv6 address, try visiting [https://ipv6.google.com/ ipv6.google.com].&lt;br /&gt;
&lt;br /&gt;
If your IP address changes, or you are away from your home network, then you&#039;ll get rate-limited again. So if you find yourself getting rate-limited after already having been whitelisted, check if you are on a different IP address than the one for which you requested whitelisting.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3610</id>
		<title>MediaWiki:Sitenotice</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3610"/>
		<updated>2024-09-06T00:25:50Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3609</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3609"/>
		<updated>2024-09-06T00:24:04Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* &amp;lt;math&amp;gt;(7 + 2)^\sqrt{9} = 729&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;5^{1 + 2} = 125&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;6^{2 + 1} = 216&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3608</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3608"/>
		<updated>2024-09-06T00:20:10Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* &amp;lt;math&amp;gt;(7 + 2)^\sqrt{9} = 729&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;5^{1 + 2} = 125&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3605</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3605"/>
		<updated>2024-09-06T00:12:52Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* &amp;lt;math&amp;gt;(7 + 2)^\sqrt{9} = 729&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3604</id>
		<title>MediaWiki:Sitenotice</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=MediaWiki:Sitenotice&amp;diff=3604"/>
		<updated>2024-09-05T23:59:58Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;This wiki is in the process of being upgraded. The site may go down intermittently. Please try to avoid editing until this notice has been removed.&amp;#039;&amp;#039;&amp;#039;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This wiki is in the process of being upgraded. The site may go down intermittently. Please try to avoid editing until this notice has been removed.&#039;&#039;&#039;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3603</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3603"/>
		<updated>2024-07-06T04:52:14Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;math&amp;gt;e^{\pi^3 + \sqrt{3} + \sqrt[4]{6 - \sqrt{3}}}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3598</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=3598"/>
		<updated>2024-05-05T20:03:57Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;math&amp;gt;e^{\pi^3 + \sqrt{3} + \sqrt[4]{6}}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3302</id>
		<title>Artificial neural network</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3302"/>
		<updated>2021-06-12T03:00:03Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Topology of the neural network */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neural network&#039;&#039;&#039; is a collection of nodes, each of which is an [[artificial neuron]], as well as directed edges between the nodes, called connections, each of which has a weight. &lt;br /&gt;
&lt;br /&gt;
The output of each artificial neuron flows out from it on each of the connections &#039;&#039;from&#039;&#039; that node and become an input to the node the connection goes &#039;&#039;to&#039;&#039;. The weight applied to that input is the weight on the connection. Each node also has an associated bias term that is the weight applied to the input 1 (not corresponding to any connection).&lt;br /&gt;
&lt;br /&gt;
Nodes that have no connections going to them represent the inputs to the neural network; these correspond to the inputs or features for the problem being modeled through the neural network. Nodes that have no connections going out from them represent the outputs of the neural network, these correspond to the labels we are trying to predict.&lt;br /&gt;
&lt;br /&gt;
==Things to decide in a neural network==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say we want to design a neural network with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; inputs and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; outputs being predicted. There are a few main things to decide about the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Activation function of the neural network ===&lt;br /&gt;
&lt;br /&gt;
We need to select the activation function that will be used for the artificial neurons. In principle, a different activation function could be used for each neuron; in practice neural networks choose a single activation function across all neurons.&lt;br /&gt;
&lt;br /&gt;
=== Topology of the neural network ===&lt;br /&gt;
&lt;br /&gt;
The topology of the neural network is the diagram of the nodes and their connections -- but without information on the weights and the activation function used. This topology might include connections for which we ultimately decide to set a weight of zero (and that we can therefore remove).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of network !! Description of topology !! Implications for learning&lt;br /&gt;
|-&lt;br /&gt;
| Single-layer neural network (no hidden layers)|| There are no nodes other than the input and output nodes. The input nodes feed directly into the output nodes. || This basically involves just doing machine learning on the activation function. For instance, if the activation function is a logistic function, it means running a [[logistic regression]] separately on each of the outputs.&lt;br /&gt;
|-&lt;br /&gt;
| Single-hidden-layer (feedforward) neural network || There is no direct connection between input and output nodes. There is a single hidden layer of neurons; all connections are either from inputs to the hidden layer or from the hidden layer to the outputs. In the &amp;quot;fully connected&amp;quot; version, &#039;&#039;all&#039;&#039; the permitted connections exist. || Backpropagation becomes serious business here.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Information about the problem domain may go into the design of the topology of the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Weights of the neural network (including bias terms) ===&lt;br /&gt;
&lt;br /&gt;
The weights of the neural network (including weights on connections as well as bias terms) are the most detailed and specific part of the description of the neural network. &lt;br /&gt;
&lt;br /&gt;
These weights are generally learned by running a gradient descent / backpropagation algorithm on training data.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3301</id>
		<title>Artificial neural network</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3301"/>
		<updated>2021-06-12T02:59:45Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Things to decide in a neural network */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neural network&#039;&#039;&#039; is a collection of nodes, each of which is an [[artificial neuron]], as well as directed edges between the nodes, called connections, each of which has a weight. &lt;br /&gt;
&lt;br /&gt;
The output of each artificial neuron flows out from it on each of the connections &#039;&#039;from&#039;&#039; that node and become an input to the node the connection goes &#039;&#039;to&#039;&#039;. The weight applied to that input is the weight on the connection. Each node also has an associated bias term that is the weight applied to the input 1 (not corresponding to any connection).&lt;br /&gt;
&lt;br /&gt;
Nodes that have no connections going to them represent the inputs to the neural network; these correspond to the inputs or features for the problem being modeled through the neural network. Nodes that have no connections going out from them represent the outputs of the neural network, these correspond to the labels we are trying to predict.&lt;br /&gt;
&lt;br /&gt;
==Things to decide in a neural network==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say we want to design a neural network with &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; inputs and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; outputs being predicted. There are a few main things to decide about the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Activation function of the neural network ===&lt;br /&gt;
&lt;br /&gt;
We need to select the activation function that will be used for the artificial neurons. In principle, a different activation function could be used for each neuron; in practice neural networks choose a single activation function across all neurons.&lt;br /&gt;
&lt;br /&gt;
=== Topology of the neural network ===&lt;br /&gt;
&lt;br /&gt;
The topology of the neural network is the diagram of the nodes and their connections -- but without information on the weights and the activation function used. This topology might include connections for which we ultimately decide to set a weight of zero (and that we can therefore remove).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of network !! Description of topology !! Implications for learning&lt;br /&gt;
|-&lt;br /&gt;
| Single-layer neural network (no hidden layers)|| There are no nodes other than the input and output nodes. The input nodes feed directly into the output nodes. || This basically involves just doing machine learning on the activation function. For instance, if the activation function is a logistic function, it means running a [[logistic regression]] separately on each of the outputs.&lt;br /&gt;
|-&lt;br /&gt;
| Single-hidden-layer (feedforward) neural network || There is no direct connection between input and output nodes. There is a single hidden layer of neurons; all connections are either from inputs to the hidden layer or from the hidden layer to the outputs. In the &amp;quot;fully connected&amp;quot; version, &#039;&#039;all&#039;&#039; the permitted connections exist.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Information about the problem domain may go into the design of the topology of the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Weights of the neural network (including bias terms) ===&lt;br /&gt;
&lt;br /&gt;
The weights of the neural network (including weights on connections as well as bias terms) are the most detailed and specific part of the description of the neural network. &lt;br /&gt;
&lt;br /&gt;
These weights are generally learned by running a gradient descent / backpropagation algorithm on training data.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3300</id>
		<title>Artificial neural network</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neural_network&amp;diff=3300"/>
		<updated>2021-06-12T02:59:34Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;==Definition==  An &amp;#039;&amp;#039;&amp;#039;artificial neural network&amp;#039;&amp;#039;&amp;#039; is a collection of nodes, each of which is an artificial neuron, as well as directed edges between the nodes, called con...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neural network&#039;&#039;&#039; is a collection of nodes, each of which is an [[artificial neuron]], as well as directed edges between the nodes, called connections, each of which has a weight. &lt;br /&gt;
&lt;br /&gt;
The output of each artificial neuron flows out from it on each of the connections &#039;&#039;from&#039;&#039; that node and become an input to the node the connection goes &#039;&#039;to&#039;&#039;. The weight applied to that input is the weight on the connection. Each node also has an associated bias term that is the weight applied to the input 1 (not corresponding to any connection).&lt;br /&gt;
&lt;br /&gt;
Nodes that have no connections going to them represent the inputs to the neural network; these correspond to the inputs or features for the problem being modeled through the neural network. Nodes that have no connections going out from them represent the outputs of the neural network, these correspond to the labels we are trying to predict.&lt;br /&gt;
&lt;br /&gt;
==Things to decide in a neural network==&lt;br /&gt;
&lt;br /&gt;
Let&#039;s say we want to design a neural network with &amp;lt;math&amp;gt;m&amp;lt;math&amp;gt; inputs and &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; outputs being predicted. There are a few main things to decide about the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Activation function of the neural network ===&lt;br /&gt;
&lt;br /&gt;
We need to select the activation function that will be used for the artificial neurons. In principle, a different activation function could be used for each neuron; in practice neural networks choose a single activation function across all neurons.&lt;br /&gt;
&lt;br /&gt;
=== Topology of the neural network ===&lt;br /&gt;
&lt;br /&gt;
The topology of the neural network is the diagram of the nodes and their connections -- but without information on the weights and the activation function used. This topology might include connections for which we ultimately decide to set a weight of zero (and that we can therefore remove).&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of network !! Description of topology !! Implications for learning&lt;br /&gt;
|-&lt;br /&gt;
| Single-layer neural network (no hidden layers)|| There are no nodes other than the input and output nodes. The input nodes feed directly into the output nodes. || This basically involves just doing machine learning on the activation function. For instance, if the activation function is a logistic function, it means running a [[logistic regression]] separately on each of the outputs.&lt;br /&gt;
|-&lt;br /&gt;
| Single-hidden-layer (feedforward) neural network || There is no direct connection between input and output nodes. There is a single hidden layer of neurons; all connections are either from inputs to the hidden layer or from the hidden layer to the outputs. In the &amp;quot;fully connected&amp;quot; version, &#039;&#039;all&#039;&#039; the permitted connections exist.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Information about the problem domain may go into the design of the topology of the neural network.&lt;br /&gt;
&lt;br /&gt;
=== Weights of the neural network (including bias terms) ===&lt;br /&gt;
&lt;br /&gt;
The weights of the neural network (including weights on connections as well as bias terms) are the most detailed and specific part of the description of the neural network. &lt;br /&gt;
&lt;br /&gt;
These weights are generally learned by running a gradient descent / backpropagation algorithm on training data.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3299</id>
		<title>Artificial neuron</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3299"/>
		<updated>2021-06-12T02:34:02Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Common choices of activation function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neuron&#039;&#039;&#039; is a function of the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;y = \varphi\left(\sum_{j=0}^m w_j x_j\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;w_j&amp;lt;/math&amp;gt; are the weights on the neuron and &amp;lt;math&amp;gt;\varphi&amp;lt;/math&amp;gt; is the activation function. Artificial neurons form components of [[artificial neural network]]s: an artificial neural network is obtained by composing and combining artificial neurons (i.e., using the outputs of some neurons as inputs for other neurons).&lt;br /&gt;
&lt;br /&gt;
Generally, in [[machine learning]] problems, the topology of the artificial neural network, as well as the choice of activation function for each neuron, are fixed in advance. The values of the weights are discovered using the [[training set]] by minimizing an appropriately chosen cost function.&lt;br /&gt;
&lt;br /&gt;
===Bias term===&lt;br /&gt;
&lt;br /&gt;
Generally, the variable &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; is always taken to be &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, and called the &#039;&#039;bias term&#039;&#039;. The weight &amp;lt;math&amp;gt;w_0&amp;lt;/math&amp;gt; is the bias weight.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the weights===&lt;br /&gt;
&lt;br /&gt;
The purpose of the weights is to combine the inputs in a way that extracts some information from all of them.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the activation function===&lt;br /&gt;
&lt;br /&gt;
The purpose of the activation function is to rescale in a manner that extracts the relevant valuable information from the linear combination. In general, the activation function tends to squish the domain down to a smaller subset. The idea is that the goal of the neuron is closer to a classification problem than a problem of finding an exact magnitude, so very large values should get squished down to the same value as intermediate values.&lt;br /&gt;
&lt;br /&gt;
For instance, suppose a self-driving car is trying to determine whether a particular segment of the picture frame represents paved road or a sidewalk. The degree of certainty that the picture is of paved road can be described by a probability that can range from 0 to 1. We may compute this probability using a [[logistic regression]] problem: we combine a lot of different pieces of information about the picture frame to compute a real number describing the log-odds of it being paved road, then apply the logistic function to compute the probability. Here, the logistic function plays the role of the activation function.&lt;br /&gt;
&lt;br /&gt;
For an artificial neural network to have some power beyond a single artificial neuron, we &#039;&#039;must&#039;&#039; have a nonlinear activation function, because composing linear functions just gives us a linear function.&lt;br /&gt;
&lt;br /&gt;
=== Common choices of activation function ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Name of artificial neuron type !! Choice of activation function  !! Mathematical form !! More information&lt;br /&gt;
|-&lt;br /&gt;
| Linear threshold unit or McCulloch-Pitts neuron || Heaviside step function (zero if less than a threshold, one if above the threshold) || for threshold &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;: 0 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j &amp;lt; \theta&amp;lt;/math&amp;gt;, 1 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j &amp;lt; \theta&amp;lt;/math&amp;gt;, 1/2 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j = \theta&amp;lt;/math&amp;gt; || This is not continuous at the threshold &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;; geometrically the region of discontinuity is a hyperplane. Linear threshold units are good for implementing boolean functions.&lt;br /&gt;
|-&lt;br /&gt;
| Logistic neuron || [[calculus:Logistic function|logistic function]] || &amp;lt;math&amp;gt;g\left(\sum_{j=0}^m w_j x_j = \theta \right)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the logistic function &amp;lt;math&amp;gt;g(t) = \frac{1}{1 + e^{-t}}&amp;lt;/math&amp;gt; || An artificial neural network with just one logistic neuron is equivalent to [[logistic regression]]. The continuity and in fact infinite differentiability of the logistic function makes it amenable to gradient descent / backpropagation methods. Artificial neural networks where all neurons are logistic neurons are commonly used in practice.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3298</id>
		<title>Artificial neuron</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3298"/>
		<updated>2021-06-12T02:33:26Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Purpose of the activation function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neuron&#039;&#039;&#039; is a function of the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;y = \varphi\left(\sum_{j=0}^m w_j x_j\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;w_j&amp;lt;/math&amp;gt; are the weights on the neuron and &amp;lt;math&amp;gt;\varphi&amp;lt;/math&amp;gt; is the activation function. Artificial neurons form components of [[artificial neural network]]s: an artificial neural network is obtained by composing and combining artificial neurons (i.e., using the outputs of some neurons as inputs for other neurons).&lt;br /&gt;
&lt;br /&gt;
Generally, in [[machine learning]] problems, the topology of the artificial neural network, as well as the choice of activation function for each neuron, are fixed in advance. The values of the weights are discovered using the [[training set]] by minimizing an appropriately chosen cost function.&lt;br /&gt;
&lt;br /&gt;
===Bias term===&lt;br /&gt;
&lt;br /&gt;
Generally, the variable &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; is always taken to be &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, and called the &#039;&#039;bias term&#039;&#039;. The weight &amp;lt;math&amp;gt;w_0&amp;lt;/math&amp;gt; is the bias weight.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the weights===&lt;br /&gt;
&lt;br /&gt;
The purpose of the weights is to combine the inputs in a way that extracts some information from all of them.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the activation function===&lt;br /&gt;
&lt;br /&gt;
The purpose of the activation function is to rescale in a manner that extracts the relevant valuable information from the linear combination. In general, the activation function tends to squish the domain down to a smaller subset. The idea is that the goal of the neuron is closer to a classification problem than a problem of finding an exact magnitude, so very large values should get squished down to the same value as intermediate values.&lt;br /&gt;
&lt;br /&gt;
For instance, suppose a self-driving car is trying to determine whether a particular segment of the picture frame represents paved road or a sidewalk. The degree of certainty that the picture is of paved road can be described by a probability that can range from 0 to 1. We may compute this probability using a [[logistic regression]] problem: we combine a lot of different pieces of information about the picture frame to compute a real number describing the log-odds of it being paved road, then apply the logistic function to compute the probability. Here, the logistic function plays the role of the activation function.&lt;br /&gt;
&lt;br /&gt;
For an artificial neural network to have some power beyond a single artificial neuron, we &#039;&#039;must&#039;&#039; have a nonlinear activation function, because composing linear functions just gives us a linear function.&lt;br /&gt;
&lt;br /&gt;
=== Common choices of activation function ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Name of artificial neuron type !! Choice of activation function  !! Mathematical form !! More information&lt;br /&gt;
|-&lt;br /&gt;
| Linear threshold unit or McCulloch-Pitts neuron || Heaviside step function (zero if less than a threshold, one if above the threshold) || for threshold &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;: 0 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j &amp;lt; \theta&amp;lt;/math&amp;gt;, 1 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j &amp;lt; \theta&amp;lt;/math&amp;gt;, 1/2 if &amp;lt;math&amp;gt;\sum_{j=0}^m w_j x_j = \theta&amp;lt;/math&amp;gt; || This is not continuous at the threshold &amp;lt;math&amp;gt;\theta&amp;lt;/math&amp;gt;; geometrically the region of discontinuity is a hyperplane. Linear threshold units are good for implementing boolean functions.&lt;br /&gt;
|-&lt;br /&gt;
| Logistic neuron || [[calculus:Logistic function|logistic function]] || &amp;lt;math&amp;gt;g\left(\sum_{j=0}^m w_j x_j = \theta \right)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the logistic function || An artificial neural network with just one logistic neuron is equivalent to [[logistic regression]]. The continuity and in fact infinite differentiability of the logistic function makes it amenable to gradient descent / backpropagation methods. Artificial neural networks where all neurons are logistic neurons are commonly used in practice.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3297</id>
		<title>Artificial neuron</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Artificial_neuron&amp;diff=3297"/>
		<updated>2021-06-12T01:56:51Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
An &#039;&#039;&#039;artificial neuron&#039;&#039;&#039; is a function of the form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;y = \varphi\left(\sum_{j=0}^m w_j x_j\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;w_j&amp;lt;/math&amp;gt; are the weights on the neuron and &amp;lt;math&amp;gt;\varphi&amp;lt;/math&amp;gt; is the activation function. Artificial neurons form components of [[artificial neural network]]s: an artificial neural network is obtained by composing and combining artificial neurons (i.e., using the outputs of some neurons as inputs for other neurons).&lt;br /&gt;
&lt;br /&gt;
Generally, in [[machine learning]] problems, the topology of the artificial neural network, as well as the choice of activation function for each neuron, are fixed in advance. The values of the weights are discovered using the [[training set]] by minimizing an appropriately chosen cost function.&lt;br /&gt;
&lt;br /&gt;
===Bias term===&lt;br /&gt;
&lt;br /&gt;
Generally, the variable &amp;lt;math&amp;gt;x_0&amp;lt;/math&amp;gt; is always taken to be &amp;lt;math&amp;gt;+1&amp;lt;/math&amp;gt;, and called the &#039;&#039;bias term&#039;&#039;. The weight &amp;lt;math&amp;gt;w_0&amp;lt;/math&amp;gt; is the bias weight.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the weights===&lt;br /&gt;
&lt;br /&gt;
The purpose of the weights is to combine the inputs in a way that extracts some information from all of them.&lt;br /&gt;
&lt;br /&gt;
===Purpose of the activation function===&lt;br /&gt;
&lt;br /&gt;
The purpose of the activation function is to rescale in a manner that extracts the relevant valuable information from the linear combination. In general, the activation function tends to squish the domain down to a smaller subset. The idea is that the goal of the neuron is closer to a classification problem than a problem of finding an exact magnitude, so very large values should get squished down to the same value as intermediate values.&lt;br /&gt;
&lt;br /&gt;
For instance, suppose a self-driving car is trying to determine whether a particular segment of the picture frame represents paved road or a sidewalk. The degree of certainty that the picture is of paved road can be described by a probability that can range from 0 to 1. We may compute this probability using a [[logistic regression]] problem: we combine a lot of different pieces of information about the picture frame to compute a real number describing the log-odds of it being paved road, then apply the logistic function to compute the probability. Here, the logistic function plays the role of the activation function.&lt;br /&gt;
&lt;br /&gt;
A few other remarks:&lt;br /&gt;
&lt;br /&gt;
* The logistic function is a fairly common choice of activation function, and the default [[artificial neural network]] architecture uses logistic functions at all artificial neurons, so we can view artificial neural networks as generalizations of [[logistic regression]].&lt;br /&gt;
* Activation functions such as the logistic function, and most others that are typically chosen, have the property that for generally nice inputs, they are likely to simulate some form of almost-binary logic, and the artificial neural network can be viewed as a slight fuzzification of what is essentially a Boolean circuit.&lt;br /&gt;
* For an artificial neural network to have some power beyond a single artificial neuron, we &#039;&#039;must&#039;&#039; have a nonlinear activation function, because composing linear functions just gives us a linear function.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Supervised_learning&amp;diff=3296</id>
		<title>Supervised learning</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Supervised_learning&amp;diff=3296"/>
		<updated>2021-06-12T01:50:47Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Steps of supervised learning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;supervised learning&#039;&#039;&#039; is used to describe a subclass of machine learning problems where we are provided with a set of labeled examples for training and can use that data to determine a function that would take any new example and predict the label for that. There are two types of supervised learning techiques, [[classification]] and [[regression]].&lt;br /&gt;
&lt;br /&gt;
Here, the term &amp;quot;example&amp;quot; refers to the input part of the function (that can be used to make the prediction) and the term &amp;quot;label&amp;quot; refers to the output of the function (that needs to be predicted).&lt;br /&gt;
&lt;br /&gt;
==Steps of supervised learning==&lt;br /&gt;
&lt;br /&gt;
Supervised learning is a process that goes through several steps, which are presented here in a table.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! What gets chosen here !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[Feature selection]] || The set of features that the model depends on. || Based on the problem domain, we come up with a list of relevant features that affect the output function. If we choose too few features, then the task might be theoretically impossible. For instance, if the only feature we have for a house is its area, and we need to predict the price, we cannot do the prediction too well. The more the features, the better our ability to predict in principle. However, too many features means more effort spent collecting their values, and there are also dangers of [[overfitting]].&lt;br /&gt;
|-&lt;br /&gt;
| [[Model class selection]] (not to be confused with [[hyperparameter optimization]]) || The functional form (with [[parameter]]s) describing how the output depends on the features. || This again depends on theoretical knowledge based on the problem domain, as well as empirical exploration of the data gathered.&lt;br /&gt;
|-&lt;br /&gt;
| [[Cost function selection]] || The cost function (or error function) used to measure error on new data. || This again depends on theoretical knowledge based on the problem domain, and also on the choice of model type. Often, the error function selection is bundled with the model class selection, because part of the model class selection process also includes identifying the nature of distribution of errors or anomalies. This has the property that if we choose parameters so that our predicted function matches the actual function precisely, the error is zero. In principle, however, the error function is independent of the model class, so we can essentially combine any permissible model class with any permissible error function.&lt;br /&gt;
|-&lt;br /&gt;
| Regularization-type choices || The choice of regularization function to add to the cost function when using on the training data. Requires choosing [[regularization hyperparameter]](s). ||&lt;br /&gt;
|-&lt;br /&gt;
| [[Learning algorithm]] applied on the training data || The values of the parameters (not uniquely determined, we might get a portfolio of choices for different hyperparameter choices)|| This is the algorithm that tries to solve the optimization function of choosing values of the parameters (for our chosen model) so that the error function is minimized (or close to minimized). Note that we are trying to minimize the error function for unknown inputs, but our algorithm is being trained on known inputs. Thus, there are issues of [[overfitting]]. This problem is addressed through a number of techniques, including [[regularization]] and [[early stopping]].&lt;br /&gt;
|-&lt;br /&gt;
| [[Cross-validation]] (relates to hyperparameter optimization) || The actual values of the hyperparameters and parameters || This includes techniques that tweak the [[hyperparameter]]s that control the performance of the learning algorithm. These could include learning rate parameters for gradient descent, or regularization parameters introduced to avoid overfitting.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Machine_learning&amp;diff=3295</id>
		<title>Machine learning</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Machine_learning&amp;diff=3295"/>
		<updated>2021-06-12T01:49:06Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Classification based on nature of training data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Machine learning&#039;&#039;&#039; can be defined as the problem of using partial data about a function or relation to make predictions about how the function or relation would perform on new data. It is the branch of AI that covers its statistical part.&lt;br /&gt;
&lt;br /&gt;
===The case of learning a function===&lt;br /&gt;
&lt;br /&gt;
Although this particular formulation is not the most natural formulation of all machine learning problems, any machine learning problem can be converted to this formulation.&lt;br /&gt;
&lt;br /&gt;
An output function depends on some inputs (called [[feature]]s) (and possibly a random noise component). We have access to some training data, or thee ability to explore and discover training data, where we may or may not have the value of the output function, and we either already have or can get the values of the features. The machine learning problem asks for an explicit description of a function that would perform well on new inputs that we provide to it.&lt;br /&gt;
&lt;br /&gt;
==Types of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Classification based on nature of training data===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of machine learning !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[supervised learning]] || Explicit training data (input-output pairs) are provided. These can be used to learn the parameters for the functional form that can then be used to make predictions.&lt;br /&gt;
|-&lt;br /&gt;
| [[unsupervised learning]] || The training data as provided includes a list of inputs but does not provide explicit outputs for explicit inputs. For instance, in the context of classification problems, an unsupervised learning problem would simply provide a lot of inputs without specifying the output values for those inputs. The job of the machine learning algorithm is to use the distribution of the inputs to figure out the output values.&lt;br /&gt;
|-&lt;br /&gt;
| [[semi-supervised learning]] || The training data is a mix of explicit input-output pairs and input-only data. Semi-supervised learning combines some of the aspects of supervised learning and unsupervised learning.&lt;br /&gt;
|-&lt;br /&gt;
| [[reinforcement learning]] || Unlike supervised learning, the training data is not chosen by the user; instead, the agent being trained generates the training data by interacting with the environment. In addition, the kind of feedback is different: in supervised learning the feedback is &#039;&#039;instructive&#039;&#039; (i.e. does not depend on the outputs the system selects), but in reinforcement learning the feedback is &#039;&#039;evaluative&#039;&#039; (i.e. depends on the action selected by the agent).&amp;lt;ref&amp;gt;Sutton and Barto. &#039;&#039;Reinforcement Learning: An Introduction&#039;&#039; (2nd ed). p. 25.&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[https://www.coursera.org/learn/fundamentals-of-reinforcement-learning/lecture/PtVBs/sequential-decision-making-with-evaluative-feedback &amp;quot;Sequential Decision Making with Evaluative Feedback&amp;quot;]. Coursera.&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Classification based on nature of prediction===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of prediction problem !! Description&lt;br /&gt;
|-&lt;br /&gt;
| binary classification problem || Here, the output has only two permissible values. Therefore, the prediction problem can be viewed as a yes/no or a true/false prediction problem. Models for binary classification can be probabilistic (such as [[logistic regression]] or [[artificial neural network]]s) or yes/no (such as [[support vector machine]]s). Note that probabilistic binary classification models structurally resemble regression models.&lt;br /&gt;
|-&lt;br /&gt;
| discrete variable prediction problem, or multi-class classification problem || Here, the output can take one of a finite number of values. We can also think of this as a classification problem where each input case needs to be sorted into one of finitely many classes.&lt;br /&gt;
|-&lt;br /&gt;
| regression problem, or continuous variable prediction problem || Here, the output can take a value over a continuous range of values.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Classification based on the stage of learning===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Stage of learning !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[eager learning]] || This is the more common form of learning. Here, the training data is pre-processed and an explicit and compact representation of the function is learned from it (usually, in the form of a paramater vector). The learning phase that uses the training data to learn the compact representation takes substantially greater time, but once this phase is done, the training data can be thrown away. The compact representation takes much less memory than the training data and can be used to quickly compute the output for any input.&lt;br /&gt;
|-&lt;br /&gt;
| [[lazy learning]] || With this form of learning, the training data is not completely pre-processed. Every time a new prediction needs to be made, the training data is used to make the prediction. Lazy learning algorithms are useful in cases where the prediction of function values is based on nearby values.&lt;br /&gt;
|-&lt;br /&gt;
| [[online learning]] || Here, the input data is streamed to the algorithm, one instance at a time. For the one-instance case (each data point) three steps occur: (a) The algorithm reads the data (the input only), (b) the algorithm makes a prediction of the output, (c) the algorithm learns the actual output and updates the parameters according to that.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Machine_learning&amp;diff=3294</id>
		<title>Machine learning</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Machine_learning&amp;diff=3294"/>
		<updated>2021-06-12T01:48:36Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* The case of learning a function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Machine learning&#039;&#039;&#039; can be defined as the problem of using partial data about a function or relation to make predictions about how the function or relation would perform on new data. It is the branch of AI that covers its statistical part.&lt;br /&gt;
&lt;br /&gt;
===The case of learning a function===&lt;br /&gt;
&lt;br /&gt;
Although this particular formulation is not the most natural formulation of all machine learning problems, any machine learning problem can be converted to this formulation.&lt;br /&gt;
&lt;br /&gt;
An output function depends on some inputs (called [[feature]]s) (and possibly a random noise component). We have access to some training data, or thee ability to explore and discover training data, where we may or may not have the value of the output function, and we either already have or can get the values of the features. The machine learning problem asks for an explicit description of a function that would perform well on new inputs that we provide to it.&lt;br /&gt;
&lt;br /&gt;
==Types of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Classification based on nature of training data===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of machine learning !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[supervised learning]] || Explicit training data (input-output pairs) are provided. These can be used to learn the parameters for the functional form that can then be used to make predictions.&lt;br /&gt;
|-&lt;br /&gt;
| [[unsupervised learning]] || The training data as provided does not provide explicit outputs for explicit inputs. For instance, in the context of classification problems, an unsupervised learning problem would simply provide a lot of inputs without specifying the output values for those inputs. The job of the machine learning algorithm is to use the distribution of the inputs to figure out the output values.&lt;br /&gt;
|-&lt;br /&gt;
| [[semi-supervised learning]] || The training data is a mix of explicit input-output pairs and input-only data. Semi-supervised learning combines some of the aspects of supervised learning and unsupervised learning.&lt;br /&gt;
|-&lt;br /&gt;
| [[reinforcement learning]] || Unlike supervised learning, the training data is not chosen by the user; instead, the agent being trained generates the training data by interacting with the environment. In addition, the kind of feedback is different: in supervised learning the feedback is &#039;&#039;instructive&#039;&#039; (i.e. does not depend on the outputs the system selects), but in reinforcement learning the feedback is &#039;&#039;evaluative&#039;&#039; (i.e. depends on the action selected by the agent).&amp;lt;ref&amp;gt;Sutton and Barto. &#039;&#039;Reinforcement Learning: An Introduction&#039;&#039; (2nd ed). p. 25.&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;[https://www.coursera.org/learn/fundamentals-of-reinforcement-learning/lecture/PtVBs/sequential-decision-making-with-evaluative-feedback &amp;quot;Sequential Decision Making with Evaluative Feedback&amp;quot;]. Coursera.&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Classification based on nature of prediction===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Type of prediction problem !! Description&lt;br /&gt;
|-&lt;br /&gt;
| binary classification problem || Here, the output has only two permissible values. Therefore, the prediction problem can be viewed as a yes/no or a true/false prediction problem. Models for binary classification can be probabilistic (such as [[logistic regression]] or [[artificial neural network]]s) or yes/no (such as [[support vector machine]]s). Note that probabilistic binary classification models structurally resemble regression models.&lt;br /&gt;
|-&lt;br /&gt;
| discrete variable prediction problem, or multi-class classification problem || Here, the output can take one of a finite number of values. We can also think of this as a classification problem where each input case needs to be sorted into one of finitely many classes.&lt;br /&gt;
|-&lt;br /&gt;
| regression problem, or continuous variable prediction problem || Here, the output can take a value over a continuous range of values.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Classification based on the stage of learning===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Stage of learning !! Description&lt;br /&gt;
|-&lt;br /&gt;
| [[eager learning]] || This is the more common form of learning. Here, the training data is pre-processed and an explicit and compact representation of the function is learned from it (usually, in the form of a paramater vector). The learning phase that uses the training data to learn the compact representation takes substantially greater time, but once this phase is done, the training data can be thrown away. The compact representation takes much less memory than the training data and can be used to quickly compute the output for any input.&lt;br /&gt;
|-&lt;br /&gt;
| [[lazy learning]] || With this form of learning, the training data is not completely pre-processed. Every time a new prediction needs to be made, the training data is used to make the prediction. Lazy learning algorithms are useful in cases where the prediction of function values is based on nearby values.&lt;br /&gt;
|-&lt;br /&gt;
| [[online learning]] || Here, the input data is streamed to the algorithm, one instance at a time. For the one-instance case (each data point) three steps occur: (a) The algorithm reads the data (the input only), (b) the algorithm makes a prediction of the output, (c) the algorithm learns the actual output and updates the parameters according to that.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=210</id>
		<title>User:Vipul/Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=User:Vipul/Sandbox&amp;diff=210"/>
		<updated>2017-11-27T14:59:43Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;&amp;lt;math&amp;gt;e^{\pi^3 + \sqrt{3}}&amp;lt;/math&amp;gt;&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;math&amp;gt;e^{\pi^3 + \sqrt{3}}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Sandbox&amp;diff=202</id>
		<title>Sandbox</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Sandbox&amp;diff=202"/>
		<updated>2017-09-10T20:15:09Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;math&amp;gt;e^{\pi^{1/3} + \sqrt{-2} + \sqrt{-3}}&amp;lt;/math&amp;gt;&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=201</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=201"/>
		<updated>2017-09-10T20:13:37Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Unique property of the logistic link function ==&lt;br /&gt;
&lt;br /&gt;
The logistic function is not the only possible choice of link function that can be used to apply generalized linear models to probabilistic binary classification; another choice is the normal CDF, used in [[probit regression]].&lt;br /&gt;
&lt;br /&gt;
However, the logistic link function is the only link function &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; that satisfies the property of taking the value 1/2 at 0 (which is necessary for the symmetric sigmoidal shape we seek) &#039;&#039;and&#039;&#039; satisfies the condition that, if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and the linear combination in question is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the derivative of the logarithmic cost function is &amp;lt;math&amp;gt;g(w) - q&amp;lt;/math&amp;gt;, and therefore the second derivative is &amp;lt;math&amp;gt;g(w)(1 - g(w))&amp;lt;/math&amp;gt; which is positive and bounded by &amp;lt;math&amp;gt;1/4&amp;lt;/math&amp;gt;. This is because of the [[calculus:logistic function#differential equation|differential equation]] it satisfies. This provides an easy proof of convexity as well as bounded second derivative, and shows that [[calculus:gradient descent with constant learning rate for a convex function of multiple variables|gradient descent]] can be applied.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Probit regression===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s used for probability prediction for binary classification || Both fit the description; the link function for logistic regression is the logistic function and the link function for probit regression is the normal CDF. || The logistic link function is the unique function where the cost grows quadratically with distance from the true probability, or equivalently, the marginal cost is linear in distance from the true probability.&lt;br /&gt;
|-&lt;br /&gt;
| Use of [[calculus:gradient descent with constant learning rate for a convex function of multiple variables|gradient descent]] || Logistic regression is a convex optimization problem with a globally bounded second derivative, therefore gradient descent works. What about probit? || ??&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=200</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=200"/>
		<updated>2017-09-10T20:13:15Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Unique property of the logistic link function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Unique property of the logistic link function ==&lt;br /&gt;
&lt;br /&gt;
The logistic function is not the only possible choice of link function that can be used to apply generalized linear models to probabilistic binary classification; another choice is the normal CDF, used in [[probit regression]].&lt;br /&gt;
&lt;br /&gt;
However, the logistic link function is the only link function &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; that satisfies the property of taking the value 1/2 at 0 (which is necessary for the symmetric sigmoidal shape we seek) &#039;&#039;and&#039;&#039; satisfies the condition that, if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and the linear combination in question is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the derivative of the logarithmic cost function is &amp;lt;math&amp;gt;g(w) - q&amp;lt;/math&amp;gt;, and therefore the second derivative is &amp;lt;math&amp;gt;g(w)(1 - g(w))&amp;lt;/math&amp;gt; which is positive and bounded by &amp;lt;math&amp;gt;1/4&amp;lt;/math&amp;gt;. This is because of the [[calculus:logistic function#differential equation|differential equation]] it satisfies. This provides an easy proof of convexity as well as bounded second derivative, and shows that [[calculus:gradient descent with constant learning rate for a convex function of multiple variables|gradient descent]] can be applied.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Probit regression===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s used for probability prediction for binary classification || Both fit the description; the link function for logistic regression is the logistic function and the link function for probit regression is the normal CDF. || The logistic link function is the unique function where the cost grows quadratically with distance from the true probability, or equivalently, the marginal cost is linear in distance from the true probability.&lt;br /&gt;
|-&lt;br /&gt;
| Use of [[calculus:gradient descent with constant learning rate for a convex function of multiple variables|gradient descent]] || Logistic regression is a convex optimization problem with a globally bounded second derivative, therefore gradient descent works. What about probit? || ??&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=199</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=199"/>
		<updated>2017-09-10T20:00:11Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Probit regression */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Unique property of the logistic link function ==&lt;br /&gt;
&lt;br /&gt;
The logistic function is not the only possible choice of link function that can be used to apply generalized linear models to probabilistic binary classification; another choice is the normal CDF, used in [[probit regression]].&lt;br /&gt;
&lt;br /&gt;
However, the logistic link function is the only link function &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; that satisfies the property of taking the value 1/2 at 0 (which is necessary for the symmetric sigmoidal shape we seek) &#039;&#039;and&#039;&#039; satisfies the condition that, if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and the linear combination in question is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the derivative of the logarithmic cost function is &amp;lt;math&amp;gt;g(w) - q&amp;lt;/math&amp;gt;. Verbally, this is saying that the cost grows quadratically with the distance from the true probability. This is because of the [[calculus:logistic function#differential equation|differential equation]] it satisfies.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Probit regression===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s used for probability prediction for binary classification || Both fit the description; the link function for logistic regression is the logistic function and the link function for probit regression is the normal CDF. || The logistic link function is the unique function where the cost grows quadratically with distance from the true probability, or equivalently, the marginal cost is linear in distance from the true probability.&lt;br /&gt;
|-&lt;br /&gt;
| Use of [[calculus:gradient descent with constant learning rate for a convex function of multiple variables|gradient descent]] || Logistic regression is a convex optimization problem with a globally bounded second derivative, therefore gradient descent works. What about probit? || ??&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=198</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=198"/>
		<updated>2017-09-10T19:36:55Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Relation with other forms of machine learning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Unique property of the logistic link function ==&lt;br /&gt;
&lt;br /&gt;
The logistic function is not the only possible choice of link function that can be used to apply generalized linear models to probabilistic binary classification; another choice is the normal CDF, used in [[probit regression]].&lt;br /&gt;
&lt;br /&gt;
However, the logistic link function is the only link function &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; that satisfies the property of taking the value 1/2 at 0 (which is necessary for the symmetric sigmoidal shape we seek) &#039;&#039;and&#039;&#039; satisfies the condition that, if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and the linear combination in question is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the derivative of the logarithmic cost function is &amp;lt;math&amp;gt;g(w) - q&amp;lt;/math&amp;gt;. Verbally, this is saying that the cost grows quadratically with the distance from the true probability. This is because of the [[calculus:logistic function#differential equation|differential equation]] it satisfies.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Probit regression===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s used for probability prediction for binary classification || Both fit the description; the link function for logistic regression is the logistic function and the link function for probit regression is the normal CDF. || The logistic link function is the unique function where the cost grows quadratically with distance from the true probability, or equivalently, the marginal cost is linear in distance from the true probability.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=197</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=197"/>
		<updated>2017-09-10T19:34:50Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Relation with other forms of machine learning */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Unique property of the logistic link function ==&lt;br /&gt;
&lt;br /&gt;
The logistic function is not the only possible choice of link function that can be used to apply generalized linear models to probabilistic binary classification; another choice is the normal CDF, used in [[probit regression]].&lt;br /&gt;
&lt;br /&gt;
However, the logistic link function is the only link function &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; that satisfies the property of taking the value 1/2 at 0 (which is necessary for the symmetric sigmoidal shape we seek) &#039;&#039;and&#039;&#039; satisfies the condition that, if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; and the linear combination in question is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the derivative of the logarithmic cost function is &amp;lt;math&amp;gt;g(w) - q&amp;lt;/math&amp;gt;. Verbally, this is saying that the cost grows quadratically with the distance from the true probability. This is because of the [[calculus:logistic function#differential equation|differential equation]] it satisfies.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=196</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=196"/>
		<updated>2017-09-10T19:09:36Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Single-feature bias or intercept model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
=== Bias feature and a single binary feature  ===&lt;br /&gt;
&lt;br /&gt;
Consider a logistic regression model with a bias feature and a single binary feature (that can be either 0 or 1). Assume we have enough training data, and the binary feature is both zero and nonzero on enough examples.&lt;br /&gt;
&lt;br /&gt;
There are two ways of operationalizing this. One is to train it as a two-feature model, with one bias feature and the single binary feature. Another is to train it as a &#039;&#039;three&#039;&#039;-feature model, with one bias feature, the binary feature, and its complement. The latter approach has a linear relation between features (the binary feature and its complement add up to 1). However, it allows for a more clean-to-interpret model.&lt;br /&gt;
&lt;br /&gt;
Assuming no regularization:&lt;br /&gt;
&lt;br /&gt;
* With the two-feature model, the model weight learned on the bias feature is the log-odds of the probability of the event occurring if the single binary feature is off, and the model weight learned on the binary feature is the correction to the log-odds caused by the binary feature being true.&lt;br /&gt;
* With the three-feature model, the model weight learned on the bias feature is the log-odds of the overall probability, independent of whether the binary feature is true or false. The other two model weights give the respective corrections to the log-odds probability from the feature being true and false. These two model weights are of opposite sign, and they can be deduced from one another (but they are not literally negatives of each other, because (a) the feature may not be true and false the same amount of time, so there is a skew, and (b) these are additive corrections on log-odds not on probability itself, so the linearity is not preserved). In particular, the magnitude of the weight should generally be higher for the rarer of the two cases(since this gives more unique information, and is therefore expected to cause a larger update) but that is not always true.&lt;br /&gt;
&lt;br /&gt;
In particular, if knowledge of the binary feature does not change our probability estimate, then the weight learned on the feature and/or its complement is zero.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=195</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=195"/>
		<updated>2017-09-10T18:58:45Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Single-feature bias or intercept model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term (after normalizing by the number of examples); the larger the regularization terms, the closer &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; is to zero. In particular, the greater the number of examples, the closer we get to &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, holding the regularization term constant. This makes sense from the perspective of regularization as Bayesian prior: with small amounts of data we gravitate toward the Bayesian prior of even odds, whereas with a large amount of data we gravitate toward the frequency seen in the data.&lt;br /&gt;
&lt;br /&gt;
Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, and a total of &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; examples, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \frac{\lambda_1}{m} |w| + \frac{\lambda_2}{m} w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \frac{\lambda_1}{m} \operatorname{sgn}(w) + \frac{2\lambda_2}{m} w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=194</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=194"/>
		<updated>2017-09-10T18:55:11Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Empty feature set and empty model */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[calculus:logistic function|logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term. Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \lambda_1 |w| + \lambda_2 w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \lambda_1 \operatorname{sgn}(w) + 2\lambda_2 w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=193</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=193"/>
		<updated>2017-09-10T18:54:07Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Computational format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
== Examples of feature sets and models ==&lt;br /&gt;
&lt;br /&gt;
=== Empty feature set and empty model ===&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;empty model&amp;quot; for a logistic regression problem is the model with no features, or alternatively, the model where all the features have zero model weights. The linear combination generated for any example is zero, so the probability predicted for any example is the [[logistic function]] applied at 0, which is &amp;lt;math&amp;gt;g(0) = 1/2&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function for each example is therefore &amp;lt;math&amp;gt;-\log(1/2) = \log 2 \approx 0.6931&amp;lt;/math&amp;gt;, and hence, so is the arithmetic mean. This is treated as a baseline for the logarithmic loss on logistic regression models and for any binary classification models predicting a probability; any logistic regression model that is trained properly should provide a lower (better) cost than the empty model.&lt;br /&gt;
&lt;br /&gt;
Standard choices of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; ([[lasso]]), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; ([[ridge regression]]), and elastic net (a mix of the two) all give their lowest penalty of zero to the empty model. Therefore, in general, if the event occurs about half the time and none of the features being trained on have any signal useful for predicting the outcome, a regularized logistic regression will converge to the empty model (however, note the caveat on the bias term below).&lt;br /&gt;
&lt;br /&gt;
=== Single-feature bias or intercept model ===&lt;br /&gt;
&lt;br /&gt;
This is a model with a single nonzero model weight, corresponding to a feature that is 1 on all examples. If this weight is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;, then the linear combination is &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; on each example, and the predicted probability works out to &amp;lt;math&amp;gt;g(w)&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If this model is trained without regularization on a training set, then the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that it learns is &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; is the fraction of positive examples in the training set. If the training set is sufficiently large and representative, then &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; equals the probability of occurrence of the event, so the model essentially predicts the probability of occurrence (the base rate) without trying to figure out which examples are more or less likely to be positive.&lt;br /&gt;
&lt;br /&gt;
In the case of regularization such as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;, or elastic net, the weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; learned is between &amp;lt;math&amp;gt;0&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;g^{-1}(q)&amp;lt;/math&amp;gt;, where its exact position is determined by the strength of the regularization term. Specifically, for the case of elastic net regularization with &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-parameter &amp;lt;math&amp;gt;\lambda_2&amp;lt;/math&amp;gt;, we have to pick &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; that minimizes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-q \log(g(w)) - (1 - q) \log(1 - g(w)) + \lambda_1 |w| + \lambda_2 w^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Taking derivatives and finding critical points, we get:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(w) - q + \lambda_1 \operatorname{sgn}(w) + 2\lambda_2 w = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There is no analytical solution to this but it can be solved using numerical techniques.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=192</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=192"/>
		<updated>2017-09-10T18:26:49Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&amp;lt;br/&amp;gt;The parameters are sometimes called the &#039;&#039;model weights&#039;&#039;, with each model weight associated to a particular feature for which it is the coefficient. The feature for which the model weight is zero can be thought of as not being part of the model, since its value plays no role in the prediction. We sometimes say that the features with nonzero model weights are features &amp;quot;picked&amp;quot; by the training.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Comparison_of_lasso_and_ridge_regularization&amp;diff=191</id>
		<title>Comparison of lasso and ridge regularization</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Comparison_of_lasso_and_ridge_regularization&amp;diff=191"/>
		<updated>2017-09-10T17:52:49Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Case of generalized linear model (such as linear regression or logistic regression) ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Case on features !! Result under lasso !! Result under ridge &lt;br /&gt;
|-&lt;br /&gt;
| Two copies of the same feature. If only one copy had been included, a parameter value of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; would have been learned. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; gets split across the features, but in an indeterminate way. In other words, you could get any distribution &amp;lt;math&amp;gt;\alpha w, (1 - \alpha) w&amp;lt;/math&amp;gt;. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; gets evenly split across the features: &amp;lt;math&amp;gt;w/2&amp;lt;/math&amp;gt; each.&lt;br /&gt;
|-&lt;br /&gt;
| One primary feature, that for simplicity we take as a binary feature that is nonzero on some fraction of examples. Two other &amp;quot;backup&amp;quot; features, that are each nonzero in disjoint halves of the case the primary feature is nonzero. Once the primary feature is known, there is no additional signal in knowing the values of the backup features. If the backup features were excluded, the primary feature would learn a weight of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; all goes on the primary features, and the backup features get weights of zero. || The primary features gets weights &amp;lt;math&amp;gt;(2/3)w&amp;lt;/math&amp;gt; and each of the backup features get weight &amp;lt;math&amp;gt;(1/3)w&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=190</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=190"/>
		<updated>2017-09-10T17:46:42Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Cost function used */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Cost_function&amp;diff=189</id>
		<title>Cost function</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Cost_function&amp;diff=189"/>
		<updated>2017-09-10T16:44:57Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Binary classification problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;cost function&#039;&#039;&#039; associated with a given machine learning problem is a function that takes as input the predicted function value and actual observed output and associates to them a number measuring how far the predicted value is from the observed value.&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
This section gives the definitions of cost functions for a single piece of data, for both regression problems and classification problems.&lt;br /&gt;
&lt;br /&gt;
===Regression problems===&lt;br /&gt;
&lt;br /&gt;
For regression problems (prediction problems associated with continuous variables), both the predicted value and the actual value are continuous variables. The cost function is a function &amp;lt;math&amp;gt;C\colon \mathbb R \times \mathbb R \to \mathbb R&amp;lt;/math&amp;gt; of two variables &amp;lt;math&amp;gt;u,v \in \mathbb R&amp;lt;/math&amp;gt; (the predicted value and actual value) satisfying the following conditions:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(u,u) = 0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u \in \R&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;u \le v \le w&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(u,v) \le C(u,w)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;C(v,w) \le C(u,w)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cost function need not satisfy the triangle inequality; in fact, typical cost functions penalize bigger errors superlinearly.&lt;br /&gt;
&lt;br /&gt;
Two typical examples of cost functions are &amp;lt;math&amp;gt;C(u,v) = (u-v)^2&amp;lt;/math&amp;gt; (the [[quadratic cost function]], used for least squares linear regression) and &amp;lt;math&amp;gt;C(u,v) = |u-v|&amp;lt;/math&amp;gt; (used for least absolute deviations regression). With the former cost function, we see that for &amp;lt;math&amp;gt;-1,0,1 \in \mathbb R&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(-1-0)^2 + (0-1)^2 = 2 \not\geq 4 = (-1-1)^2&amp;lt;/math&amp;gt;, so the triangle inequality is not satisfied.&lt;br /&gt;
&lt;br /&gt;
===Binary classification problems===&lt;br /&gt;
&lt;br /&gt;
For binary classification problems (prediction problems associated with discrete variables), the predicted value is a probability and the actual value is simply a discrete value (0 or 1). The cost function is a function &amp;lt;math&amp;gt;C\colon [0,1]\times \{0,1\} \to \mathbb R&amp;lt;/math&amp;gt; of two variables &amp;lt;math&amp;gt;p\in [0,1]&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v \in \{0,1\}&amp;lt;/math&amp;gt; (the predicted probability and actual value) satisfying the following conditions:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(1,1) = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;C(0,0) = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;p \le q&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(q,1) \le C(p,1)&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;p \le q&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(p,0) \le C(q,0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Although not a strict requirement, cost functions should be selected to be [[calculus:proper scoring rule|proper scoring rule]]s, so that they penalize accurate probabilities less than inaccurate probabilities.&lt;br /&gt;
&lt;br /&gt;
Typical cost functions used for binary classification problems include the [[calculus:logarithmic scoring rule|logarithmic cost function]] and the [[quadratic cost function]], both of which are proper scoring rules. Of these, the logarithmic scoring rules is the more widely used, because it is the only [[calculus:logarithmic scoring rule is the only proper scoring rule up to affine transformations in case of more than two classes|proper scoring rule when considering more than two classes]].&lt;br /&gt;
&lt;br /&gt;
==Combining the cost function values across multiple data points==&lt;br /&gt;
&lt;br /&gt;
To compute the cost function for several data points, we need to know the cost function for a single data point, as well as an approach for averaging the cost functions. The following are some typical choices:&lt;br /&gt;
&lt;br /&gt;
* Arithmetic mean: This is the most common, and the default specification. This is equivalent to using the sum of the cost functions, but using the mean instead of the sum is preferable because that allows us to directly compare cost function values for data sets of different sizes.&lt;br /&gt;
* Mean using &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; powers, for some &amp;lt;math&amp;gt;r &amp;gt; 1&amp;lt;/math&amp;gt;: We take the mean of the &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; powers of all the cost functions, then take the &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; root.&lt;br /&gt;
* Maximum value&lt;br /&gt;
&lt;br /&gt;
Note that there is some flexibility in terms of how we divide the load between the choice of cost function and the choice of averaging function: for instance, there is some equivalence between using the absolute value cost function and the root mean square averaging process versus using the squared error cost function and the arithmetic mean averaging process. The cost functions obtained in both cases are equivalent under a monotone transformation. If, however, we are considering adding regularization terms, then the distinction between the cost functions matters.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Cost_function&amp;diff=188</id>
		<title>Cost function</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Cost_function&amp;diff=188"/>
		<updated>2017-09-10T16:42:29Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Regression problems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;cost function&#039;&#039;&#039; associated with a given machine learning problem is a function that takes as input the predicted function value and actual observed output and associates to them a number measuring how far the predicted value is from the observed value.&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
This section gives the definitions of cost functions for a single piece of data, for both regression problems and classification problems.&lt;br /&gt;
&lt;br /&gt;
===Regression problems===&lt;br /&gt;
&lt;br /&gt;
For regression problems (prediction problems associated with continuous variables), both the predicted value and the actual value are continuous variables. The cost function is a function &amp;lt;math&amp;gt;C\colon \mathbb R \times \mathbb R \to \mathbb R&amp;lt;/math&amp;gt; of two variables &amp;lt;math&amp;gt;u,v \in \mathbb R&amp;lt;/math&amp;gt; (the predicted value and actual value) satisfying the following conditions:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(u,u) = 0&amp;lt;/math&amp;gt; for all &amp;lt;math&amp;gt;u \in \R&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;u \le v \le w&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(u,v) \le C(u,w)&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;C(v,w) \le C(u,w)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The cost function need not satisfy the triangle inequality; in fact, typical cost functions penalize bigger errors superlinearly.&lt;br /&gt;
&lt;br /&gt;
Two typical examples of cost functions are &amp;lt;math&amp;gt;C(u,v) = (u-v)^2&amp;lt;/math&amp;gt; (the [[quadratic cost function]], used for least squares linear regression) and &amp;lt;math&amp;gt;C(u,v) = |u-v|&amp;lt;/math&amp;gt; (used for least absolute deviations regression). With the former cost function, we see that for &amp;lt;math&amp;gt;-1,0,1 \in \mathbb R&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;(-1-0)^2 + (0-1)^2 = 2 \not\geq 4 = (-1-1)^2&amp;lt;/math&amp;gt;, so the triangle inequality is not satisfied.&lt;br /&gt;
&lt;br /&gt;
===Binary classification problems===&lt;br /&gt;
&lt;br /&gt;
For binary classification problems (prediction problems associated with discrete variables), the predicted value is a probability and the actual value is simply a discrete value (0 or 1). The cost function is a function &amp;lt;math&amp;gt;C\colon [0,1]\times \{0,1\} \to \mathbb R&amp;lt;/math&amp;gt; of two variables &amp;lt;math&amp;gt;p\in [0,1]&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;v \in \{0,1\}&amp;lt;/math&amp;gt; (the predicted probability and actual value) satisfying the following conditions:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;C(1,1) = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;C(0,0) = 0&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;p \le q&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(q,1) \le C(p,1)&amp;lt;/math&amp;gt;&lt;br /&gt;
* For &amp;lt;math&amp;gt;p \le q&amp;lt;/math&amp;gt;, we have &amp;lt;math&amp;gt;C(p,0) \le C(q,0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Combining the cost function values across multiple data points==&lt;br /&gt;
&lt;br /&gt;
To compute the cost function for several data points, we need to know the cost function for a single data point, as well as an approach for averaging the cost functions. The following are some typical choices:&lt;br /&gt;
&lt;br /&gt;
* Arithmetic mean: This is the most common, and the default specification. This is equivalent to using the sum of the cost functions, but using the mean instead of the sum is preferable because that allows us to directly compare cost function values for data sets of different sizes.&lt;br /&gt;
* Mean using &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; powers, for some &amp;lt;math&amp;gt;r &amp;gt; 1&amp;lt;/math&amp;gt;: We take the mean of the &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; powers of all the cost functions, then take the &amp;lt;math&amp;gt;r^{\text{th}}&amp;lt;/math&amp;gt; root.&lt;br /&gt;
* Maximum value&lt;br /&gt;
&lt;br /&gt;
Note that there is some flexibility in terms of how we divide the load between the choice of cost function and the choice of averaging function: for instance, there is some equivalence between using the absolute value cost function and the root mean square averaging process versus using the squared error cost function and the arithmetic mean averaging process. The cost functions obtained in both cases are equivalent under a monotone transformation. If, however, we are considering adding regularization terms, then the distinction between the cost functions matters.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=187</id>
		<title>Lasso</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=187"/>
		<updated>2017-09-10T16:25:46Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Effects of lasso */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Definition ==&lt;br /&gt;
&lt;br /&gt;
Lasso, also known as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-regularization, is a type of [[regularization]] where the regularization term is of the following form, where &amp;lt;math&amp;gt;w_1, w_2, \dots, w_n&amp;lt;/math&amp;gt; are the unknown parameters of the form being trained for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n  | w_i |&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, due to scaling issues, a lasso may not make direct sense, so we may need additional (predetermined) coefficients &amp;lt;math&amp;gt;\alpha_1, \alpha_2, \dots, \alpha_n&amp;lt;/math&amp;gt; to rescale the weights:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n \alpha_i |w_i|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effects of lasso ==&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value &lt;br /&gt;
|-&lt;br /&gt;
| Convexity || The lasso function is convex. Thus, if the original cost function is convex, the regularized cost function is also convex. In particular, it does not destroy the ability to apply optimization methods that rely solely on convexity. &lt;br /&gt;
|-&lt;br /&gt;
| Differentiability || The lasso function is differentiable at most points except where one of the weights becomes zero (with partial derivative being undefined in the direction parallel to that weight vector). This can come in the way of iterative application of [[gradient descent]] since the gradient vector is undefined. However, setting partial derivative to zero when it is undefined generally works.&lt;br /&gt;
|-&lt;br /&gt;
| Type of model generated || Lasso regression pushes towards models where some parameters become precisely zero. It will also generally push those features to be zero that can help distinguish fewer examples, so for instance if a dense feature and a sparser feature both play a similar predictive role, lasso will tend to set the sparser feature to zero. For more, see [[comparison of lasso and ridge regularization]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Comparison_of_lasso_and_ridge_regularization&amp;diff=186</id>
		<title>Comparison of lasso and ridge regularization</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Comparison_of_lasso_and_ridge_regularization&amp;diff=186"/>
		<updated>2017-09-10T16:25:18Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot; ! Case on features !! Result under lasso !! Result under ridge  |- | Two copies of the same feature. If only one copy had been included, a param...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Case on features !! Result under lasso !! Result under ridge &lt;br /&gt;
|-&lt;br /&gt;
| Two copies of the same feature. If only one copy had been included, a parameter value of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; would have been learned. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; gets split across the features, but in an indeterminate way. In other words, you could get any distribution &amp;lt;math&amp;gt;\alpha w, (1 - \alpha) w&amp;lt;/math&amp;gt;. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; gets evenly split across the features: &amp;lt;math&amp;gt;w/2&amp;lt;/math&amp;gt; each.&lt;br /&gt;
|-&lt;br /&gt;
| One primary feature, that for simplicity we take as a binary feature that is nonzero on some fraction of examples. Two other &amp;quot;backup&amp;quot; features, that are each nonzero in disjoint halves of the case the primary feature is nonzero. Once the primary feature is known, there is no additional signal in knowing the values of the backup features. If the backup features were excluded, the primary feature would learn a weight of &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt;. || The weight &amp;lt;math&amp;gt;w&amp;lt;/math&amp;gt; all goes on the primary features, and the backup features get weights of zero. || The primary features gets weights &amp;lt;math&amp;gt;(2/3)w&amp;lt;/math&amp;gt; and each of the backup features get weight &amp;lt;math&amp;gt;(1/3)w&amp;lt;/math&amp;gt;.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=185</id>
		<title>Lasso</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=185"/>
		<updated>2017-09-10T16:12:29Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Definition ==&lt;br /&gt;
&lt;br /&gt;
Lasso, also known as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-regularization, is a type of [[regularization]] where the regularization term is of the following form, where &amp;lt;math&amp;gt;w_1, w_2, \dots, w_n&amp;lt;/math&amp;gt; are the unknown parameters of the form being trained for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n  | w_i |&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, due to scaling issues, a lasso may not make direct sense, so we may need additional (predetermined) coefficients &amp;lt;math&amp;gt;\alpha_1, \alpha_2, \dots, \alpha_n&amp;lt;/math&amp;gt; to rescale the weights:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n \alpha_i |w_i|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effects of lasso ==&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value &lt;br /&gt;
|-&lt;br /&gt;
| Convexity || The lasso function is convex. Thus, if the original cost function is convex, the regularized cost function is also convex. In particular, it does not destroy the ability to apply optimization methods that rely solely on convexity. &lt;br /&gt;
|-&lt;br /&gt;
| Differentiability || The lasso function is differentiable at most points except where one of the weights becomes zero (with partial derivative being undefined in the direction parallel to that weight vector). This can come in the way of iterative application of [[gradient descent]] since the gradient vector is undefined. However, setting partial derivative to zero when it is undefined generally works.&lt;br /&gt;
|-&lt;br /&gt;
| Type of model generated || Lasso regression pushes towards models where some parameters become precisely zero. It will also generally push those features to be zero that can help distinguish fewer examples, so for instance if a dense feature and a sparser feature both play a similar predictive role, lasso will tend to set the sparser feature to zero.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=184</id>
		<title>Lasso</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Lasso&amp;diff=184"/>
		<updated>2017-09-10T16:12:07Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;== Definition ==  Lasso, also known as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-regularization, is a type of regularization where the regularization term is of the following form, where &amp;lt;math&amp;gt;w_1...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Definition ==&lt;br /&gt;
&lt;br /&gt;
Lasso, also known as &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-regularization, is a type of [[regularization]] where the regularization term is of the following form, where &amp;lt;math&amp;gt;w_1, w_2, \dots, w_n&amp;lt;/math&amp;gt; are the unknown parameters of the form being trained for:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n  | w_i |&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, due to scaling issues, a lasso may not make direct sense, so we may need additional (predetermined) coefficients &amp;lt;math&amp;gt;\alpha_1, \alpha_@, \dots, \alpha_n&amp;lt;/math&amp;gt; to rescale the weights:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\lambda \sum_{i=1}^n \alpha_i |w_i|&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Effects of lasso ==&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value &lt;br /&gt;
|-&lt;br /&gt;
| Convexity || The lasso function is convex. Thus, if the original cost function is convex, the regularized cost function is also convex. In particular, it does not destroy the ability to apply optimization methods that rely solely on convexity. &lt;br /&gt;
|-&lt;br /&gt;
| Differentiability || The lasso function is differentiable at most points except where one of the weights becomes zero (with partial derivative being undefined in the direction parallel to that weight vector). This can come in the way of iterative application of [[gradient descent]] since the gradient vector is undefined. However, setting partial derivative to zero when it is undefined generally works.&lt;br /&gt;
|-&lt;br /&gt;
| Type of model generated || Lasso regression pushes towards models where some parameters become precisely zero. It will also generally push those features to be zero that can help distinguish fewer examples, so for instance if a dense feature and a sparser feature both play a similar predictive role, lasso will tend to set the sparser feature to zero.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=L%5E1_regularization&amp;diff=183</id>
		<title>L^1 regularization</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=L%5E1_regularization&amp;diff=183"/>
		<updated>2017-09-10T15:40:26Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Redirected page to Lasso&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#redirect [[Lasso]]&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Regularization&amp;diff=182</id>
		<title>Regularization</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Regularization&amp;diff=182"/>
		<updated>2017-09-10T15:39:32Z</updated>

		<summary type="html">&lt;p&gt;Vipul: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Definition==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Regularization&#039;&#039;&#039; is described as follows.&lt;br /&gt;
&lt;br /&gt;
We have:&lt;br /&gt;
&lt;br /&gt;
* A set of [[feature]]s that predict an output value&lt;br /&gt;
* A set of [[training data]], including the set of features and the output value&lt;br /&gt;
* A functional form, in terms of unknown parameters, that describes the output value in terms of the features. These parameters are also sometimes known as model weights.&lt;br /&gt;
* A choice of [[cost function]] (or error function) that measures the error for a given pair of predicted output and actual output.&lt;br /&gt;
&lt;br /&gt;
Regularization refers to a process where we modify the cost function by adding to it an expression that captures the complexity of the feature set. The expression is typically a product of a [[hyperparameter]] (subject to smart [[hyperparameter optimization]]) and a fixed function of the parameters being learned (i.e., the model weights) chosen based on the problem domain. This fixed function is typically the &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;-norm, squared &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-norm, or &amp;lt;math&amp;gt;L^\infty&amp;lt;/math&amp;gt;-norm of the feature vector (sometimes with some coordinates removed).&lt;br /&gt;
&lt;br /&gt;
Note that the choice of regularization, including the choice of hyperparameter, need to be known by the [[learning algorithm]]. Moreover, some learning algorithms that work for unregularized problems may not work for regularized problems, or may need to be modified to tackle the version with regularization.&lt;br /&gt;
&lt;br /&gt;
Regularization is used &#039;&#039;only on the training data&#039;&#039;, not on test data that was withheld from the learning algorithm.&lt;br /&gt;
&lt;br /&gt;
===Goal: enforcing simplicity and reducing complexity===&lt;br /&gt;
&lt;br /&gt;
Regularization introduces a penalty for complexity, and forces the parameter vector to be simple. This reduces the extent of [[overfitting]].&lt;br /&gt;
&lt;br /&gt;
Regularization can also enforce unique solutions in the case of overdetermined problems.&lt;br /&gt;
&lt;br /&gt;
==Hyperparameter optimization for the regularization hyperparameter==&lt;br /&gt;
&lt;br /&gt;
{{further|[[hyperparameter optimization]]}}&lt;br /&gt;
&lt;br /&gt;
Ideally, we would like to choose a [[regularization hyperparameter]] such that the parameters found by the model do best on new data that was withheld from the learning algorithm. The approach used for this is [[cross-validation]]: we cordon off a part of the training set from the learning algorithm (this cordoned-off part is called the cross-validation set), run the learning algorithm for different choices of hyperparameter, and compare the performance of all the solutions obtained on the cross-validation set. We pick the one that does best on this set and then check that it did well on the training set.&lt;br /&gt;
&lt;br /&gt;
Some algorithms use the test set as their cross-validation set. For sufficiently large data sets, this is not a problem. However, for small and intermediate-sized data sets, this is problematic because we end up overfitting the regularization parameter itself by exposing it to influence from the test set. The neatest approach is to keep the cross-validation and test sets separate.&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Linear_regression&amp;diff=181</id>
		<title>Linear regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Linear_regression&amp;diff=181"/>
		<updated>2017-09-10T15:37:05Z</updated>

		<summary type="html">&lt;p&gt;Vipul: Created page with &amp;quot;== Summary ==  {| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot; ! Item !! Value |- | Type of variable predicted || Continuous; however this could also be used to predict discrete variables that...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Continuous; however this could also be used to predict discrete variables that can be placed on a continuum, such as values that are constrained to be integers.&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || A point estimate of the value is output&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the point estimate for the value being predicted by taking a linear combination of the features. The coefficients for the linear combination are the unknown parameters (also known as &#039;&#039;model weights&#039;&#039;) that need to be determined by the learning algorithm.&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || The most typical is ordinary least squares (OLS) regression, where the loss associated with each prediction is the square of the distance between the prediction and the actual value. There are many variants, such as weighted least squares (where different predictions get different weights), total least squares (where errors in both dependent and independent variables are modeled), non-negative least squares (where the parameters are all constrained to be non-negative).&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; (lasso), &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; (ridge), and a mix (elastic net). Other Bayesian priors may also be used to generate regularizations.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=180</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=180"/>
		<updated>2017-09-10T15:24:51Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[calculus:logarithmic scoring|logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
	<entry>
		<id>https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=179</id>
		<title>Logistic regression</title>
		<link rel="alternate" type="text/html" href="https://machinelearning.subwiki.org/w/index.php?title=Logistic_regression&amp;diff=179"/>
		<updated>2017-09-10T15:19:05Z</updated>

		<summary type="html">&lt;p&gt;Vipul: /* Support vector machines */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Summary==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Item !! Value&lt;br /&gt;
|-&lt;br /&gt;
| Type of variable predicted || Binary (yes/no)&lt;br /&gt;
|-&lt;br /&gt;
| Format of prediction || Probabilistic. Rather than simply returning a binary answer, the prediction gives the respective probabilities of the two answers.&lt;br /&gt;
|-&lt;br /&gt;
| Functional form of model || Computes the probability by applying the [[calculus:logistic function|logistic function]] to a linear combination of the features. The coefficients used in the linear combination are the unknown parameters that need to be determined by the learning algorithm. It is an example of a [[generalized linear model]].&lt;br /&gt;
|-&lt;br /&gt;
| Typical cost function || As with most probabilistic binary prediction models, logistic regression models are typically scored using the [[logarithmic cost function]]. However, they could in principle be scored using the squared error cost function. Note that this still wouldn&#039;t be least-squares regression, because the least-squares is being computed &#039;&#039;after&#039;&#039; applying the logistic function.&lt;br /&gt;
|-&lt;br /&gt;
| Typical regularization choices || Both &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt;- and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt;-regularization, as well as combined regularization using &amp;lt;math&amp;gt;L^1&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;L^2&amp;lt;/math&amp;gt; terms, are common.&lt;br /&gt;
|-&lt;br /&gt;
| Learning algorithms || See [http://www.cs.iastate.edu/~honavar/minka-logreg.pdf here for more] (to eventually fill in here).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==Definition==&lt;br /&gt;
&lt;br /&gt;
The term &#039;&#039;&#039;logistic regression&#039;&#039;&#039; is used for a model as well as the act of finding the parameters of the model whose goal is to predict binary outputs. It is therefore better viewed as solving a [[classification]] problem than a regression problem. However, because the model shares many basic components with [[linear regression]], and is an example of a [[generalized linear model]], it has historically gone by the name of logistic &#039;&#039;regression&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
The logistic regression problem attempts to predict a binary output (yes/no) based on a set of inputs (called [[feature]]s). Rather than just predicting a yes/no answer, the logistic regression problem predicts a probability of yes. This is a number in &amp;lt;math&amp;gt;[0,1]&amp;lt;/math&amp;gt;. By using a threshold probability (such as 0.5, or another value depending on what sorts of risks we want to avoid) this can make a yes/no prediction.&lt;br /&gt;
&lt;br /&gt;
The probability is computed as follows:&lt;br /&gt;
&lt;br /&gt;
Probability = [[calculus:logistic function|logistic function]] evaluated at (linear combination of features with initially unknown parameters)&lt;br /&gt;
&lt;br /&gt;
The logistic function is the function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g(x) = \frac{1}{1 + e^{-x}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The values of the unknown parameters are determined empirically so as to best fit the [[training set]]. &lt;br /&gt;
&lt;br /&gt;
===Cost function used===&lt;br /&gt;
&lt;br /&gt;
The typical cost function used is the logarithmic cost function (also known as [[calculus:logarithmic scoring rule|logarithmic scoring]]): This assigns a score of &amp;lt;math&amp;gt;-\log p&amp;lt;/math&amp;gt; if the event happened and a score of &amp;lt;math&amp;gt;-\log (1 - p)&amp;lt;/math&amp;gt; if the event did not happen. The lower the score, the better. The [[calculus:logarithmic scoring rule is proper|logarithmic scoring rule is proper]]: if the true probability is &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;, then the score is minimized by predicting &amp;lt;math&amp;gt;p = q&amp;lt;/math&amp;gt;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if we could predict whether or not the event will happen with perfect confidence, the logarithmic score would evaluate to 0.&lt;br /&gt;
&lt;br /&gt;
The logarithmic cost function is computed for each of the predictions made by the logistic regression model. We then average the values of the cost functions across all instances to obtain the logarithmic cost function for the specific choice of parameter values on the specific data set.&lt;br /&gt;
&lt;br /&gt;
There are two standard choices of labels for describing whether the event did or did not occur. One choice is to assign a label of 0 if the event did not occur and 1 if the event occurred. Another choice is to assign a label of -1 if the event did not occur and 1 if the event occurred.&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using 0,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;y&amp;lt;/math&amp;gt; with value 0 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-(y \log p + (1 - y)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Suppose there are &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; data points. The probability vector is the vector &amp;lt;math&amp;gt;\vec{y} = (y_1,y_2,\dots,y_m)&amp;lt;/math&amp;gt; and the probability vector is the vector &amp;lt;math&amp;gt;\vec{p} = (p_1,p_2,\dots,p_m)&amp;lt;/math&amp;gt;. The cost function is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\frac{1}{m} \left[\sum_{i=1}^m -(y_i \log p_i + (1 - y_i)\log(1 - p_i))\right]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Closed form expression for cost function using -1,1-encoding====&lt;br /&gt;
&lt;br /&gt;
Suppose we assign a label &amp;lt;math&amp;gt;l&amp;lt;/math&amp;gt; with value -1 if the event did not occur and 1 if the event occurred. Then, if &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is the predicted probability, the score associated with &amp;lt;math&amp;gt;p&amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;-\frac{1}{2} ((1 + l) \log p + (1 - l)\log(1 - p))&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Description as a generalized linear model===&lt;br /&gt;
&lt;br /&gt;
The logistic regression model can be viewed as a special case of the [[generalized linear model]], namely a case where the link function is the [[calculus:logistic function|logistic function]] and where the cost function is the logarithmic cost function.&lt;br /&gt;
&lt;br /&gt;
The inverse of the logistic function is the log-odds function, and applying it to the probability gives the log-odds (logarithm of odds). Explicitly, we have:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;g^{-1}(p) = \ln \left( \frac{p}{1 - p}\right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Therefore, the logistic regression problem can be viewed as a linear regression problem:&lt;br /&gt;
&lt;br /&gt;
Log-odds function = Linear combination of features with unknown parameters&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;However&#039;&#039;, the cost function now changes as well: we now need to apply the logistic function and then do logarithmic scoring to compute the cost function.&lt;br /&gt;
&lt;br /&gt;
==Computational format==&lt;br /&gt;
&lt;br /&gt;
The computational format for a logistic regression is as follows. Note that there may be variations in terms of the roles of rows and columns. We follow the convention of using column vectors and having the matrix multiplied on the left of the vector.&lt;br /&gt;
&lt;br /&gt;
Some notation:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; denotes the number of examples (data points).&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; denotes the number of features, or equivalently, the number of parameters. Note that the number of elementary features need not equal &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;. The &amp;quot;features&amp;quot; we are referring to are expressions in the elementary features that we can use as the spanning set for our arbitrary linear combinations whose coefficients are the unknown parameters we need to find.&lt;br /&gt;
* &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is the data matrix or design matrix of the regression. &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; is a &amp;lt;math&amp;gt;m \times n&amp;lt;/math&amp;gt; matrix. Each row of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one example. Each column of &amp;lt;math&amp;gt;X&amp;lt;/math&amp;gt; corresponds to one feature (not necessarily an elementary feature) and hence also to one coordinate of the parameter vector (the coefficient on that feature). The entry in a given row and given column is the feature value for that example.&lt;br /&gt;
* The vector of labels (or actual outputs) is a &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt;-dimensional vector. If we use the 0-1 convention, this is a vector all of whose coordinates are either 0 or 1. If we use the &amp;lt;math&amp;gt;\{ -1,1 \}&amp;lt;/math&amp;gt;-convention, this is a vector all of whose coordinates are either -1 or 1. For convenience on this page, we&#039;ll denote the former vector by &amp;lt;math&amp;gt;\vec{y}&amp;lt;/math&amp;gt; and the latter by &amp;lt;math&amp;gt;\vec{l}&amp;lt;/math&amp;gt;. We have the relations &amp;lt;math&amp;gt;y_i = (1 + l_i)/2&amp;lt;/math&amp;gt;, and &amp;lt;math&amp;gt;l_i = 2y_i - 1&amp;lt;/math&amp;gt;, for all &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt;.&lt;br /&gt;
* The parameter vector is a &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;-dimensional vector. We will denote it as &amp;lt;math&amp;gt;\vec{\theta}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The predicted probability vector is given as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\vec{p} = g(X \vec{\theta})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;math&amp;gt;g&amp;lt;/math&amp;gt; is the [[calculus:logistic function|logistic function]] and is applied coordinate-wise.&lt;br /&gt;
&lt;br /&gt;
==Relation with other forms of machine learning==&lt;br /&gt;
&lt;br /&gt;
===Linear regression===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and [[linear regression]] are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| [[Generalized linear model]]s, so linear dependence on inputs || Both are examples of generalized linear models || For linear regression, the link function is the identity function and the typical choice of cost function is the squared error cost function. In the case of logistic regression, the link function is the [[calculus:logistic function|logistic function]] and the typical choice of cost function is the logarithmic cost function.&lt;br /&gt;
|-&lt;br /&gt;
| Prediction of continuous variables || &#039;&#039;Prima facie&#039;&#039;, both of them output variables that take continuous values || Linear regression outputs a continuous variable that is the estimate of the output being predicted.&amp;lt;br&amp;gt;The continuous variable output by logistic regression is the &#039;&#039;probability&#039;&#039; associated with a binary classification problem.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Support vector machines===&lt;br /&gt;
&lt;br /&gt;
Logistic regression and the [[support vector machine]] (SVM) regression method are related in the following ways:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;sortable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! Aspect !! How they&#039;re similar !! How they&#039;re different&lt;br /&gt;
|-&lt;br /&gt;
| Binary classification || Both logistic regression and support vector model are approaches to tackling binary classification. || Logistic regression outputs a probability, whereas support vector models output a yes/no answer. Support vector machines &#039;&#039;can&#039;&#039; be construed as giving an output describing the confidence of a classification, but this is not explicitly translated into a probability. Note that the linear SVM result can be interpreted as a result for the logistic regression problem, and running linear SVM and logistic regression on the same data set can yield very similar results.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Artificial neural networks===&lt;br /&gt;
&lt;br /&gt;
Artificial neural networks are a more complicated type of machine learning setup that is capable of learning more complex functions. The individual units in an artificial neural network, called [[artificial neuron]]s, can in principle be chosen to be any functions, but the typical choice is to choose each of them as a logistic regression model. In other words, the output of each artificial neuron is obtained by computing the logistic function of a linear combination (via an unknown parameter vector) of the inputs.&lt;br /&gt;
&lt;br /&gt;
===Maximum entropy (MaxEnt) models===&lt;br /&gt;
&lt;br /&gt;
Maximum entropy models generalize logistic regression to particular types of classification problems where the relative probabilities of the discrete classes satisfy a particular kind of mathematical relationship (the need for a constraint on the relationship arises only when there are three or more different possibilities; no assumptions are necessary in the binary case).&lt;/div&gt;</summary>
		<author><name>Vipul</name></author>
	</entry>
</feed>