<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ramraj Chandradevan on Medium]]></title>
        <description><![CDATA[Stories by Ramraj Chandradevan on Medium]]></description>
        <link>https://medium.com/@ramrajchandradevan?source=rss-acf289935f45------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jZdI7RAvcjlXs7OkqT-Zrw.jpeg</url>
            <title>Stories by Ramraj Chandradevan on Medium</title>
            <link>https://medium.com/@ramrajchandradevan?source=rss-acf289935f45------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 02:43:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramrajchandradevan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Comparison among Hyper-parameter Optimizers]]></title>
            <link>https://medium.com/@ramrajchandradevan/comparison-among-hyper-parameter-optimizers-cd37483cd47?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd37483cd47</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[scikit]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Thu, 31 Aug 2017 05:07:08 GMT</pubDate>
            <atom:updated>2020-06-19T15:08:01.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*bRcEE570pkYwOQRX0EPh9g@2x.png" /></figure><h3><strong>parameter :-</strong></h3><p>All the values that we set constant for our neural network are called paramers for example, we train a network and then using back propagation we drive the <strong>weight matrix</strong> and <strong>bias matrix</strong>. These final-trained values are set to constant and then the model is ready for testing.</p><h3>hyper-parameter :-</h3><p>They both sound similar, but hyper-parameters are chosen <strong>prior</strong> to the assignment of parameter values. That means we first train our network to find out how many layers we need, how many neurons per each layer, drop out ratio, etc. Then using these optimized hyper-parameter values we train our model with back propagation for parameter setting. Now this hyper-parameter optimized model is best among its family of ensemble models.</p><p><strong>EG.</strong></p><blockquote>learning rate</blockquote><blockquote>regularizers</blockquote><blockquote>strength of those regularizers</blockquote><blockquote>dimensionality of any hidden representations</blockquote><blockquote>number of decision trees (for random forest )</blockquote><blockquote>optimization algorithm (even could be)</blockquote><ul><li>Hyper-parameters <strong>selection</strong> has<strong> significant impact</strong> on <strong>model performance.</strong></li></ul><h4>Open-source hyper-parameter optimization packages,</h4><p><strong>1) Hyperopt -</strong></p><blockquote>explores hyper-parameter space strategically using “<strong>tree of Parzen estimators</strong>” (<strong>bayesian approach</strong>)</blockquote><p><strong>2) scikit-optimize -</strong></p><blockquote>new package</blockquote><blockquote>has 3 algorithms :-</blockquote><blockquote><strong>1. forest_minimize(decision tree regression search)</strong></blockquote><blockquote><strong>2. gbrt_minimize (gradient-boosted-tree regression search)</strong></blockquote><blockquote><strong>3. gp_minimize (Gaussian Process Regression Search)</strong></blockquote><p>Above 2 are most prominent methods.</p><p><strong>3) Spearmint</strong> -</p><p>under active development (license does <strong>not permit for commercial usage</strong>)</p><p><strong>4) MOE -</strong></p><p>growing as start-up</p><p>These packages, (benefit)</p><blockquote>1. can set up very large space of hyper-parameters to explore</blockquote><blockquote>2. can reduce the number of choices (heuristically made)</blockquote><ul><li>We compare the packages based on<strong> balance accuracy</strong> &amp;&amp; <strong>speed</strong>. (test scores)</li><li>The above both packages are based on <strong>Sequential model-based optimization.</strong>( at start samples small number of points from full hyper-parameter space, then run evaluations based on them)</li></ul><p><strong>5) </strong><a href="https://neptune.ai/blog/optuna-vs-hyperopt"><strong>Optuna</strong></a></p><h3>Baseline Method :-</h3><p>These are the conventional optimization methods, on which we couldn’t find any improvements on qualities. Here we take 2 baseline methods to compare with our 2 packages.</p><ol><li><strong>Grid Search -</strong></li></ol><ul><li>exhaustive search (will try every combination of each settings of hyper-parameters)</li><li>is <strong>guaranteed</strong> to find the best set of values(<strong>discrete</strong> version) in search space.</li><li>not tractable for large parameter space</li></ul><p><strong>2. Randomized Search -</strong></p><ul><li><strong>samples</strong> from full grid search</li><li><strong>doesn’t</strong> offer the same guarantee as grid search</li><li>extremely effective in practice</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*_p4D_BN0w2smNhyRY1dWrA.jpeg" /></figure><h3>Packages -</h3><ul><li>Basis for search is “<strong>dictionary mapping parameter names to values”</strong></li><li>we give a set of values for each key word. So this has <strong>one-to-many dictionary</strong> format.</li></ul><p>EG . for baseline methods</p><blockquote><strong><em>param_grid = {</em></strong></blockquote><blockquote><strong><em>‘max_depth’ : [4, 8, 12],</em></strong></blockquote><blockquote><strong><em>‘learning_rate’ : [0.01, 0.3, 0.5],</em></strong></blockquote><blockquote><strong><em>‘n_estimators’ : [20, 50, 200],</em></strong></blockquote><blockquote><strong><em>‘objective’ : [‘multi:softprob’],</em></strong></blockquote><blockquote><strong><em>‘gamma’ : [0, 0.25, 0.5],</em></strong></blockquote><blockquote><strong><em>‘min_child_weight’ : [1, 3, 5],</em></strong></blockquote><blockquote><strong><em>‘subsample’ : [0.1, 0.5, 1],</em></strong></blockquote><blockquote><strong><em>‘colsample_bytree’ : [0.1, 0.5, 1]}</em></strong></blockquote><ul><li>We provide full list of values for dict. The algorithm <strong>only search among them.</strong></li><li>Mostly, the model expands for large dataset or architecture. So dict expands to very large list. So the algorithms have to search for each combinations including <strong>cross-combinations</strong>. So grid search is not <strong>tractable</strong>.</li></ul><p>In <strong>Hyperopt</strong>, values are hyper-opt functions specifying <strong>distributions</strong> <strong>over</strong> <strong>parameter values.</strong></p><p>Search is then samples the distributions over the each values.</p><blockquote><strong><em>hyperopt_grid = {</em></strong></blockquote><blockquote><strong><em>‘max_depth’ : hp.choice(‘max_depth’, range(4, 13, 1)),</em></strong></blockquote><blockquote><strong><em>‘learning_rate’ : hp.quniform(‘learning_rate’, 0.01, 0.5, 0.01),</em></strong></blockquote><blockquote><strong><em>‘n_estimators’ : hp.choice(‘n_estimators’, range(20, 205, 5)),</em></strong></blockquote><blockquote><strong><em>‘objective’ : ‘multi:softprob’,</em></strong></blockquote><blockquote><strong><em>‘gamma’ : hp.quniform(‘gamma’, 0, 0.50, 0.01),</em></strong></blockquote><blockquote><strong><em>‘min_child_weight’ : hp.quniform(‘min_child_weight’, 1, 5, 1),</em></strong></blockquote><blockquote><strong><em>‘subsample’ : hp.quniform(‘subsample’, 0.1, 1, 0.01),</em></strong></blockquote><blockquote><strong><em>‘colsample_bytree’ : hp.quniform(‘colsample_bytree’, 0.1, 1.0, 0.01)}</em></strong></blockquote><p><strong>scikit-optimize</strong> only requires to specify the <strong>upper &amp;&amp; lower bound</strong> for the search space.</p><p><strong>scikit-opt</strong> wants <strong>lists of lists of values</strong>, rather than just dict.</p><p>So hard to keep track of which parameters are being specified.</p><p>The packge code handles internal conversions for <strong>dict — -&gt; list</strong> &amp;&amp; <strong>list — -&gt; dict.</strong></p><blockquote><strong><em>skopt_grid = {</em></strong></blockquote><blockquote><strong><em>‘max_depth’: (4, 12),</em></strong></blockquote><blockquote><strong><em>‘learning_rate’: (0.01, 0.5),</em></strong></blockquote><blockquote><strong><em>‘n_estimators’: (20, 200),</em></strong></blockquote><blockquote><strong><em>‘objective’ : Categorical((‘multi:softprob’,)),</em></strong></blockquote><blockquote><strong><em>‘gamma’: (0, 0.5),</em></strong></blockquote><blockquote><strong><em>‘min_child_weight’: (1, 5),</em></strong></blockquote><blockquote><strong><em>‘subsample’: (0.1, 1),</em></strong></blockquote><blockquote><strong><em>‘colsample_bytree’: (0.1, 1)}</em></strong></blockquote><h3>Experimental Set-up :-</h3><p>This will make <strong>max use of available data</strong> (whether its small or large)</p><p><strong>1 ) Outer five-fold cross-validation</strong></p><p>the full dataset is divided into five sections (folds). This creates five experimental settings, in which we train on four of the folds (merged together) and test on the fifth.</p><p><strong>2 ) Inner five-fold cross-validation</strong></p><p>For each experimental setting, the training set is used to find the optimal hyperparameters — for each setting of the hyperparameters, a full round of five-fold cross-validation is performed using only the training data.</p><p><strong>3 ) hybrid</strong></p><p>The hyperparameter setting that does best at step 2 is the basis for the model that is used for testing in the outer cross-validation.</p><blockquote><strong><em>For each (train_folds, test_fold) in the outer cross-validation:</em></strong></blockquote><blockquote><strong><em>For each setting S of the hyperparameters:</em></strong></blockquote><blockquote><strong><em>Cross-validate S on train_folds</em></strong></blockquote><blockquote><strong><em>Let S* be the setting that did best in the inner loop.</em></strong></blockquote><blockquote><strong><em>Use S* to assess on test_fold.</em></strong></blockquote><ul><li>Here if we considered the <strong>parallelization</strong>, then the <strong>performance</strong> for each packages and baseline will be <strong>different</strong>.</li></ul><p>We can <strong>segment</strong> and provide data sets to <strong>each algorithms</strong> for better performance.</p><blockquote><strong><em>full_experimental_run = [</em></strong></blockquote><blockquote><strong><em>(grid_search, param_grid, {}),</em></strong></blockquote><blockquote><strong><em>(random_search, param_grid, {‘sampsize’: None}),</em></strong></blockquote><blockquote><strong><em>(hyperopt_search, hyperopt_grid, {‘max_evals’: 100}),</em></strong></blockquote><blockquote><strong><em>(skopt_gp_search, skopt_grid, {‘n_calls’: 100}),</em></strong></blockquote><blockquote><strong><em>(skopt_forest_search, skopt_grid, {‘n_calls’: 100}),</em></strong></blockquote><blockquote><strong><em>(skopt_gbrt_search, skopt_grid, {‘n_calls’: 100})]</em></strong></blockquote><ul><li>Usually, from experiments the the time taken is,(in <strong>fast measurement</strong>)</li></ul><blockquote>2 packages &gt; &gt; grid search</blockquote><blockquote>2 packages &gt; random_search</blockquote><ul><li>Random search <strong>strongly</strong> shows the <strong>brute-force approach.</strong></li></ul><p>Experiment should be conducted on cases of,</p><blockquote><strong>Small datasets</strong></blockquote><blockquote><strong>Small features, but large observations</strong></blockquote><blockquote><strong>large features, but small observations</strong></blockquote><blockquote><strong>Large datasets</strong></blockquote><h3>Summary :-</h3><p><strong><em>— No big difference between Hyperopt &amp;&amp; scikit-opt. They consistently perform better &amp;&amp; deliver more effective models faster &amp;&amp; easy to use.</em></strong></p><p><strong><em>— But clearly better than baseline approaches.</em></strong></p><p><strong><em>— These baseline approaches needlessly expensive.</em></strong></p><h3>References :-</h3><ol><li><a href="https://roamanalytics.com/2016/09/15/optimizing-the-hyperparameter-of-which-hyperparameter-optimizer-to-use/">https://roamanalytics.com/2016/09/15/optimizing-the-hyperparameter-of-which-hyperparameter-optimizer-to-use/</a></li><li><a href="http://www.cs.ubc.ca/~hutter/papers/11-LION5-SMAC.pdf">http://www.cs.ubc.ca/~hutter/papers/11-LION5-SMAC.pdf</a></li><li>MOE — <a href="https://github.com/Yelp/MOE">https://github.com/Yelp/MOE</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd37483cd47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Radial Basis Functions Neural Networks — All we need to know]]></title>
            <link>https://medium.com/data-science/radial-basis-functions-neural-networks-all-we-need-to-know-9a88cc053448?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a88cc053448</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 04:32:31 GMT</pubDate>
            <atom:updated>2017-08-18T04:32:31.865Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*U5y_-UuqGe1lxdgisM32xw.png" /></figure><p>⁃ In <strong>Single Perceptron</strong> / <strong>Multi-layer Perceptron(MLP)</strong>, we only have linear separability because they are composed of input and output layers(some hidden layers in MLP)</p><p>⁃ For example, AND, OR functions are <strong>linearly</strong>-separable &amp; XOR function is <strong>not</strong> linearly separable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*CyGlr8VjwtQGeNsuTUq3HA.jpeg" /><figcaption>Linear-separability of AND, OR, XOR functions</figcaption></figure><p>⁃ We atleast need <strong>one hidden layer</strong> to derive a non-linearity <strong>separation</strong>.</p><p>⁃ Our RBNN what it does is, it transforms the input signal into another form, which can be then <strong>feed</strong> into the network to <strong>get linear separability.</strong></p><p>⁃ RBNN is <strong>structurally</strong> <strong>same</strong> as perceptron(MLP).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*aNeBDke8kLPPCuu29tq-Nw.jpeg" /><figcaption>Distinction between MLP and RBF</figcaption></figure><p>⁃ RBNN is composed of <strong>input, hidden,</strong> and <strong>output</strong> layer. RBNN is <strong>strictly limited</strong> to have exactly<strong> one hidden layer</strong>. We call this hidden layer as <strong>feature vector.</strong></p><p>⁃ RBNN <strong>increases dimenion</strong> of feature vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*umho3WaIXmB2qBoHTgw0MA.gif" /><figcaption>Simplest diagram shows the architecture of RBNN</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*kBCuq8ckCo67oyEiPW9Pdg.jpeg" /><figcaption>Extended diagram shows the architecture of RBNN with hidden functions.</figcaption></figure><p>⁃ We apply <strong>non-linear transfer function</strong> to the feature vector before we go for <strong>classification problem.</strong></p><p>⁃ When we increase the dimension of the feature vector, the linear separability of feature vector increases.</p><blockquote>A non-linearity separable problem(pattern classification problem) is highly separable in high dimensional space than it is in low dimensional space.</blockquote><blockquote>[<strong><em>Cover’s Theorem</em></strong>]</blockquote><p>⁃ What is a Radial Basis Function ?</p><blockquote>⁃ we define a receptor = t</blockquote><blockquote>⁃ we draw confrontal maps around the receptor.</blockquote><blockquote>⁃ Gaussian Functions are generally used for Radian Basis Function(confrontal mapping). So we define the radial distance r = ||x- t||.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/1*AdPrlGRh6usbZNgFWTWaEQ.jpeg" /><figcaption>Radial distance and Radial Basis function with confrontal map</figcaption></figure><p>Gaussian Radial Function :=</p><blockquote>ϕ(r) = exp (- r²/2<strong>σ²</strong>)</blockquote><blockquote>where σ &gt; 0</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*c6KMMqfhmXdJda9LBGmhJw.png" /><figcaption>Classification only happens on the second phase, where linear combination of hidden functions are driven to output layer.</figcaption></figure><h3>⁃ Example. XOR function :-</h3><p>⁃ I have 4 inputs and I will not increase dimension at the feature vector here. So I will select 2 receptors here. For each transformation function ϕ(x), we will have each receptors t.</p><p>⁃ Now consider the RBNN architecture,</p><blockquote>⁃ P := # of input features/ values.</blockquote><blockquote>⁃ M = # of transformed vector dimensions (hidden layer width). So M ≥ P usually be.</blockquote><blockquote>⁃ Each node in the hidden layer, performs a set of non-linear radian basis function.</blockquote><blockquote>⁃ Output C will remains the same as for the classification problems(certain number of class labels as predefined).</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHaXRnx9Tj5LkxqynnGoSw.png" /><figcaption>Architecture of XOR RBNN</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8nLnA4vPDRJOBV7H4tv5cQ.png" /><figcaption>Transformation function with receptors and variances.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MVVBo_E4SBodjPXreMbJVw.png" /><figcaption>Output → linear combination of transformation function is tabulated.</figcaption></figure><p>⁃ Only Nodes in the hidden layer perform the radian basis transformation function.</p><p>⁃ Output layer performs the linear combination of the outputs of the hidden layer to give a final probabilistic value at the output layer.</p><p>⁃ So the classification is only done only @ <strong><em>(hidden layer → output layer)</em></strong></p><h3>Training the RBNN :-</h3><p>⁃ <strong>First</strong>, we should train the <strong>hidden layer</strong> using <strong>back propagation.</strong></p><p>⁃ Neural Network training(back propagation) is a <strong>curve fitting method</strong>. It <strong>fits</strong> a <strong>non-linear curve</strong> during the <strong>training</strong> phase. It runs through stochastic approximation, which we call the back propagation.</p><p>⁃ For each of the node in the hidden layer, we have to find <strong>t</strong>(receptors) &amp; the variance (<strong>σ</strong>)[variance — the spread of the radial basis function]</p><p>⁃ On the <strong>second</strong> training phase, we have to <strong>update</strong> the <strong>weighting vectors </strong>between <strong>hidden layers &amp; output layers.</strong></p><p>⁃ In hidden layers, <strong>each</strong> node represents <strong>each</strong> transformation basis function. <strong>Any</strong> of the function could satisfy the non-linear separability OR even <strong>combination</strong> of set of functions could satisfy the non-linear separability.</p><p>⁃ So in our hidden layer transformation, all the non-linearity terms are included. Say like X² + Y² + 5XY ; its all included in a hyper-surface equation(X &amp; Y are inputs).</p><p>⁃ Therefore, the first stage of training is done by <strong>clustering algorithm.</strong> We define the <strong>number of cluster centers</strong> we need. And by clustering algorithm, we compute the cluster centers, which then is assigned as the <strong>receptors</strong> for each hidden neurons.</p><p>⁃ I have to cluster N samples or observations into M clusters (N &gt; M).</p><p>⁃ So the output “clusters” are the “receptors”.</p><p>⁃ for each receptors, I can find the variance as “<strong>the squared sum of the distances between the respective receptor &amp; the each cluster nearest samples</strong>” := 1/N * ||X — t||²</p><p>⁃ The interpretation of the first training phase is that the <strong>“feature vector is projected onto the transformed space”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*cwfZauLq5T97ha_5-kQQag.gif" /><figcaption>Complex diagram depicting the RBNN</figcaption></figure><h4>Advantages of using RBNN than the MLP :-</h4><blockquote>1. Training in RBNN is <strong>faster</strong> than in Multi-layer Perceptron (MLP) → takes <strong>many interactions</strong> in MLP.</blockquote><blockquote>2. We can easily interpret what is the meaning /<strong> function of the each node</strong> in hidden layer of the RBNN. This is <strong>difficult</strong> in MLP.</blockquote><blockquote>3. (what should be the # of nodes in hidden layer <strong>&amp;</strong> the # of hidden layers) this <strong>parameterization</strong> is difficult in MLP. But this is not found in RBNN.</blockquote><blockquote>4. <strong>Classification</strong> will take more time in RBNN than MLP.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a88cc053448" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/radial-basis-functions-neural-networks-all-we-need-to-know-9a88cc053448">Radial Basis Functions Neural Networks — All we need to know</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Random Forest Learning-Essential Understanding]]></title>
            <link>https://medium.com/data-science/random-forest-learning-essential-understanding-1ca856a963cb?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ca856a963cb</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random-forest]]></category>
            <category><![CDATA[decision-tree]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Tue, 15 Aug 2017 13:47:56 GMT</pubDate>
            <atom:updated>2017-08-18T19:23:49.919Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*RZ1RKBwhLxZM6SRX5Nc4Rw.png" /></figure><p><strong>&gt;&gt;uses&gt;&gt;</strong> Decision Tree Model for Parameterization</p><p><strong>&gt;&gt;integrates&gt;&gt; </strong>3 techniques,</p><blockquote><strong>1. a Sampling Technique,</strong></blockquote><blockquote><strong>2. a Subspace Method, and</strong></blockquote><blockquote><strong>3. an Ensemble Approach</strong></blockquote><blockquote>to <strong>optimize</strong> the model building</blockquote><p><strong>** sampling approach** :=</strong> <strong>bootstrap</strong>; adopts a <strong>Random</strong> Sampling Approach with <strong>Replacement</strong>.</p><p><strong>** subspace method** :=</strong> also adopts a <strong>Random</strong> Sampling approach,</p><p>but helps extract <strong>smaller</strong> subsets(subspaces) of features.</p><p>helps to build decision tree based on them.</p><p>select decision trees for the random forest construction.</p><p><strong>** ensemble approach **:=</strong> based on <strong>bagging</strong> approah; helps to build <strong>classifiers</strong>.</p><h3>1.1 Random Forest(RF)</h3><p>Tress can be</p><blockquote><strong>1. classification tress</strong></blockquote><blockquote><strong>2. regression trees</strong></blockquote><p>So RF can be applied to both.</p><ul><li><strong>decision</strong> tree provides <strong>single</strong> trained decision tree classifier for the <strong>testing</strong> phase.</li><li>But <strong>RF</strong> provides <strong>multiple</strong> trained DT classifiers for the <strong>testing</strong> phase.</li><li>This property makes RF more preferred <strong>over</strong> regular DT learning.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1afuFrLP1talkzXk5425bA.png" /><figcaption>The construction of a Decision Tree using 1-D data domain &amp; bootstrap sampling.</figcaption></figure><h3>1.1.1 Parallel Structure</h3><ul><li><strong>Parallelization</strong> is one of the contributing properties of the RF toward the “<strong><em>enhanced classification performances</em></strong>”.</li><li>DT can be built at the <strong>same time</strong> for classssification for the RF modeling.</li><li>This RF parallel structure can help for <strong>Big Data Classification.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wirwWILVOTxVWkuf-MaBMw.png" /><figcaption>The parallelization feature of the random forest technique</figcaption></figure><h3>1.1.2 Model Parameters</h3><ul><li>Parameterization of RF includes the <strong>parameterization</strong> of a <strong>DT model </strong>becasue it adopts the other one inside.</li><li>Therefore, RF model consists of the parameters of DT, but has some more <strong>new</strong> parameters too.</li></ul><p>eg. # of <strong>feature subsets</strong>, selected for the # of DTs for the construction of RF</p><h3>1.1.3 Gain/Loss Function</h3><ul><li>parameters are optimized based on</li></ul><blockquote><strong>1. bootstrap sampling</strong></blockquote><blockquote><strong>2. subspace integration</strong></blockquote><p>in the model building</p><ul><li>Tree building uses the <strong>same quantitative measures</strong> as used in DTs to select best features, eg.</li></ul><blockquote><strong>1. Entropy</strong></blockquote><blockquote><strong>2. Gini Impurity</strong></blockquote><blockquote><strong>3. Information Gain</strong></blockquote><h3>1.1.4 Bootstrapping &amp; Bagging</h3><ul><li>for optimizing the classification objectives,</li></ul><blockquote><strong>1. statistical measures,</strong></blockquote><blockquote><strong>2. bootstrapping,</strong></blockquote><blockquote><strong>3. bagging</strong></blockquote><p>plays important roles in RF learning.</p><h3>1.1.4.1 Bootstrapping (BS)</h3><ul><li>BS is a<strong> simple randomization</strong> technique.</li><li>Its effect in RF is <strong>magnificent.</strong></li><li>It selects <strong>several</strong> <strong>subsets</strong> from a set of data by randomly selecting, but totally the same # of observations as in the original data set, but <strong>with</strong> <strong>replacement</strong>.</li><li>So some observations can be appeared <strong>many times</strong> in a subset of the data set.</li><li>Notion :-</li></ul><blockquote>maximize the “class-distance” at each intermediate node &amp; the leaves of the DT.</blockquote><ul><li><strong>BS</strong> is applied @ the <strong>training phase </strong>of the RF algorithm.</li></ul><h3>1.1.4.2 Overlap Thinning</h3><ul><li>BS brings some effects to a data domain.</li><li>BS generates <strong>several domains</strong> where the “<strong>classes</strong>” may be “<strong>isolated</strong>” more than the original data domain.</li><li>The classes in these <strong>isolated data domains</strong> can be <strong>easily separated</strong> by <strong>single splits.</strong></li><li>Sometimes we may <strong>not need splitting.</strong></li></ul><h3>1.1.4.3 Bagging</h3><ul><li>means the <strong>averaging</strong> of the <strong>prediction</strong>(classification) <strong>responses</strong>, the BS samples gave, to obtain <strong>final</strong> prediction result.</li><li>Bagging came from <strong><em>Bootstrap Aggregating.</em></strong></li><li>BS creates <strong>multiple</strong> domains with “<strong><em>simple class overlap thinning</em></strong>”, these domains help create <strong>multiple classification models</strong>, and the multiple classification models allow the <strong>testing algorithm</strong> to evaluate the <strong>performance of the classifiers efficiently.</strong></li><li>Bagging is applied at the <strong>testing phase</strong> of the RF algorithm.</li></ul><h3>1.2 Random Forest Learning Model</h3><ul><li>achieves <strong>parameterization</strong> objectives &amp; <strong>optimization</strong> objectives.</li></ul><h3>1.2.1 Parameterization</h3><ul><li>parameters,</li></ul><blockquote><strong>1. # of domains generated using bootstrapping — A.</strong></blockquote><blockquote><strong>2. size of the subspace for each node(domain) — B.</strong></blockquote><blockquote><strong>3. threshold for a domain split — C.</strong></blockquote><ul><li><strong>Goal</strong> of parameterization:-</li></ul><blockquote>we need to find or suggest possible values for the parameters.</blockquote><ul><li>usual value for <strong>A</strong> is <strong>10</strong>.</li></ul><p>But it is appropriate to conduct “<strong>cross-validation</strong>” and determine a suitable <strong>range of values.</strong></p><ul><li>for the B selection, there is <strong>2 constraints.</strong></li><li>first recommendation is <strong>n &lt;&lt; p</strong> &amp; it must be kept contant throughout the construction of DT.</li><li>second constriant, <strong>n &lt;= sqrt(p); </strong>we have <strong>p features</strong> in the original data domain. <strong>n </strong>of them are <strong>good ones. </strong>Fraction of good ones in <strong>n/p. </strong>Among them <strong>one</strong> of the feature is <strong>best</strong> one, its fraction among good ones is <strong>1/n.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/194/1*epbwvcen8XedKb3QXEkQaA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*cbrCdWE8dAFqz4RprsTXTA.png" /></figure><ul><li>people use <strong>sqrt(p)</strong> as the <strong># of features for random selection.</strong></li></ul><h3>1.2.2 Optimization</h3><blockquote>once the parameters are selected, the model is parameterized. Then the parameters must be optimized.</blockquote><ul><li>But in RF parameterization &amp; optimization are <strong>nested</strong>, &amp; they are <strong>performed at the same time.</strong></li><li>Optimization has been done <strong>at each node of the tree.</strong></li><li>Major players for the RF optimization are the <strong>Gini index(entropy)</strong> &amp; the <strong>information gain</strong>.</li></ul><h3>1.3 Random Forest Learning Algorithm</h3><ul><li>consists 3 parts as any other machine learning algorithms; <strong><em>training, validation, and testing.</em></strong></li><li><strong>Cross-validation</strong> is already <strong>included</strong> in the <strong>training agorithm.</strong></li><li>So <strong>no</strong> <strong>separate</strong> <strong>validation</strong> algorithm is needed for RF technique.</li></ul><h4>SIMPLY :-</h4><blockquote>RF learning gives us several spaces (best feature combinations), where the best domain divisions can be performed &amp; high classification accuracies can be obtained.</blockquote><ul><li>Therefore, RF classification objective is divided into <strong>only</strong> <strong>training &amp; testing</strong> algorithms.</li></ul><h3>1.3.1 Training Algorithm</h3><ul><li>This provides a <strong>systematic</strong> approach to develop <strong>multiple classifiers</strong>(DTs) so that testing algorithm uses multiple classifiers to select the <strong>best way to classify the new data.</strong></li></ul><h4>Step 1 :: —</h4><p>— <strong>multiple</strong> subspaces are created for given data.</p><p><strong>r &lt;= sqrt(p)</strong></p><blockquote><em>p = # of features ;</em></blockquote><blockquote><em>r = dim of subspaces</em></blockquote><h4>Step 2 :: —</h4><p>— we have <strong>significantly smaller r</strong> (<strong><em>dimensional subspace</em></strong>), so we can find the <strong>best feature</strong> &amp; <strong>best split location(</strong>domain division) for the <strong>root node </strong>using the DT building process.</p><blockquote>[But we DO NOT perform this process to this subspace, so skip to next step]</blockquote><h4>Step 3 :: —</h4><p>— <strong>alter</strong> the subspace <strong>randomly</strong> using bootstrap samples &amp; create multiple <strong>bootstrap-subspaces</strong>, where the <strong>overlap thinning</strong> occured in data domains.</p><h4><strong>Step 4 :: —</strong></h4><p>— construct nodes for the DTs by applying DT algorithm to find best feature &amp; the best split location for each bootstrap-subspace.</p><h4>Step 5 :: —</h4><p>— Now we have a DT(classifier) for each bootstrap sample.</p><p>— These trees can be used by the <strong>testing</strong> algorithm to <strong>classify</strong> the <strong>new</strong> data.</p><p><strong>Advantages of RF over DT,</strong></p><blockquote>1. multiple DTs are available for classification at the test space <strong>=&gt;</strong> will <strong>increase</strong> the <strong>classification accuracy.</strong></blockquote><blockquote>2. bootstrap samples are used for multiple DTs, which will help increase the “<strong>sharpening</strong>” of the <strong>classification boundary </strong>through <strong>overlap thinning.</strong></blockquote><blockquote>3. the <strong>exhaustive search</strong> done for finding the best feature &amp; best split location in the entire space is <strong>eliminated</strong> by the subspace search <strong>=&gt;</strong> <strong>small additional computational cost</strong> in <strong>bootstrap sampling. </strong>(<em>Computational Advantages</em>)</blockquote><h3>1.3.2 Testing Algorithm</h3><ul><li>Testing requires the <strong>entire</strong> RF can be <strong>constructed using several bootstrap samples(10)</strong> in early. So then the <strong>labelling process</strong> can be started.</li><li><strong>Steps</strong>,</li></ul><h4>1. Feature Selection :</h4><p>the <strong>correct sequence of features</strong> from the <strong>incoming data</strong> for the nodes of the trees must be “<strong>observed</strong>”.</p><h4>2. Tree Selection :</h4><p>we have <strong>N</strong> number of RF classifiers. So we <strong>push</strong> the <strong>new</strong> data <strong>according to the features</strong> through all of the DTs &amp; obtain its class labels.</p><h4>3. Bagging :</h4><p>trees selected in the previous step are used to find the <strong>aggregate of the results</strong> obtained (<strong>bagging technique</strong>)</p><p>Finally, we can conclude the new observation belongs to a specific label by <strong><em>voting mechanism</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*W70TAcPDXVexTL6JNED6OA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*V1gaYbSzecaGE7s6WVIcsQ.png" /></figure><h3>Random Forest Scalability</h3><ul><li>In typical <strong>data science application,</strong></li></ul><p><strong># of features is fixed.</strong></p><p>RF technique selects a subspace from them &amp; builds the “<strong>depth-first decision trees</strong>” based on bootstrapping to construct RF.</p><ul><li>But in <strong>Big Data,</strong></li></ul><p><strong>feature set can dynamically “grow”.</strong></p><ul><li>The problem can be handled by building “<strong>breadth-first decision trees”. </strong>Here the DTs were build in <strong>parallel</strong>.</li></ul><p>However, in <strong>depth-first</strong> &amp; <strong>conventional RF</strong>, the DTs are build one after the other DT is completely constructed.</p><h3><strong>Reference :-</strong></h3><p><strong><em>Machine Learning Models and Algorithms for Big Data Classification, Shan Suthaharan; Chapter 11 — Random Forest Learning</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ca856a963cb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/random-forest-learning-essential-understanding-1ca856a963cb">Random Forest Learning-Essential Understanding</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decision Tree Learning-Essential Understanding]]></title>
            <link>https://medium.com/@ramrajchandradevan/decision-tree-learning-essential-understanding-fd05158f0ca4?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd05158f0ca4</guid>
            <category><![CDATA[decision-tree]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Mon, 14 Aug 2017 18:33:24 GMT</pubDate>
            <atom:updated>2017-08-14T18:33:24.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*McD6MUj47Gq71xAdvSTImg.png" /></figure><p>Frequent terminologies,</p><blockquote>Data Domain := node</blockquote><blockquote>Events := Observations</blockquote><blockquote>Subdomains := leaves of current tree</blockquote><ul><li><strong>Hierarchical</strong> supervised learning models.</li><li><strong>Main</strong> hierarchical model is DECISION TREE.</li><li>It has 2 categories,</li></ul><blockquote><strong><em>1. Classification Tree</em></strong></blockquote><blockquote><strong><em>2. Regression Tree</em></strong></blockquote><blockquote>for building decision tree <strong><em>— — &gt;</em></strong> tree split algorithms</blockquote><blockquote>for building efficient tree via training<strong> — — &gt;</strong> requires quantitative measures</blockquote><ul><li>These measures are,</li></ul><blockquote><strong>1. entropy</strong></blockquote><blockquote><strong>2. cross-entropy</strong></blockquote><blockquote><strong>3. Gini impurity</strong></blockquote><blockquote><strong>4. Information Gain</strong></blockquote><ul><li>Discussion of “<strong>training algorithms” </strong>is suitable for both classification &amp; regression trees.”</li></ul><h3>Decision Tree</h3><ul><li>Defined as “<strong>rule-based, binary-tree building technique</strong>.”</li><li>But easier to INTERPRET as a “<strong>hierarchical domain division technique.”</strong></li><li>Is a<strong> supervised learning model,</strong> which HIERARCHICALLY “<strong>maps</strong>” a <strong><em>DATA DOMAIN</em></strong> onto a <strong><em>RESPONSE SET.</em></strong></li><li>Divides a <strong>data domain(node)</strong> <em>recursively</em> into 2 sub domains(have HIGHER information gain) THAN was before split.</li><li>GOAL of SUPERVISED learning <strong>====&gt;</strong> Classification of Data</li><li>Information Gain<strong><em> — — means — →</em></strong> EASE of classification in the subdomains (created by split).</li><li>Optimization Algorithms <strong><em>— -GOAL — — -&gt;</em></strong> find the best split (giving <strong>max</strong> infromation gain).</li></ul><blockquote><strong>Data Domain := D (in sorted list)</strong></blockquote><blockquote><strong>Class Lables := L (corresponding)</strong></blockquote><blockquote><strong>Information Gain := <em>Ii</em></strong></blockquote><blockquote><strong>The 2 Sub Domains = D1, D2</strong></blockquote><blockquote><strong>The 2 Domain Labels = L1, L2</strong></blockquote><blockquote><strong>Best split = m</strong></blockquote><ul><li><strong>Spread</strong> (or <strong>Distribution Pattern</strong>) over the class labels → determines the <strong>ease</strong> of classification.</li><li>If m is considered as the best split,</li></ul><blockquote>average (Ii1, Ii2) &gt; Ii</blockquote><p>Here Ii1, Ii2 are the information gains of the 2 subdomains derived after first previous split.</p><ul><li>We need a <strong>GOOD qualitative measure</strong> for <strong>measuring Information Gain.</strong></li><li><strong>p0, p1</strong> =&gt; <strong>probabilities</strong> class 0, 1 drawn from the domain D.</li></ul><blockquote>|p0 — p1| — — &gt; 1</blockquote><blockquote>— one particular class DOMINATES highly in that domain.</blockquote><blockquote>— domain DIVISION is NOT required.</blockquote><p>On the other hand,</p><blockquote>|p0 — p1| — — &gt; 0</blockquote><blockquote>class have equal domination in that domain</blockquote><blockquote>further split is needed</blockquote><p>1)</p><ul><li><strong>q0, q1 </strong>=&gt; <strong>probabilities</strong> class 0, 1 drawn from <strong>subdomain</strong> D1.</li><li>If our Split is <strong>Efficient</strong>,</li></ul><blockquote><strong>q0 &gt; p0</strong></blockquote><blockquote><strong>OR</strong></blockquote><blockquote><strong>q1 &gt; p1</strong></blockquote><p>2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*vsmpjhgxNHXku2-BdATzPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*EjNS0nBVd3h4ZvvXfkx1_Q.png" /></figure><p>3)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/1*MRfEXiu1OpOO-qF1BamU6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*h91JtMiZFo4NUoCC1vVZuQ.png" /></figure><p>— The <strong>absolute differences</strong> are QUANTITATIVE MEASURES that measures <strong>PROPORTIONALITY</strong> between the <strong>classes</strong> in respective SUBdomains.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_uwaQVDx2KKbwrIOU43QQ.png" /><figcaption>General picture describes the decision tree mechanism with numerical example.</figcaption></figure><h3>Types of Decision Trees</h3><ul><li>Classification Decision Tree — — &gt; <strong>predict</strong> a <strong>class label (</strong>discrete)</li><li>Regression Decision Tree — — &gt; helps <strong>predict</strong> a <strong>value</strong> (continuous)</li></ul><blockquote>for a response variable</blockquote><h3>Classification Tree</h3><ul><li>We need to construct the <strong>tree</strong> at the <strong>training phase.</strong></li><li>The <strong>propagation of tree split</strong> divides <strong>data domain.</strong></li><li>“<strong>generation</strong>” of SIMPLE, MULTIPLE, THIN layers of data domains consists of SPLIT-REGIONS.</li><li>The <strong>classified</strong> subdomains should be differnet “<strong>Disjoint Subdomains</strong>”.</li><li>Main Parameters,</li></ul><p>— — “<strong>values of the features</strong>” used to split tree at a particular node.</p><p>— — these parameters <strong>TRAINED</strong> using INFORMATION GAIN as quantitative measure.</p><p>— — combination of selected parameters — — &gt; <strong>classifier</strong></p><ul><li>Subdomains(<strong>leaves of current tree</strong>) also have “<strong>Class information</strong>”</li><li>“<strong>split criterion</strong>” needs “<strong>decision parameters</strong>” that <strong>form</strong> the <strong>classification model.</strong></li><li><strong>Decision</strong> parameters := a <strong>feature</strong> &amp; its <strong>split location</strong></li></ul><p>— — — — — by <strong>maximizing</strong> the information gain</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ht8kCkneBfvqn8DLBW2ZaQ.png" /><figcaption>The Classification Tree is given here in 3D using 2 classes with domain division properties. Response variable Y has 2 discrete values, red &amp; blue.</figcaption></figure><h3>Regression Tree</h3><ul><li>It helps to <strong>assign a value</strong> for new data.</li><li>It divides data domain into <strong>disjoint</strong>, <strong>rectangular</strong> subdomains by “<strong>splitting features</strong>”, &amp; <strong>MAPS</strong> the subdomains to <strong>NON-EVERLAPPING </strong>groups of <strong>RESPONSES</strong> that are <strong>ESTIMATED</strong> with <strong>minimum</strong> ERROR criterion.</li><li>Method has 4 tasks,</li></ul><blockquote><strong>1. feature selection for a node.</strong></blockquote><blockquote><strong>2. parameterization of the split location.</strong></blockquote><blockquote><strong>3. parameterization of the depth of tree</strong></blockquote><blockquote><strong>4. estimation of the response variables.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fWDrNh-2SQB3CXxZLlrhAA.png" /><figcaption>The Regression Tree is given here in 3D using 2 classes with domain division properties. Response variable Y has 2 contiunous values, red &amp; blue.</figcaption></figure><h3>Decision Tree Learning Model</h3><ul><li>Modeling<strong> — -means — -&gt;</strong> <strong>definition</strong> of a function Or <strong>MAPPING</strong> between a <strong>DATADOMAIN</strong> and a <strong>RESPONSE</strong> set, followed by <strong>PARAMETERIZATION</strong> of the <strong>model</strong> &amp; the <strong>OPTIMIZATION</strong> of the <strong>parameters</strong>.</li></ul><h4>Parameterization :-</h4><p>— a “<strong>supervised model</strong>” must be <strong>PARAMETERIZED</strong> so that it can be <strong>TRAINED, VALIDATED, &amp; TESTED </strong>(This is true for decision tree too).</p><blockquote>— how to parameterize tree like structure? how to find the parameters?</blockquote><p>— In parameter building,</p><blockquote>-nodes are split,</blockquote><blockquote>-leaves are generated</blockquote><p><strong><em>recursively.</em></strong></p><p>— we can parameterize,</p><blockquote><strong><em>1. the coise of features for a node.</em></strong></blockquote><blockquote><strong><em>2. the threshold that splits the node and divides the feature set into 2 subsets.</em></strong></blockquote><blockquote><strong><em>3. the number of levels that the entire tree should have.</em></strong></blockquote><blockquote><strong><em>[4. features.]</em></strong></blockquote><h4>— <strong>parameterization :-</strong></h4><p><strong><em>*parameter1*</em></strong> select the <strong>features</strong> for the root node &amp; intermediate nodes.</p><blockquote>1. Can be chosen randomly</blockquote><blockquote>2. May select a feature that gives max information gain/Error Reduction</blockquote><p><strong><em>*parameter2*</em></strong> parameter for <strong>splitting criterion,</strong></p><blockquote>1. may select the “statistical techniques; mean/ median” to find the split location</blockquote><blockquote>2. find split location, that give an accepatble information gain.</blockquote><p><strong><em>*parameter3*</em></strong> select a parameter to <strong>STOP</strong> tree <strong>BUILDING</strong>. <strong>==&gt;</strong> # of <strong>levels</strong> in decision tree := is a parameter.</p><h4><strong>— Optimization :-</strong></h4><p>** select an ALGORITHMS that helps to optimize the parameters <strong>==&gt;</strong> <strong>final</strong> decision tree is <strong>OPTIMAL</strong> <strong>==&gt;</strong> <strong>tree can perform very good PREDICTION</strong></p><p>** may lead to a <strong>computationally</strong> <strong>expensive</strong> process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MN2v9ggUhaCXzlCJn5unmQ.png" /><figcaption>The process of selecting the best features(with its split locaiton) that gives the max information gain (i = 1,2,…, n)</figcaption></figure><h4>OPTIMIZATION :-</h4><ul><li><strong>divides</strong> decision tree <strong>EFFICIENTLY</strong> in <strong>training</strong>.</li><li>This determines which <strong>feature</strong> must be selected <strong>FIRST</strong> to <strong>start</strong> building the tree?</li></ul><p>Which feature must be selected <strong>@ INTERMEDIATE</strong> <strong>steps</strong> of tree building?</p><ul><li>Therefore, we need a GOOD Quantitative Measure</li><li>Tree building <strong>— -means — -&gt;</strong> generating <strong>LEAVES/ BRANCHES</strong> from a <strong>node</strong>, by carrying out the algorithm <strong>ITERATIVELY</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NNwlKaL_yEyReAK3CqsMnw.png" /><figcaption>The process of finding the best split location using the max information gain.</figcaption></figure><h3>Quantitative MEASURES</h3><ul><li>We need Quantitative measures in 2 places,</li></ul><blockquote>1. to measure information gain while splitting</blockquote><blockquote>2. to measure SIGNIFICANCE in the class difference in each node to decide further split.</blockquote><ul><li>For a useful measures, the requirements are,</li></ul><blockquote>1. first requirements</blockquote><blockquote><strong>1. entropy</strong></blockquote><blockquote><strong>2. Gini impurity</strong></blockquote><blockquote><strong>3. information gain</strong></blockquote><blockquote>2. second requirement</blockquote><blockquote><strong>1. class proportions</strong></blockquote><blockquote><strong>2. count differences</strong></blockquote><blockquote><strong>3. probability measures (ratios &amp; percentages)</strong></blockquote><h3><strong>ENTROPY &amp; CROSS-ENTROPY</strong></h3><ul><li>based on “<strong>proportionality of the events.</strong>”</li><li>if one event occurs more than another event in a <strong>PLACE</strong> or with an <strong>OBJECT</strong>,</li></ul><blockquote>then we <strong>HAVE A GOOD KNOWLEDGE </strong>about that <strong>PLACE</strong> or <strong>OBJECT</strong> <strong>relative</strong> to the<strong> MAJORITY event.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*2AzFFk2zkelfbbBgGxXJsQ.png" /><figcaption>Pi is the probability of the i th event.</figcaption></figure><ul><li>if both events occur the <strong>same NUMEBR of times</strong> in that PLACE or with the OBEJCT, then it is <strong>HARD to Characterize.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3XhlGLKtb0_BS9grP6n82A.png" /><figcaption>Entropy Graph without &amp; with ERROR FACTOR</figcaption></figure><ul><li>This graph is plot against <strong>probability index VS entropy</strong></li></ul><h3>Gini Impurity</h3><ul><li>used to measure <strong>INCORRECT</strong> <strong>labelling</strong> with <strong>MATCHING PATTERNS.</strong></li><li>Gini<strong> — means — -&gt;</strong> “<strong>generalized inequlity index</strong>”</li><li>may be used to <strong>build</strong> decision tree <strong>instead of entropy</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*YHFwNFUpYEIQyD5HU57FUg.png" /><figcaption>Pi is the probability of the i th event.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bhm0M1sFkWjq9J6fPKrs-Q.png" /><figcaption>The graph without &amp; with Error Factor</figcaption></figure><ul><li><strong>differences</strong> in graphy of Gini and entropy</li></ul><blockquote>1. spread of plot</blockquote><blockquote>2. skewness (symmetry)</blockquote><blockquote><strong>Entropy</strong> ====&gt; useful, when “<strong>multiple</strong> events occur at a <strong>PARTICULAR instance</strong> or a <strong>location</strong>”</blockquote><blockquote><strong>Cross-Entropy</strong> ====&gt; useful, when “<strong>multiple</strong> events(but the <strong>same events</strong>) occur at <strong>2 different instances</strong> OR <strong>locations</strong>.</blockquote><blockquote>Entropy =====&gt; events come from <strong>SAME STATISTICAL distribution</strong></blockquote><blockquote>X-Entropy =====&gt; events are from <strong>2 different distributions.</strong></blockquote><blockquote>entropy within a distribution =&gt; <strong>intra-error</strong></blockquote><blockquote>Cross-Entropy =&gt; <strong>inter-error</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*q6z18pjLIdMNvl3Wb4Cd5A.png" /><figcaption><strong>2 Events a, b occur in 2 different instances with probabilities [p1, q1] , [p2, q2]; where p1 + q1 = 1 &amp;&amp; p2 + q2 = 1</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*-2HRgMr2UxMbBJxUYp2hZA.png" /><figcaption>Generalized equation for multi-class x-entropy</figcaption></figure><h3>Information Gain</h3><ul><li>binary events</li><li>entropy OR Gini <strong>used</strong> to “<strong>Describe these Characteristics.”</strong></li></ul><h3>Decision Tree Learning Algorithm</h3><ul><li>GOAL :-</li></ul><blockquote>* to focus on <strong>EACH</strong> <strong>one</strong>-DIMENSIONAL subspace(<strong>single feature at a tim</strong>e),</blockquote><blockquote>* select the <strong>best</strong> <strong>feature</strong>(best one-dimensional <strong>subspace</strong>) and <strong>BEST split LOCATION</strong>,</blockquote><blockquote>* <strong>extract</strong> the <strong>feature value</strong> at the <strong>best split location</strong>,</blockquote><blockquote>* <strong>divide</strong> the domain into 2 subdomains.</blockquote><blockquote>REPEAT until **NO** Domain divisions are required</blockquote><h4>Training Algorithm</h4><ul><li><strong>first</strong> &amp; <strong>most</strong> important requirement =&gt; <strong><em>best feature &amp; best split location</em></strong></li><li><strong>parameterization</strong> &amp; <strong>optimization</strong> are PERFORMED “<strong>simultaneously</strong>” @ <strong>EACH</strong> node <strong>WHILE a decision tree is BUILT.</strong></li></ul><h3>Reference :-</h3><p><strong><em>Machine Learning Models and Algorithms for Big Data Classification, Shan Suthaharan; Chapter 10 — Decision Tree Learning</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd05158f0ca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Virtualenv & pip Package Manager]]></title>
            <link>https://medium.com/@ramrajchandradevan/python-virtualenv-pip-package-manager-339b7548af1d?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/339b7548af1d</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pip]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Sun, 06 Aug 2017 03:44:16 GMT</pubDate>
            <atom:updated>2017-08-06T03:44:16.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*bYuziXx7lsAhHgReTIWFyg.png" /></figure><p>Virtual-Environment is a tool that creates an isolated environment in Python. When we download and install <strong><em>virtualenv</em></strong> inside a desired folder, a <strong>bin</strong> sub-directory is created and it has all the necessary executables to support python execution.</p><p>We can create many <strong>instances</strong> of virtual environment in that folder by executing the command with the desired instance name. However, the disadvantage it has is that we cannot transfer the folder to different machine or platform. That means virtualenv is <strong>not portable.</strong></p><p>When the <strong>virtualenv</strong> instance is in run mode, we can execute the regular python package manager commands like <strong>pip</strong> and python commands.</p><p>To begin, using the virtual environment, it needs to be activated:</p><blockquote><strong><em>$ source my_project/bin/activate</em></strong></blockquote><p>Then install the packages as usual, for example:</p><blockquote><strong>$ pip install requests</strong></blockquote><p>If we are done working inside the virtual environment for the moment, we can deactivate it:</p><blockquote><strong>$ deactivate</strong></blockquote><p>This puts us back to the system’s default Python interpreter with all its installed gloabl libraries.</p><p>To delete a virtual environment, just delete its folder. (In this case, it would be <strong><em>rm -rf my_project</em></strong>.)</p><h3>virtualenv — wrapper</h3><p>virtualenv wrapper provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place.</p><blockquote><strong>$ pip search Pympler</strong></blockquote><p>SEARCH A PIP PACKAGE NAME</p><blockquote><strong>$ pip install Pympler</strong></blockquote><p>INSTALLING A PIP PACKAGE NAME</p><blockquote><strong>$ pip list</strong></blockquote><p>LIST OUT THE PIP PACKAGES INSTALLED CURRENTLY</p><blockquote><strong>$ pip uninstall Pypmpler</strong></blockquote><p>UNINSTALL THE NAMED PIP PACKAGE</p><blockquote><strong>$ pip list — outdated</strong></blockquote><p>ONLY LIST THE OUTDATED PIP PACKAGE</p><p>OR</p><blockquote><strong>$ pip list -o (</strong>small o letter)</blockquote><blockquote><strong>$ pip install -U setuptools (</strong>Capital U Letter) → Update</blockquote><h4>— — * — — * — — * —EXPORTING PIP PACKAGES— — * — — * — — * —</h4><blockquote><strong>$ pip freeze</strong></blockquote><p>This will output all currently installed pip packages ( into a <strong><em>requirements.txt </em></strong>file)</p><blockquote><strong>$ pip freeze &gt; requirements.txt</strong></blockquote><blockquote><strong>$ cat requirements.txt</strong></blockquote><p>This will show the file contents</p><h4>— — * — — * — — * — IMPORTING PIP PACKAGES — — * — — * — — * —</h4><blockquote><strong>$ cat r_test.txt</strong></blockquote><blockquote><strong>$ pip install -r r_rest.txt</strong></blockquote><p>This tells that we gonna use a requirement file</p><blockquote><strong>$ pip list</strong></blockquote><blockquote><strong>$ pip freeze- -local</strong></blockquote><p>— -local → will not allow us to access global properties</p><p><strong>-nl</strong> (flag) → tells that one at a time</p><h4><strong>— —* — — *— —* — —* — — *— — * — — * — — * — — * — — * — — * —</strong></h4><h3>Pip for virtual environment</h3><blockquote><strong>$ pip install virtualenv</strong></blockquote><blockquote><strong>$ pip list</strong></blockquote><blockquote><strong>$ mkdir Environments</strong></blockquote><blockquote><strong>$ cd Environments</strong></blockquote><blockquote><strong>$ virtualenv project1_env</strong></blockquote><blockquote><strong>$ source project1_env/bin/activate</strong></blockquote><p>&gt; From this last command, the prompt will begins with virtual env name now onwards</p><blockquote><strong># which python</strong></blockquote><blockquote><strong># which pip</strong></blockquote><blockquote><strong># pip list</strong></blockquote><p>This will list only local packages, not global</p><blockquote><strong># pip install bumpy</strong></blockquote><blockquote><strong># pip install scipy</strong></blockquote><blockquote><strong># pip list</strong></blockquote><blockquote><strong># pip freeze — local &gt; requirements.txt</strong></blockquote><p>This will export only the local entities</p><blockquote><strong># cat requirements.txt</strong></blockquote><blockquote><strong># deactivate</strong></blockquote><blockquote><strong>$ which python</strong></blockquote><blockquote><strong>$ pip list</strong></blockquote><blockquote><strong>$ ls</strong></blockquote><p>&gt; This commands will show only 2 files according to what we typed in cmd. <strong>requirements.txt</strong> AND <strong>project1_env</strong></p><blockquote><strong>$ rm -rf project1_env</strong></blockquote><blockquote><strong>$ ls</strong></blockquote><p>&gt; This will show only the requirements.txt because the project folder was deleted.</p><h4>NOW INSIDE PYTHON 2.6 VERSION CODE (This tells that we can initialize virtualenv even inside the lib python folder too)</h4><blockquote><strong>$ virtualenv -p usr/bin/python2.7 py26_env</strong></blockquote><blockquote><strong>$ ls</strong></blockquote><blockquote><strong>$ source active py26_env</strong></blockquote><blockquote><strong># which python</strong></blockquote><blockquote><strong># ls</strong></blockquote><blockquote><strong># pip install -r requirements.txt</strong></blockquote><blockquote><strong># deactivate</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/287/1*3ovYQZsFB5ddCkt2hAm3tQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=339b7548af1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python __init__.py & modular Imports]]></title>
            <link>https://medium.com/@ramrajchandradevan/python-init-py-modular-imports-81b746e58aae?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/81b746e58aae</guid>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 05:17:30 GMT</pubDate>
            <atom:updated>2017-08-03T05:18:09.039Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*u4_UByLJqJKDMDzsJqNhvw.png" /></figure><p>Python modular import has 2 options,</p><blockquote><strong>1. Absolute modular imports</strong></blockquote><blockquote><strong>2. Relative modular imports</strong></blockquote><ul><li>Absolute imports exist from the beginning of python release; however, relative import came once after python 2.7.</li><li>Relative imports use <strong>module’s name attribute</strong> to determine the module’s position in the <strong>package hierarchy</strong>.</li></ul><p>A project with multiple hierarchical level directories work as a package with some attributes.</p><p>1. There should be a <strong>__init__.py</strong> file(usually kept empty) in a directory. <em>When a python scripts need to look down into the hierarchical level, the existance of __init__.py file will lead the program flow. Otherwise “</em><strong><em>package not found error</em></strong><em>” occurs.</em></p><p>2. The script should be called while running by standing out from the package.</p><blockquote><strong>python -m package.subpackage.subsubpackage.pyscript</strong></blockquote><p>We can <strong>run</strong> python scripts in 2 ways.</p><p>1.We step into the python script directory and call <strong><em>python mypy.py </em></strong>[Current script is a <strong>top-level module</strong>]</p><ul><li>In this case, the import module canot step out of the directory in hierarchical tree.</li><li>Here code runs on <strong>global namespace.</strong></li></ul><p>2. We stand ahead of the python package and call <strong><em>python -m myPackage.subPackage.subsubPackage.myScript</em></strong> [<strong>modular level module</strong>]</p><ul><li>Here<strong> -m</strong> tells the <strong>modular initialization.</strong></li><li>We drop <strong><em>.py</em></strong> at the end of script extension.</li><li>We direct the script to run by the use of namesapces.</li><li>Namespapces are just the names given to each directory in the package.</li><li>This script run call tells exactly where the module is actually located inside the package.</li><li>Here the code runs as a part of an <strong>imported module.</strong></li><li>As this code runs <strong>not</strong> in global namespace, the __name__ becomes the <strong>name of the module.</strong></li></ul><h3>Namespace for python script :-</h3><p>Usually, say for example if we have a python script called <strong>myPython.py,</strong> when we run this script, a namespace will be added to each module, and by default it is __main__.</p><blockquote><strong><em>def funcPy():</em></strong></blockquote><blockquote>pass</blockquote><blockquote><strong>if __name__ == ‘__main__’:</strong></blockquote><blockquote>print ‘__main__’</blockquote><blockquote><strong>else:</strong></blockquote><blockquote>print __name__</blockquote><p>So basically, python has <strong>name</strong> module, which holds all <strong>namesapces</strong> inside. By deafult when a script runs, it grabs the global namespace <strong>__main__</strong>. We can call this name of the script by <strong>__name__</strong> variable. Samelike, we can get package name <strong>__package__ </strong>and directoty name<strong> __dir__</strong>. If a script has multiple import and from statements, those modules will take their file name as namesapces, but our primary running script will take __main__ namesapce. However, we can manually change this name. One way is to change in /python2.7/lib/__init__.py folder and other way is to re-initialized inside the code.</p><p>By default, <strong>__package__</strong> will be assigned to <strong>None</strong> &amp; <strong>__name__ </strong>will be assigned to<strong> __main__</strong>.</p><h3><strong><em>******************Don’t Forget*****************</em></strong></h3><p>When we use relative modular imports, we shoud <strong>stay outside the package</strong> and call,</p><blockquote><strong>python -m myPackage.subPackage.subsubPackage.myScript</strong></blockquote><p>Otherwise, runtime error will rise.</p><blockquote><strong>“You’re not using it as a package.”</strong></blockquote><h3><strong><em>**********************************************</em></strong></h3><p>The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur deeper on the module search path. In the simplest case, __init__.py can just be an empty file, but it can also execute initialization code for the package or set the __all__ variable, described later.</p><p>1. from packagePy import *</p><p>2. __all__ = [“module1”, “module2”, module2]</p><p>The example for the above implementation is,</p><h3>PackagePy</h3><blockquote>1. module0</blockquote><blockquote>2. module1</blockquote><blockquote>3. module2</blockquote><blockquote>4. module3</blockquote><blockquote>5. module4</blockquote><p>The difference between above 2 is that we don’t have to import all modules inside the package in (2)nd one.</p><p>Python searches a list of directories to resolve names while import statements. Because these names can be any directory, or arbitrary names can be added by the developer. However, the developers have to worry about directories that happen to share the same name with a valid Python module, such as ‘<strong>string</strong>’. To differentiate those 2 modules(<strong>default python lib module</strong> &amp; <strong>user defined module</strong>), relative modular import comes into play. The creation of __init__.py will direct the script to search for the namespace in sub directories on hierarchical level of the package. If you remove the __init__.py file, Python will no longer look for submodules inside that directory, so attempts to import the module will fail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*baq1t0g9N4tKXBB8nfJ2KQ.png" /></figure><h3><strong>Reference :-</strong></h3><ol><li><a href="https://stackoverflow.com/questions/37193670/valueerror-attempted-relative-import-in-non-package-not-for-tests-package">https://stackoverflow.com/questions/37193670/valueerror-attempted-relative-import-in-non-package-not-for-tests-package</a></li><li><a href="https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time">https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81b746e58aae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ubuntu-Docker Image on Mac & Docker Image Caching]]></title>
            <link>https://medium.com/@ramrajchandradevan/ubuntu-docker-image-on-mac-docker-image-caching-9c103150a4d9?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c103150a4d9</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-image]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Thu, 03 Aug 2017 01:48:51 GMT</pubDate>
            <atom:updated>2017-08-03T01:48:51.609Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/560/1*vzPJvcWrDqrwr5chwEiwWA.png" /></figure><p><strong>Docker Build</strong> file is a <strong>text</strong> file that creates our <strong>own custom</strong> docker image. <strong>Docker Build</strong> file builds docker image from docker file.</p><p>Examples here are done in <strong>Mac</strong>.</p><blockquote><strong><em>$ touch Dockerfile</em></strong></blockquote><p>— — — creates a Dockerfile</p><blockquote><strong><em>$ docker ps</em></strong></blockquote><p>— — — list of images, currently running. Usually nothing shows up as no docker images run on background.</p><blockquote><strong><em>$ docker ps -a</em></strong></blockquote><p>— — — lists down the previously ran docker images. Those docker images will still exist in the machine unless the user manually remove them once task completed.</p><blockquote><strong><em>$ docker run -ti -rm ubuntu /bin/sh</em></strong></blockquote><p>— — — When we use <strong>-rm</strong> in the command, the given docker image will be removed when exit the application. Here <strong>t</strong> denotes <strong>terminal</strong> &amp; <strong>i</strong> points <strong>interactive</strong> mode.</p><p>Now the docker will start running &amp; our terminal will change to docker image prompt mode(interactive mode changes from <strong>$ prompt</strong> to <strong># prompt- </strong>depending on the OS used and current state).</p><blockquote><strong><em># whoami</em></strong></blockquote><p>— — — will give root</p><blockquote><strong><em># get - -version</em></strong></blockquote><blockquote><strong><em># vim</em></strong></blockquote><blockquote><strong><em># curl</em></strong></blockquote><blockquote><strong><em># wget</em></strong></blockquote><p>— — — these above commands should be initialized in the docker file while creating the docker image incase we prefer to use them in our docker image.</p><blockquote><strong><em># exit</em></strong></blockquote><p>— — — will exit the docker image run mode.</p><blockquote><strong>$ docker ps</strong></blockquote><p>— — — Now this command will show Nothing because we said to remove the image once we exit in the docker run command(No images of lastly opened)</p><h3>DOCKER FILE</h3><p>First line should start with ‘<strong>FROM</strong>’. We can import or start the docker image from scratch.</p><blockquote><strong>FROM ubuntu</strong></blockquote><blockquote><strong>MAINTAINER Ramraj@ramraj@emory.edu</strong></blockquote><p><strong>MAINTAINER</strong> is not that important because we just use it to mention the create name and contact email id.</p><p><strong>RUN</strong> is going to add some package managers inside</p><blockquote><strong>: RUN app update</strong></blockquote><blockquote><strong>: RUN app add vim</strong></blockquote><blockquote><strong>: RUN apk curl</strong></blockquote><blockquote><strong>$ ll</strong></blockquote><p>— — — will list down the docker files</p><blockquote><strong>$ docker build -t ramraj/ubuntu-custom:1.0 .</strong></blockquote><p>— — — Here <strong>-t</strong> denotes the tag, just the version. And<strong> ‘.’</strong> tells that the current folder (usually path to folder) of the docker file.</p><p><strong>STEPS</strong> are being created while building the docker file. It creates final docker image as well as intermediate docker images(with name “<strong>none</strong>”). After the completion of STEP 1/N (N lines in docker file), the created image will have an <strong>unique ID.</strong></p><blockquote><strong>$ docker images</strong></blockquote><p>— — — will give the specified image with TAG 1.0</p><p><strong>$ docker images -a</strong></p><p>— — — will give too many images(includes intermediate images). But only the final docker image has the name and TAG. This scenario is called <strong><em>Image cache</em></strong>. Each lines in the docker file create each docker images for the purpose of caching. When we run the docker build again less number of steps will be displayed.</p><blockquote><strong>$ docker build -t ramraj/ubuntu-custom:1.0 .</strong></blockquote><p>— — — Using cache the building process will speed up.</p><blockquote><strong>$ docker run -ti -rm ramraj/ubuntu-custom:1.0 /bin/sh</strong></blockquote><p>Now if we changed a step in Docker build file, say for example</p><p><strong><em>RUN: APK GIT</em></strong> from<strong><em> APK CURL</em></strong></p><p>When we build the docker image again, the non-changed steps still run from cache. But the changed line is executed again. Here a docker image is created, called <strong><em>Dangling Image</em></strong></p><blockquote><strong>$ dicker images — filter “dangling=true”</strong></blockquote><p>When we change mind and want to change the docker image, the previous image would be abandoned in the pool. That is called dangling image.</p><blockquote><strong>$ docker mi $(docker images -q — filter “dangling=true”)</strong></blockquote><p>— — — Here <strong><em>-q </em></strong>will remove the <strong>HEADING</strong> displayed.</p><p>If we break the docker building cycle, then the flow interrupts, and the cache flow will be reorganized. Each intermediate docker images, consumes almost same space. If the space is large for a docker image, then the whole steps of intermediate docker images consume a lot of spance.</p><blockquote><strong>RUN apk update &amp;&amp; \</strong></blockquote><blockquote><strong>apk add curl &amp;&amp; \</strong></blockquote><blockquote><strong>ask add vim &amp;&amp; \</strong></blockquote><blockquote><strong>apk aadd git</strong></blockquote><p>Instead of creating many steps, includes all steps in one. Total numeber of steps is 3 now, NOT 5 (<strong>FROM, MAINTAINER, RUN</strong>) = <strong><em>OPTIMIZATION.</em></strong></p><p>Usual Docker file initializers are <strong><em>FROM, MAINTAINER, COPY, ADD, LABELS, ENV, EXPOSE (for https), USER, WORKDIR, RUN.</em></strong></p><p>Now we create a file named <strong><em>config.txt.</em></strong></p><p><strong>COPY ./config.txt /usr/src/config.txt</strong></p><p>— — — Add this statement to Docker file.</p><blockquote><strong>$ docker build -t ramraj/ubuntu-custom:1.0 .</strong></blockquote><blockquote><strong>$ docker run -ti -rm ramraj/ubuntu-custom:1.0 /bin/sh</strong></blockquote><blockquote><strong># ls /usr/src</strong></blockquote><p>— — — will return <strong><em>config.txt</em></strong> as the output display.</p><blockquote><strong># cat /usr/src/config.txt</strong></blockquote><p>— — — will show what we have already written and saved on the config.txt file.</p><p>This change of adding a new file into the Docker build file, will too rebuild the docker images by non-caching intermediate docker images. Somehow docker understands the change made in its build flow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*yQRWru_VZbzifDQCcJGiig.png" /></figure><h3><strong>Reference :-</strong></h3><p><a href="https://www.youtube.com/watch?v=6Er8MAvTWlI">https://www.youtube.com/watch?v=6Er8MAvTWlI</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c103150a4d9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shallow Understanding on Bayesian Optimization]]></title>
            <link>https://medium.com/data-science/shallow-understanding-on-bayesian-optimization-324b6c1f7083?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/324b6c1f7083</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[bayesian-machine-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deeper-learning]]></category>
            <category><![CDATA[bayesian-statistics]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Sat, 29 Jul 2017 00:36:57 GMT</pubDate>
            <atom:updated>2017-07-30T18:57:42.730Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PhKGj_bZlND8IEfII426wA.png" /><figcaption>Sample data increases &amp; Curve fitting gets improved.</figcaption></figure><h4>Hard Terms, known in advance :-</h4><blockquote>Gaussian Process</blockquote><blockquote>Noise-Free Global optimization</blockquote><blockquote>Noisy Global optimization</blockquote><blockquote>Acquisition functions</blockquote><blockquote>Surrogate Functions (/Gaussian Process)</blockquote><blockquote>Stochastic</blockquote><blockquote>Bayesian Regression</blockquote><p>What is Gaussian Process ??</p><p>- It is an <strong>Bayesian Regression</strong></p><p>- It is an <strong>exact</strong> interpolation <strong>regression</strong> method.</p><p>- It is a <strong>natural generalization</strong> of <strong>linear</strong> regression.</p><ul><li>It specifies a <strong>Distribution</strong> <strong>over</strong> <em>functions</em>.</li></ul><p><strong>Bayesian Optimization</strong> is a method that uses some kind of approximation. Imagine, if we don’t know a function, what we usually do? Ofcourse, we will try to guess or approximate it with some know prior knowledge. The same idea is behind the <strong>posteriori probability</strong>. The criteria here is that we have <strong>observations</strong>, where the data are coming records by records (<strong>online-learning</strong>), so we need to train this model. The trained model will obviously obey a function. That function that we don’t know will absolutely depend on the <strong>learnt data</strong>. So our task is to find the <strong>hyper-parameters</strong> that <strong>maximizes</strong> the learning schema.</p><p>We have some <em>variables</em> here. One is the <strong>observation records(features + labels)</strong> and the second is the <strong>parameters</strong>, which defines the model.</p><h3>eg.</h3><blockquote>(say for like in <strong>y = mx + c </strong>; m &amp; c are parameters, and y, x are variables-labels &amp; features. We have an obligation to find these m &amp; c to learn our best model)</blockquote><p>Bayesian Optimization helps to find a <strong>best model</strong> among many. We have cross-validation in hand. But how many samples we gonna try on a pre-list to choose a best model among them. That’s why Bayesian approach <strong>speed up</strong> the process by reducing the computation task and doesn’t expect help from the person to guess the values. This optimization technique is based on <strong>randomness</strong> and <strong>probability distributions.</strong></p><p>To say in my words, the <em>first observed point</em> comes to the model. we draw a line. Then the next point follows. We joint those 2 points and draw an adjusted line from previous curve. A third point comes, so we draw a non-linear curve. When the number of observed points increases, the number of combination for possible curves increases. <em>It is same like sampling theorm in Statistics where we estimate a population parameter from sample parameters.</em></p><p>We plot another <strong>histogram curve</strong> along with the non-linear objective function curve. That tells, where the <strong>max</strong> value will present among all past observations for a given objective function curve(finding <strong>arg</strong> max).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bp7dYIKiYGeQD7e1eW4zcg.png" /><figcaption><strong>Histogram Curve</strong>, that is the <strong>Acquisition Function</strong> (includes different acq functions).</figcaption></figure><p>Our goal here is <strong>not</strong> to determine the objective function(which is unknow) as a curve completely with as much as observed points as possible. Instead, we need the <strong>arg of the maximum value</strong>(index of the max function). So we need to divert out concentration towards the histogram function. When the possible combination of objective function curves increases the histogram forms a distribution, which describes the acquisition funtion. It is the idea behind Bayesian Optimization.</p><blockquote>REMEMBER, our goal, primarily need to determine the arg of the max value, and secondarily selecting next best possible max value, which could be on the function curve.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkZ9AEweXXJhwBWneV0HsA.png" /><figcaption><strong>Many Random Ensemble Curves</strong> that we could draw from the <strong>above observed black samples.</strong></figcaption></figure><p>We see many <strong>waggle curves</strong> in the plot. That tells the range of the function curve <strong>next point could be located</strong> at given a sampled point. The variance gives the distribution from the mean value on the function curve.</p><p>When we estimate by superimposing the observed values over the unknown function curve, then this is <strong>noise-free optimization</strong>. But when we need to consider <strong>noisy optimization</strong>, our unknown function will slightly diviates the observed points by a noisy error value.</p><p>We define the <strong>acquisition function</strong> under many measures and some of them are here,</p><blockquote><strong>1. PMAX</strong></blockquote><blockquote><strong>2. IEMAX</strong></blockquote><blockquote><strong>3. MPI = Maximum Probabiity of Improvement</strong></blockquote><blockquote><strong>4. MEI = Maximum Expected of Improvement</strong></blockquote><blockquote><strong>5. UCB = Upper Confidence Bounds</strong></blockquote><blockquote><strong>6. GP-Hedge</strong></blockquote><blockquote><strong>MM = Maximum Mean</strong></blockquote><blockquote><strong>MUI = Maximum Upper Interval</strong></blockquote><p><strong>Acquisition Criteria</strong> :- <em>which sample should be sleceted next</em></p><p><strong>Surrogate Function/ Response Surface(model)</strong></p><ul><li>posterior over <strong>unobserved</strong> points <strong>based on prior</strong>.</li><li>its <strong>parameters</strong> might be based on prior.</li></ul><h3>An Acquisition function :-</h3><p>The measurement is <strong><em>Probability of Improvement(PI).</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*5FpIvJ-TVh_ZlAKmrv9nRg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*epvSotjfl110JKkZhZYtLg.png" /></figure><p><strong>μ</strong>+ = the <strong>best</strong> <strong>observed</strong> value among the past points.</p><p>We are looking for a <strong>max</strong> value of the <strong>unknown function. </strong>But among our past observation, the <strong>next</strong> <strong>possible</strong> max value should be larger than the <strong>current max observed value.</strong></p><p><strong>ε</strong> = <strong>very small</strong> arbitary value denotes the point in Guassian Distribution.</p><h3>Our Goal :-</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*AcbaPDYbf0nSeTq154hRyA.png" /><figcaption>Find the arg of the max of f(X)</figcaption></figure><p><strong>PI(x)</strong> = The probability of the <strong>next max</strong> of the <strong>unknown function</strong> found to be above the <strong>max observed value</strong> plus <strong>some bias.</strong></p><p>This is just the 1D integration of the Gussian distribution with the threshold boundary of the max observed value.</p><p>For the each point in the unknown function, we consider a Guassian distribution placed vertically at each point samples. This distribution has mean at the value on the unknow function &amp; some certain variance.</p><p>We standardize this in the above <strong><em>Kushner 1964</em></strong> equation.</p><p><strong>Exploration &amp; Exploitation</strong> are the frequently used terms to explain a phenomena and the optimization algorithm. There is a trade-off exists in-between these 2. Therefore, we <strong>balance</strong> this tradeoff using the “<strong>acquisition function</strong>”.</p><p>Our <strong>next chosen point( x ) </strong>should has <strong>high mean</strong> (<em>exploitation</em>) &amp; <strong>high variance</strong> (<em>exploration</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*PF8XTtgVm1UYTuRc3U2ePQ.jpeg" /><figcaption>Choosing our next possible max point, with trade-off between <strong>Exploration &amp; Exploitation.</strong></figcaption></figure><p>Because we search for the next point in high variance distribution. That means exploring the point x.</p><p>High mean means we chose the next point( x ) with high offset/ bias so that we should give some exploitation weights to decrease the mean of the next point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6wykUbMfd2e1TSPr0gbagA.png" /><figcaption>The way we approach Bayesian Optimization.</figcaption></figure><p>The above picture gives some intuition about our algorithm. The red curve is our <strong>True Objective</strong> function curve. Unfortunately, we don’t know this function and its equation. So we gonna approximate it using <strong>Gaussian Process. </strong>Throughout our<strong> Sampled Points</strong>(given 4 samples here), we draw a intuitive/ confident curve that fits with our observed samples. So the green region shows the <strong>Confidence Region</strong>, where the most probability of curve points could be positioned. From the above <strong>prior knowledge</strong>, we determine that second point(<strong>f+</strong>) as the <strong>maximum observed value</strong>. So the next max point should be above it or equal. We draw a blue line here. The next max point should fall above this line. So from the <strong>intersecting</strong> points of<strong> f+</strong> and <strong>Confidence Region, </strong>we could assume that the curve samples below the<strong> f+ </strong>should be discarded along with our goal to find <strong>arg max. </strong>Therefore, now we have narrowed down our area of investigation. This same process continues with the next <strong>Sampled Points.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vh-KMqYVCotjmCrIW4OCwA.png" /><figcaption>Data sample increases; comparison of different<strong> Acquisition functions</strong> with <strong>Curve Fitting.</strong></figcaption></figure><h3>Reference :-</h3><iframe src="https://drive.google.com/viewerng/viewer?url=https%3A//www.cs.ox.ac.uk/people/nando.defreitas/publications/BayesOptLoop.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0694d0545bf9f08290b6c88906b6ea1/href">https://medium.com/media/b0694d0545bf9f08290b6c88906b6ea1/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=324b6c1f7083" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/shallow-understanding-on-bayesian-optimization-324b6c1f7083">Shallow Understanding on Bayesian Optimization</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AutoEncoders are Essential in Deep Neural Nets]]></title>
            <link>https://medium.com/data-science/autoencoders-are-essential-in-deep-neural-nets-f0365b2d1d7c?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0365b2d1d7c</guid>
            <category><![CDATA[encoding]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Wed, 26 Jul 2017 20:01:50 GMT</pubDate>
            <atom:updated>2017-07-27T07:30:41.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*lOZVC-aKzITERzC1HgNEMA.png" /></figure><p><strong>Autoencoder</strong> is a neural network (NN), as well as an <strong>un-supervised learning</strong> (feature learning) algorithm.</p><ul><li>It applies <strong>backpropagation</strong>, by setting the target value same as input.</li><li>It tries to predict <strong><em>x</em></strong> from <strong><em>x</em></strong>, without need for <strong>labels.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*RD7rWiS_9gYDN1RFoa7ShQ.png" /><figcaption>Output = f . f ‘ . Input</figcaption></figure><ul><li>It tries to learn an approximation of an “<strong>identity</strong>” function.</li><li>But we place <strong>constraints</strong> on the network like <strong>less</strong> <em>number of units in hidden layer.</em></li><li>It represents orig input from <strong>compressed, noisy, or corrupted data.</strong></li><li>It consists of <strong>narrow hidden layer</strong> between Encoder &amp; Decoder.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nmnm2rRJjaBD1TCUgL4dmA.png" /><figcaption>Network level representation</figcaption></figure><ul><li><strong>Intermediate layer</strong> (<strong>middle layer</strong>[<em>bottle neck</em>] or <strong>latent space representation</strong>) is a <strong>compresssed representation</strong> of the input data.</li><li>The difference in Autoencoder VS Engineered compression is,</li></ul><p>— — — In Autoencoder compression &amp; decompression functions <strong>learn from the data</strong> itself not like <strong>jpg</strong> and <strong>zip</strong>.</p><ul><li><strong>Encoders</strong> and <strong>Decoders</strong> are <strong>feed-forward NN.</strong></li><li>The network is trained by <strong>minimizing</strong> the <em>difference betweeen input and output.</em></li><li>If the input is <strong>completely random</strong>(chosen from <strong>IID</strong> &amp; <strong>independent from other features</strong>), then <em>compression task</em> would be <strong>difficult</strong>.</li><li>If the input features are <strong>correlated</strong>, then the network will <strong>discover those</strong>.</li><li>Its learning style is like PCA, so it closely relates to PCA(Principal Component Analysis).</li><li>We can observe it from the <em>similarity</em> of <strong>Eigen vactor representation</strong>.</li><li>The differences between <strong>PCA</strong> &amp; <strong>Autoencoders</strong> similar</li></ul><blockquote>— autoencoders are much flexible than PCA.</blockquote><blockquote>— NN activation functions introduce “<strong>non-linearities</strong>” in encoding, but PCA <strong>only</strong> linear transformation.</blockquote><blockquote>— we can stack autoencoders to form a <strong>deep autoencoder network.</strong></blockquote><ul><li>The importance of Autoencoders,</li></ul><blockquote>— It finds the <strong>low dimensional representation</strong> of input data.</blockquote><blockquote>— Some input features may be <strong>redundant</strong>/ <strong>correlated</strong> → waste of processing time &amp; “<strong>overfitting</strong>” in our model (too many parameters).</blockquote><ul><li>If the number of <strong>Hidden UNITS</strong> is <strong>LARGE</strong>, we can impose “<strong>sparsity</strong>” constraint on hidden layer. Still the network is able to <strong>discover</strong> features.</li><li>The network’s <strong>neurons</strong> can be <strong>active</strong> (as <strong>firing</strong>) or the neurons can be <strong>inactive</strong>.</li><li>“<strong>sparsity parameter</strong>” usually be <em>small value close</em> to <strong>zero</strong> = 0.05.</li><li>The network introduces <strong>extra penalty term</strong> to our <strong>optimization</strong> objective.</li><li>KL(Kullback-Leibler) divergence is used in regularization, and <strong>Bernoulli random variable</strong> is considered with <strong>means</strong> from <strong>2</strong> distributions.</li><li>The training should be on “<strong>whitened</strong>” <strong>natural images.</strong></li><li><strong>Whitening</strong> is a “<strong>preprocessing step</strong>”, removes <em>redundancy in the input</em>.</li><li>NN training strategies <strong>too</strong> work here,</li></ul><blockquote>1. backpropagation</blockquote><blockquote>2. regualarization</blockquote><blockquote>3. dropout</blockquote><blockquote>4. RBM pre-training</blockquote><h3>Other Kinds of AutoEncoders</h3><h4>1 ) Convolutional AutoEncoders (CAE)</h4><ul><li>This replaces “<strong>fully-connected layer</strong>” by “<strong>convolutional layer</strong>”.</li><li>The <strong>wide thin INOUT layer </strong>— — — converted —to — — &gt; <strong>narrow thick hidden layer.</strong></li><li>This helps in <em>extracting visual features.</em></li><li>Reconstruction Quality :-</li></ul><blockquote>- often blurry</blockquote><blockquote>- lower quality</blockquote><blockquote>- lost of some information</blockquote><ul><li>Use of CAE :-</li></ul><p><strong>1. Ultra-basic image reconstruction</strong></p><p>— learns to <strong>remove noise</strong> from picture/ <strong>reconstruct</strong> missing parts.</p><p>— the input (noisy version) ; so the output (clean version).</p><p>— the network fills the gaps in the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K7ouHU0e8cAl7P8MN4wslQ.png" /><figcaption>Removes the dark cross-bar in the image</figcaption></figure><p><strong>2. Ultra-basic image colorization</strong></p><p>— CAE maps <strong>circles</strong> and <strong>squares</strong> from an image to the same image but with red and blue respectively (coloring).</p><p>— Purple is formed sometimes because of <strong>blend</strong> of colors, where network hesitates between circle or square.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J4A4HuCltZC9UrDZbE41Ng.png" /><figcaption>Coloring</figcaption></figure><p>3. <strong>Advanced applications</strong></p><p>— fully image colorization</p><p>— latent space clustering</p><p>— generating higher resolution images</p><blockquote>Incase of image inputs,</blockquote><p>— — autoencoder uses <strong>Conv layers</strong></p><ul><li>Encoder = typical conv <strong>pyramid</strong></li><li>max-polling layer follows to reduce dimension</li><li>decoder = <strong>deconvolutional</strong> process</li></ul><p>— — The deconvolutional process,</p><blockquote>- adds new data from what it had learnt previously</blockquote><blockquote>- is prone to <strong>visual</strong> <strong>ARTEFACTS</strong>.</blockquote><blockquote>- resizes using “nearest neightbour” OR “bilinear interpolation(upsampling)” , which can be better choise than <strong>standard deconvolutional layer.</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HQ2LzQQaklCbOuGnVPlNUg.png" /><figcaption>Pushes more pixels to the image</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IE3RHJm6OKZmzbIksDgS-g.png" /><figcaption>Fully Image Colorization</figcaption></figure><h4><strong>2 ) Variational AutoEncoder(VAE)</strong></h4><ul><li>This incorporates <strong>Bayesian Inference.</strong></li><li>The <strong>compressed</strong> representation is a <strong>probability distribution.</strong></li></ul><h4><strong>3 ) Sparse AutoEncoder</strong></h4><ul><li>This is used for <strong>feature extraction.</strong></li><li>This has <strong>more</strong> <em>hidden Units than inputs.</em></li><li>This allows sparse represntation of input data.</li></ul><h4><strong>4 ) Stacked AutoEnoder</strong></h4><ul><li>If more than one HIDDEN layer is used, then we seek for this Autoencoder.</li><li>Each consecutive layer is</li></ul><blockquote>- optimally weighted</blockquote><blockquote>- non-linear</blockquote><blockquote>- lower dimensional projection of the training data</blockquote><h4><strong>4 ) Deep AutoEncoders</strong></h4><ul><li>This has 2 symmetrical “<strong>Deep-belief networks</strong>” that has usually 4 or 5 <strong>shallow layers.</strong></li><li>Its layers are<strong> Restricted Boltzmann Machines (RBM).</strong></li><li>Uses,</li></ul><p><strong>1. Image search</strong></p><p>— — An image can be compressed into around 30-number vectors (as in Google image search).</p><p><strong>2. Data Compression</strong></p><p>— — Deep Autoencoders are useful for “<strong>semantic hashing”.</strong></p><p><strong>3. Topic Modelling &amp; Information Retrieval (IR)</strong></p><h3><strong>References :-</strong></h3><ol><li><a href="http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/">http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/</a></li><li><a href="https://hackernoon.com/autoencoders-deep-learning-bits-1-11731e200694">https://hackernoon.com/autoencoders-deep-learning-bits-1-11731e200694</a></li><li><a href="https://deeplearning4j.org/deepautoencoder">https://deeplearning4j.org/deepautoencoder</a></li><li><a href="https://lazyprogrammer.me/a-tutorial-on-autoencoders/">https://lazyprogrammer.me/a-tutorial-on-autoencoders/</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0365b2d1d7c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/autoencoders-are-essential-in-deep-neural-nets-f0365b2d1d7c">AutoEncoders are Essential in Deep Neural Nets</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Python Concepts]]></title>
            <link>https://medium.com/@ramrajchandradevan/deep-python-concepts-256dd5d01a1b?source=rss-acf289935f45------2</link>
            <guid isPermaLink="false">https://medium.com/p/256dd5d01a1b</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Ramraj Chandradevan]]></dc:creator>
            <pubDate>Thu, 13 Jul 2017 17:15:19 GMT</pubDate>
            <atom:updated>2017-07-13T17:42:30.518Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XGJJWLtD7t2wkIOMnyt2Mw.jpeg" /></figure><h3>1 ) Deep copy &amp; Shallow copy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*az3aHDJNxOMhZDgqFJGs6w.png" /></figure><ul><li>Shallow copy just creates a reference and points it towards the original object.</li><li>But deep copy creates a separate object and points the new reference to it.</li></ul><blockquote>exception copy.error</blockquote><ul><li>This is the exception usually raised for module specific error.</li></ul><h3>2 ) Variable length argument list</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vb9-pj_ByT4mNMxJqZWqBw.png" /></figure><ul><li>*name should always be placed at last of the argument list.</li><li>DOUBLE ASTERISKS <strong>**</strong> prefixes??</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0gyfMpcjxUS1ZVWUPz23w.png" /></figure><ul><li>This format would be bound to a <strong>DICTIONARY</strong>, containing any keyword arguments in the actual parameters.</li><li>Will put all the remaining last arguments with keys into a dictionary.</li></ul><h3>3 ) <strong>.pyc</strong> files (byte compiled file) OR <strong>.pyo</strong> files</h3><ul><li>On a main python file, we import other python modules. So when we compiled/interpreted, a .pyc file for <strong>other imported modules </strong>will be created. But <strong>not the main file</strong>. This .pyc makes the loading fast on next time the main file is executed.</li><li>This doesn’t make it <strong>run</strong> faster, but <strong>LOAD</strong> <strong>FASTER</strong>.</li><li><strong>CPython interpreter</strong> uses this technique.</li><li>It caches the <strong>byte code</strong> whenever the source code has <strong>changed</strong>.</li><li>It inserts a <strong>magic NUMBER</strong> in .pyc file. Changes whenever .pyc get changed.</li><li>pyc files are not compatible along major Python releases.</li><li>when there is non-matching <strong>magic number</strong> or <strong>timestamp</strong>, or the byte code <strong>version is old</strong>, .py file regenerate the .pyc files(Starts in <strong>slower</strong> process).</li><li>To create PYC file, just import a module.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5TjsGehBBhJ8W86g5FStw.png" /></figure><blockquote>will automatically <strong>create</strong> <strong>mymodule.pyc</strong> file in the <strong>same</strong> folder</blockquote><blockquote>at the same time <strong>execute</strong> the module code</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LghIVgDVrBTRWhtIE-PqOg.png" /></figure><ul><li>byte code can be exchanged <strong>between paltforms</strong>.</li></ul><blockquote>&gt;&gt;&gt; imp.get_magic()</blockquote><p>will return a <strong>4-byte</strong> string IDENTIFIER</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lQZmKcYEpjvbhTK8d4fKBg.png" /><figcaption>Flow Chart describing Module Import and Byte Code Caching</figcaption></figure><h3>4 ) There is no interpreted language.</h3><ul><li>Every language can be implemented either in interpreter or compiler.</li></ul><blockquote>eg. There are interpreters for C, C++</blockquote><blockquote>There are compilers for JavaScript, PHP, Perl, Python, Ruby</blockquote><ul><li>Modern languages combine them both (even <strong>multiple</strong> compilers).</li><li>Language — a set of abstract mathematical rules.</li></ul><h3>5 ) Python module imports</h3><ul><li>There are 3 wayes exist typically.</li></ul><ol><li>import</li><li>from-import</li><li>__import__</li></ol><h4>1) import X</h4><p>— imports module X.</p><p>— creates a reference in the current <strong>namespace</strong>.</p><p>— We can call <strong>X.name</strong> to refer the the things inside the module</p><h4>2) from X import *</h4><p>— imports module X.</p><p>— creates a reference in the current namespace.</p><p>— We can simply use <strong>plain name</strong> to refer the things defined inside the module.</p><h4>3) from X import a,b,c</h4><p>— same as (2)</p><p>— can use a, b, and c.</p><h4>4) X = __import__(‘X’)</h4><p>— works same like import X.</p><p>— passed the module name as string.</p><p>— explicitly assigned it to a variable in current namesapce.</p><ul><li>Usually we can use import.</li><li>When importing package modules</li></ul><blockquote>&gt;&gt;&gt; from io.drivers import zip</blockquote><blockquote>If we run a module as a script, it is loaded under module name <strong>__main__</strong></blockquote><blockquote>&gt; give its name to interpreter</blockquote><h3>Reference :-</h3><p><a href="http://effbot.org/zone/import-confusion.htm">http://effbot.org/zone/import-confusion.htm</a></p><p><a href="http://effbot.org/zone/python-compile.htm">http://effbot.org/zone/python-compile.htm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=256dd5d01a1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>