<?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 Naeem Asvat on Medium]]></title>
        <description><![CDATA[Stories by Naeem Asvat on Medium]]></description>
        <link>https://medium.com/@naeemasvat.na?source=rss-1ce5163e966a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*SzRRIdxlYjXhMUXEMbPbUg@2x.jpeg</url>
            <title>Stories by Naeem Asvat on Medium</title>
            <link>https://medium.com/@naeemasvat.na?source=rss-1ce5163e966a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:48:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@naeemasvat.na/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[How to use H2O in Google Colab]]></title>
            <link>https://medium.com/@naeemasvat.na/how-to-use-h2o-in-google-colab-b69ba539ab1a?source=rss-1ce5163e966a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b69ba539ab1a</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[h2oai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Naeem Asvat]]></dc:creator>
            <pubDate>Sun, 13 May 2018 14:44:39 GMT</pubDate>
            <atom:updated>2018-05-13T14:46:39.621Z</atom:updated>
            <content:encoded><![CDATA[<p>If you don’t know by now, Google Colab is a <strong>free</strong> Python Notebook (Google’s docs-esque version of the Jupyter Notebook) and cloud-hosted virtual machine with GPU access designed for Machine Learning practitioners to run their experiments on. … FREE…. F-R-E-E…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*B_EOC2l6EIKmgQRKJ4g_lg.gif" /></figure><p>H2O is in my view, the gold standard for what a machine learning module in Python should be. It offers the bleeding edge in machine learning modeling (like model stacking) and it runs in java so it’s much faster than the usual Python module (*cough* sklearn *cough*). The best part is that it’s made for deployment. Once your model is ready all you need to do is deploy the data preprocessing and your model to a java object and you’re ready to implement your model in your program. Oh, and the model performance evaluation functions are so in depth and so simple to call that I can’t see myself ever going back to sklearn anytime soon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*1eaw_hyMWapqTclHnra0Cg.gif" /></figure><p>Naturally, I combined both Colab and H2O so I can operate at the bleeding edge of operational data mining , for free…FREE.</p><h3>HERE’S HOW:</h3><ol><li><strong>Install Java: </strong>In the first line of your Notebook - run the following code to install Java</li></ol><blockquote>You’re using a publicly available virtual machine so as with most things in Colab, everytime you connect you need to set up and install your packages as if it was a brand new Ubuntu server, controlled from a Jupyter Notebook, which is why we use “!” to instigate the bash function.</blockquote><pre>! apt-get install default-jre<br>!java -version</pre><p><strong>2. Install H2O:</strong> Run the following code to install the H2O python module</p><pre>! pip install h2o</pre><p><strong>3. Import H2O:</strong></p><pre>import h2o</pre><p><strong>4. Initialize H2O:</strong></p><pre>h2o.init()</pre><h3>THAT’S IT!</h3><p>You’re now ready to sink your teeth into the speedy, practical , deployable magnificence of a machine learning module that is, H2O.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/1*E-CnwLxOjQ7-wtHK3wq_Rw.gif" /></figure><p>For more information about what you can do with H2O check out their demos and documentation at:</p><ul><li><a href="http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/index.html">DEMOS — http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/index.html</a></li><li><a href="https://github.com/h2oai/h2o-tutorials">Python Documentation — https://github.com/h2oai/h2o-tutorials</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b69ba539ab1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning: Predictive Methods]]></title>
            <link>https://medium.com/@naeemasvat.na/machine-learning-predictive-methods-47db70af0d1c?source=rss-1ce5163e966a------2</link>
            <guid isPermaLink="false">https://medium.com/p/47db70af0d1c</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[machine-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Naeem Asvat]]></dc:creator>
            <pubDate>Tue, 17 Apr 2018 14:33:16 GMT</pubDate>
            <atom:updated>2018-04-17T16:58:54.698Z</atom:updated>
            <content:encoded><![CDATA[<p><em>I’m currently studying statistical learning methods for building Python ML models. I’ve compiled this summary to explain these methods to others and force myself to better understand these concepts.</em></p><h3>Linear Regression</h3><p><em>Used for predicting quantitative values given quantitative or qualitative inputs.</em></p><p>As the name says, this technique is based on the assumption of a linear relationship between the datasets parameters. The most common technique of modeling this relationship is the ordinary least squares linear model. There are others like the maximum likelihood model.</p><p>This is considered an inflexible method because it forces us to assume a “shape” between the relationship of the independent (inputs) and dependent (output) variables.</p><p>While we usually make a lot of assumptions by using this method, it’s still useful in inferring how the selected variables relate to each other and it reveals the magnitude of their impact on output in really obvious ways.</p><p>If we wanted use this method and to taken into account the pitfalls of this method there are many ways statisticians have found to overcome them by extending the model. <em>(There’s too many to state here but dig a little and you’ll find some pretty elegant solutions)</em></p><p><strong>Linear regression| </strong><em>y</em>=<strong>(B</strong><em>1)x</em><strong>+(B</strong><em>0)</em></p><p><strong>Multi-linear regression|</strong> <em>y</em>=<strong>(B</strong><em>1)x+</em><strong>(B</strong><em>2)y+</em><strong>(B</strong><em>3)z+</em><strong>(B</strong><em>0)</em></p><p><strong>Polynomial regression| </strong><em>y</em>=(x1)^<strong>(B1</strong><em>) . (x2)^</em><strong>(B2</strong><em>)+</em><strong>(B</strong><em>0)</em></p><h3>Logistic Regression</h3><p><em>Used for classification.</em></p><p>Similar to regression in that we’re using an inflexible formula to predict a binary outcome.</p><p><strong>Eg.| </strong><em>y</em>=1/(1+<em>e</em>^(<strong>(B</strong><em>1)x+</em><strong>(B</strong><em>2)y+</em><strong>(B</strong><em>3)z+…</em>))</p><blockquote>where y<em>=0 or 1</em></blockquote><p>When trained, this algorithm shapes to minimize the “<strong><em>cost</em></strong>”.</p><p>Here, <strong><em>cost</em></strong>=(<strong><em>y_</em></strong>actual*log<strong><em>y_</em></strong>estimate+(1-<strong><em>y_</em></strong>actual)*log(1-<strong><em>y_</em></strong>estimate))</p><h3>Regression with Regularization</h3><p><em>Used to avoid over-fitting, this is important because we want a robust model.</em></p><p>This method shapes a model with the point of minimizing the Betas.</p><p>It does this by adding a penalty or “cost” to the function based on the size of the total sum of the beta values.</p><blockquote>REGULARIZATION TYPES</blockquote><h3>L1 | Lasso Regression</h3><blockquote>“In <a href="https://en.wikipedia.org/wiki/Statistics">statistics</a> and <a href="https://en.wikipedia.org/wiki/Machine_learning">machine learning</a>, <strong>lasso (least absolute shrinkage and selection operator)</strong> (also Lasso or LASSO) is a <a href="https://en.wikipedia.org/wiki/Regression_analysis">regression analysis</a> method that performs both <a href="https://en.wikipedia.org/wiki/Variable_selection">variable selection</a> and <a href="https://en.wikipedia.org/wiki/Regularization_(mathematics)">regularization</a> in order to enhance the prediction accuracy and interpretability of the <a href="https://en.wikipedia.org/wiki/Statistical_model">statistical model</a> it produces.” - <strong><em>Wikipedia</em> (<em>sue me)</em></strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bfi0rbu0vGlJs2w_fqtL0g.png" /><figcaption>SOURCE: <strong>Wikipedia</strong></figcaption></figure><p><strong>Summary</strong></p><ul><li><strong>B</strong> (Beta) is added to the cost function.</li><li>Keeps one Beta and shrinks all other Betas — Great for selecting input variables by emphasizing important Betas</li></ul><h3>L2 | Ridge/Tikhonov/Weight-Decay Regression</h3><blockquote>This got <strong>so</strong> deep.</blockquote><p>To paraphrase, if you were given the matrix that represented the inputs and outputs of a dataset:</p><p><strong>A <em>x </em>= B</strong></p><p><strong>Given</strong></p><ul><li>There’s no unique solution (ie. many types of regressions could give a feasible model)</li><li>Using OLS would lead to over/under-fitted equations.</li></ul><p>If you wanted to find <strong>A<em> </em></strong>(Which in our case would be our Betas):</p><p>Conventional wisdom would say “use the inverse method to find <em>x”. </em>In real life however, the output data itself has systematic squared error (SSE) or unexplained outputs.</p><p>So if we were to inverse A, it would still be a function of this SSE and usually ends up amplifying it.</p><p>To overcome this effect, we can extend the matrix to include a value called a Tikhonov term that we can then assign a value. By assigning a suitable value, solving the system then gives preference to a solution that emphasizes smaller Betas (norms).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/85/1*XoUJohpZ553U4yrlTkw2ZA.png" /><figcaption>Matrix showing OLS RSS</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/172/1*VlfFB90JC7PRgjjjkV4dxw.png" /><figcaption>RSS matrix with Tikhonov term</figcaption></figure><p>From the matrices above we can see that if we treated the Tikhonov term as “=0” the matrix would return to the OLS RSS.</p><p><strong>SUMMARY:</strong></p><ul><li><strong>B²</strong> (Beta squared) is added to to the cost function</li><li>For interdependent variables - reduction is applied equally across Betas</li></ul><blockquote>COMBINING L1&amp;L2</blockquote><h3>Elastic Net (L1+L2) Regularization</h3><p>Can be used with SVMs (We’ll get to these later).</p><p>In theory, it’s the best of both worlds.</p><p>In reality, it introduces it’s own systematic errors and could limit the model to finding local minima in the higher dimensional space.</p><h3>Neural Networks</h3><p><em>These are a massive subset of machine learning with a huge amount of depth and variability. There’s a lot of types so here’s an overview they all should have in common.</em></p><p><strong>Layout</strong></p><ul><li>Neural networks contain layers of interlinked layers of neurons (or functions that are equivalent to logistic regression units).</li><li>The more layers, the greater complexity and the less we can observe what’s going on (AKA it’s like black box).</li></ul><p><strong>Tuning Parameters</strong> | Our locus of control</p><ul><li>Number of neurons in each layers (the same for all hidden layers, usually between 1–3 times the number of input parameters)</li><li>Number of hidden layers</li><li>Learning rate (can be thought of as the extent at which the data fed to the network changes the weighting of the neurons)</li><li>Number of output neurons (These are dependent on the number of outputs we want the model to produce)</li></ul><p><strong>Training</strong></p><ul><li>Parameters are fed into the initial input layer which feeds into the subsequent layers.</li><li>Learning happens by an iterative feedback mechanism — The error of the training data output is used to adjust the weights of the corresponding weights of the inputs.</li><li>The adjustment propagates to previous layers and the learning algorithm adjusts for differences between the actual <strong><em>y</em></strong> and the predicted <strong><em>y</em></strong> . This process is known as “back-propagation”.</li></ul><p><strong>Summary</strong></p><ul><li>Suitable for non-linear functions.</li><li>Can learn multiple outputs simultaneously.</li><li>Training time is long.</li><li>May fall into local minimum traps — can overcome by running multiple rounds and selecting best performers.</li></ul><h3>Support Vector Machines (SVM)</h3><ul><li>These models provide binary classification mechanisms.</li><li>They work by finding hyper-planes between sets of samples with +ve and -ve outputs.</li><li>The assumption made with these machines is that data is linearly separable .</li></ul><p><strong>How It Works</strong></p><p>Instead, try to imagine a floor covered with two different colored marbles and you want to best separate them according to colour by placing down many different straight lines at different angles between them.</p><p>After you’ve placed your lines, you want to place a new set of parallel lines that results in the biggest distance between the two categories based on where these many straight lines were placed. The larger the distance between the parallel lines, the lower the margin for error.</p><blockquote>A SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall.</blockquote><blockquote>In addition to performing linear classification, SVMs can efficiently perform a non-linear classification using what is called the <a href="https://en.wikipedia.org/wiki/Kernel_trick">kernel trick</a>, implicitly mapping their inputs into high-dimensional feature spaces.</blockquote><p><strong>Steps</strong></p><ul><li>Finding the optimal parameter</li><li>Training SVM using the optimal parameter</li></ul><h3>Bayesian Network and Naive Bayes</h3><p><em>The ultimate embodiment of Bayes theorem.</em></p><p>This model tries to find Y where P(Y|X) is maximized, or finding the likelihood of Y given X.</p><p><strong>Bayes Theorem</strong></p><p>P(Y|X)= P(X|Y)*P(Y)/P(X)</p><p>This is equivalent to finding Y where P(X|Y)*P(Y) is maximized.</p><p><strong><em>Example</em></strong></p><p>Parameters: Inputs X are 3 categorical features (X1, X2, X3)</p><p>General Assumption| Any variable can potentially influence any other variable</p><p>Joint Distribution| P(X|Y)=P(X1|Y)*P(X2|X1, Y)*P(X3|X1, X2, Y)</p><blockquote>From the above equation we see that the number of entries is exponentially proportional to the number of input variables</blockquote><p><strong>Naive Bayes Network (Complete Independence Assumption)</strong></p><p>P(X1^X2^X3|Y)</p><p>= P(X1|Y)*P(X2|Y^X2)*P(X3|Y^X1^X2)</p><p>=P(X1|Y)*P(X2|Y)*P(X3|Y) <em>{This requires minimal entries}</em></p><p>Thus, we need to find the Y that maximizes: P(X1|Y)*P(X2|Y)*P(X3|Y)*P(Y)</p><blockquote>Each of the terms on the right can be learned by counting the training data. We can estimate P(Y|X) and pick Y to maximize it’s value.\</blockquote><p><strong>Problem | </strong>Some patterns may never show up in training data [eg. P(X1=a|Y=y)=0 ]</p><p>To overcome this, we “pretend” to that we’ve seen each possible value one more time than we actually have.</p><p>Our equation now becomes:</p><p>P(X1=a|Y=y)==(count(a,y)+1)/(count(y)+m)</p><p><em>m= number of possible values of X1</em></p><p><strong>Conclusion</strong></p><p>When applied to real data-sets, the independence assumption is not usually true, however the system works very well. The strength of using Naive Bayes is that it is highly scale-able and can learn incrementally — it only requires that the observed variables are counted and the probability distribution is updated accordingly.</p><h3>K-Nearest Neighbors (KNN)</h3><p>A highly flexible approach that, instead of ascribing a model or assumption of the data being described, uses euclidean geometry and the distance between data points and K (a parameter we select) to infer a classification category or qualitative value. This type of approach is called “Instance-Based Learning”.</p><p><strong>Technique</strong></p><p>Using <strong>r²=x²+y²+z²</strong> {We find the <strong>K</strong>~(1;100)<strong> </strong>amount of <strong>r</strong> values closest to <strong>K</strong>)</p><p><strong>Strength | </strong>Simplicity; No model needed to be trained ; incremental learning is automatic with the arrival of new data</p><p><strong>Weakness | </strong>High dimensionality and high numbers are problematic</p><h3>Decision Trees</h3><p>This learning approach is designed to recursively divide the training data into buckets of homogeneous members through the most discriminative dividing criteria possible.</p><p><strong>Homogeneity | </strong>the degree of similarity between data points</p><p><strong><em>Measurement</em></strong></p><ul><li>Quantitative Value — variance of the bucket</li></ul><p>— Splitting Criteria: &gt;/&lt;</p><ul><li>Qualitative Value — Entropy/Gini index of bucket</li></ul><p>— Splitting Criteria: Bolean According to “True” is=(parameter.class()) else “False”</p><p>The training process of splitting into buckets and sub-buckets continues until there is no significant gain in homogeneity after splitting.</p><p><strong>Strengths | </strong>Can easily take quantitative/categorical/binary data</p><p><strong>Weakness|</strong> Decision criteria only considers one input attribute at a time (not multiple input attributes ; cannot be updated incrementally</p><p><strong>In practice </strong>| Ain’t nobody got time for those limitation s— tree ensembles are usually used instead</p><h3>Tree Ensembles | Bagging (Random Forest) &amp; Boosting (Gradient Boosted Trees)</h3><p><strong>Bagging</strong></p><p>Technique: Training multiple decision trees on <strong><em>n</em></strong> random samples on<strong><em> N</em></strong> training data . Then using a voting scheme is used to predict future data.</p><p><strong><em>Random Forest</em></strong></p><p>One of the most popular bagging models which was <em>the sauce </em>on<em> </em>Kaggle for a while were random forests. These models work by in addition to splitting the training the data , <strong><em>m </em></strong>input features are randomly selected from the total <strong><em>M </em></strong>(m~M⁰,⁵) input features, thereafter a decision tree is trained. Fiaally, each tree in the “forest” votes for the result.</p><p>This can be seen as exploratorily assigning weights to (AKA sampling) decision tree input features and thereafter cross validating each tree in order to investigate all possible relationships. Trying to shortcut/bypass/hack trees to a global min.</p><p><strong>Boosting</strong></p><p>Instead of sampling input features,training data is sampled, however more emphasis (increased weighting) is put on data that was incorrectly predicted.</p><p><strong><em>Gradient Boosting</em></strong></p><p>This popular method “boosts” by using a function that fits the residuals.</p><p>Set i=0 at the beginning and repeat until convergence.</p><ul><li>Find the <strong><em>F </em></strong>that minimizes :expected <strong><em>L(F(X)-Y) </em></strong>OR<strong><em> L(Yhat-Yactual)</em></strong> | The expected residual error</li><li>Learning <strong><em>g(X) </em></strong>to predict the gradient of the above function.</li><li>Update <strong><em>F(i+1)=F(i) + a.g(X) </em></strong>where <strong><em>a </em></strong>is the learning rate.</li></ul><h3><strong>Cross Validation</strong></h3><blockquote><em>A really interesting technique I’ve come across is </em><strong><em>cross validation.</em></strong></blockquote><p>We can build a model with a variety of techniques, but their structure is determined by the training data used to shape them and thus the split of these data partitions. Using a fixed training set may lead to a local min however, if we train multiple models based on different combinations ,we explore many more models which may in effect result in a global min for the a model approach. In effect by using this approach we can select the best model for our fitness metric (eg. decreases bias and mean squared error).</p><p>There are many techniques for splitting the training and testing data and so cross validation is wide field which offers room for deep flexibility of even relatively inflexible approaches.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47db70af0d1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>