<?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 germayne on Medium]]></title>
        <description><![CDATA[Stories by germayne on Medium]]></description>
        <link>https://medium.com/@germayneng?source=rss-395dc0d8af0d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OU2iu0CxcmV02tEtVNoNwQ.jpeg</url>
            <title>Stories by germayne on Medium</title>
            <link>https://medium.com/@germayneng?source=rss-395dc0d8af0d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:33:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@germayneng/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[What value should data-scientist be providing?]]></title>
            <link>https://medium.com/@germayneng/what-value-should-data-scientist-be-providing-ab1f3bdc2afc?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab1f3bdc2afc</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-scientist-career]]></category>
            <category><![CDATA[data-scientist-skills]]></category>
            <category><![CDATA[data-scientist]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Sat, 24 Jul 2021 16:49:16 GMT</pubDate>
            <atom:updated>2021-07-24T17:09:12.884Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a topic that I had several discussions on with colleagues of mine as well as friends. With co-pilot, and directions of autoML, 1-liner libraries to run algorithms, what should be the value of data-scientist?</p><p>TLDR: Personally, I feel that the value of a data-scientist should not be the ability to “write” just the latest machine learning API, but more towards critical thinking skills, problem solving abilities (generic), problem formulation as well as communication. I will try to touch on them more and relate them to personal experiences. Of course, having said that, technical ability is very important. However, those should not be the gauge in the ability of ease to write a script to train a model. (we will see why later and how can we gauge them?)</p><h3>Why knowing API is not really helpful</h3><p>I am sure you guys have seen the recent hype regarding the copilot tool which is an AI that is able to complete your code. You can easily find more examples of such auto-completes with examples on ML models from sk-learn, torch, TF…etc Basically this adds to the fact that most of such boiler plate codes are in the correct direction of getting automated. (which I think is definitely good)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*DUQrsqet3mFRj1TOyv-5Cg.gif" /><figcaption>Credit: <a href="https://machinelearningknowledge.ai/wp-content/uploads/2021/07/CRYPTO-PRICE.gif">https://machinelearningknowledge.ai/wp-content/uploads/2021/07/CRYPTO-PRICE.gif</a></figcaption></figure><p>We have also seen AutoML gaining prominence. (which can be a topic on its own) We also can see most ML libraries getting more user-friendly and tries to reduce the barrier of entry of training a complex neural network. For instance, we can see this in the early version of tensorflow 1 vs tensorflow 2 or even fast.ai’s wrapper. I think it is quite clear the current state of development for machine learning and it is a strong indicator that as we try to extrapolate this trend: the value in a data scientist&#39;s ability of a particular API is really diminishing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*XneaYNhxgRjdnITTf3KFLg.jpeg" /><figcaption>credit: KDnuggets</figcaption></figure><p>Moreover, based on my personal experience, having a good foundation and knowledge is enough for you to re-learn the APIs. One good example is that couple of years ago, I primarily use Keras functional API for neural networks. Later, when Pytorch gains prominence, I decided to familarize myself with Pytorch conventions. Long story short, I had to use Tensorflow 2, and they had introduced the <a href="https://www.tensorflow.org/guide/keras/custom_layers_and_models">Model subclass</a>. It then turns out to be really similar to Pytorch, allows lower-level control which fits my <a href="https://github.com/germayneng/kaggle-rainforest-connection-audio-2021/blob/master/rainforest_audio/model.py">used case</a>. All I need was just time to reference the TF documentation whenever I need it. My point is <strong>API changes all the time, </strong>and it should not be difficult to pick up if required. There should not be a focus on:</p><blockquote>Hey i know how to import X,Y libraries and bring Z API</blockquote><h3>“Do not focus on knowing how to write the API, rather understand how things work, why certain approaches might be better, or what are the trade-offs.”</h3><h3>Data-scientists are automating themselves out (to some extend)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*RpgDHNFOaVleS4AkQnG49w.png" /><figcaption><a href="https://xkcd.com/2054/">https://xkcd.com/2054/</a></figcaption></figure><p>A good and well-designed end-to-end machine learning system should be self-sufficient and robust. Basically, once you have such a system, you (as a data-scientist) should expect this system to <strong>run without intervention</strong> 99?% of the time.</p><p>E.g A data pipeline that generates required features for inference on a daily basis, a training pipeline that automatically batch-trains an updated model (be it on a fixed frequency or on a heuristic) , or even online training, as well as another system to monitor the entire machine learning system for drifts or system issue and alerts the time when required.</p><p>As such, when building such a robust system, isn’t it ironic that data-scientists are no longer needed when this is ultimately done?</p><h3><strong>Back to the question of value</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*vQWx2VEebdpiHkdq3ayfnw.jpeg" /><figcaption>Credit: kDnuggets.com</figcaption></figure><p>With all the points above, it may seem very pessimistic as a data scientist. The correct way to think about this is: <strong>what should data-scientist have that cannot be replaced and provides value to the business?</strong></p><p>For the first part of the article, I pointed that API knowledge should not be the main value a data scientist brings to the table and also pointed out the different reasons why, as well as how the entire tech development is heading to (in terms of machine learning, data science). I have also given on a surface level what the focus should be:</p><p><strong>Problem formulation, problem-solving &amp; critical thinking</strong>: Most data-science solutions in tech companies are not just out of the box where we can just import a library to solve them. You will have to understand the problem first, understand the business flow (if it is a complex system), the type of data that is available. (In tech companies there are thousands of tables, and usually, it is not intuitive what is available — since you do not know what you don’t know)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u_nxz4q8F8dUmwDSQXMwmQ.png" /><figcaption>The Cascades in machine learning, Google: <a href="https://ai.googleblog.com/2021/06/data-cascades-in-machine-learning.html">https://ai.googleblog.com/2021/06/data-cascades-in-machine-learning.html</a></figcaption></figure><p>Once there is a clear idea of the problem and what data is available, the next step is crucial — problem formulation. With the knowledge of different algorithms, how should we approach them? Note that at this step, as a data scientist, you are not restricted to just machine learning. Sometimes, it might make sense to utilize other algorithms (depends on the domain itself) or a custom algorithm to solve it. It could even be a case where machine learning is used as an intermediary step as part of the solution.</p><p>Regardless, knowing how to frame the problem such that an algorithm/series of algorithms can provide a solution is not as easy as it sounds. This requires a thorough understanding of the problem domain as well as a wide exposure to different approaches. (this step might also require research, paper reading…etc) The data-scientist will also need to consider the pros and cons of various implementations (especially from academic papers) and have the foresight to see the big picture/ consider future challenges before deciding on the approach.</p><p>As such, you can see: this aspect is important safe from any copilot, AutoML, or any other library.</p><p><strong>Communication</strong>. A data scientist needs to know how to communicate his/her thought process to stakeholders. Try to know your audience — usually, it might be tempting to lay out the technical approaches, but if you are facing C-level business leaders, it might make sense to think about explaining the impact of your solution and link to business outcomes, or a relative benchmark.</p><blockquote>E.g it might not make sense to say — Our model achieves 100 RMSE, as it does not really mean anything to external audiences</blockquote><p>Communication is not limited to verbal interaction — It includes writing good documentation/ RFCs that outlines the problem framing, solution, what was considered and why what kind of problems might not be accounted for as well as <strong>what kind of assumption was taken</strong>. This aspect will always be important, to communicate and be accountable for the system. I do not really see how this can be made redundant.</p><h3>I think we are still safe,… for now</h3><p>I think of data-scientist as modern-day’s take of data-driven problem solvers. We just get things done by framing the problem in the right way where we can use data, algorithms to obtain a solution that is data-driven, automated, and scalable. Don’t focus on the various “data-science” API, but instead question the inner-workings and why :)</p><p>What are your thoughts? Feel free to leave a comment :D</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab1f3bdc2afc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Series Cross-validation — a walk forward approach in python]]></title>
            <link>https://medium.com/eatpredlove/time-series-cross-validation-a-walk-forward-approach-in-python-8534dd1db51a?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8534dd1db51a</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sklearn]]></category>
            <category><![CDATA[forecast]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[crossvalidation]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Thu, 05 Sep 2019 10:57:57 GMT</pubDate>
            <atom:updated>2019-11-13T03:29:39.833Z</atom:updated>
            <content:encoded><![CDATA[<h3>Time Series Cross-validation — a walk forward approach in python</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/0*-PMOUcKUsQw7XMit.png" /><figcaption><a href="https://xkcd.com/605/">https://xkcd.com/605/</a></figcaption></figure><p>When we create a machine learning model, cross-validation allows us to validate if the model is in the direction we expect it to be. A good cross-validation scheme is one that emulates the test distribution well. Because when it comes to features engineering or hyperparameter tuning, you wouldn’t want a scenario that whatever changes you are making to not be indicative of future unseen data. Typically we call them our test set.</p><p>It is very easy to succumb to the common pitfalls of creating a bad validation scheme, where you are happily making ‘improvements’ and changes based on your validation metric but in fact, your model is not going to do well on your unseen data. But remember that ultimately, we will want a model that does well in future unseen test data.</p><p>A good guide to follow is to ensure validation scheme to follow as closely as test data. We will touch on that in details later below.</p><p>Today, I will discuss a form of validation that is used in time-series. Time series data are usually trickier to handle as compared to typical cross-sectional based data (think of them like different observation). In time series, we often have to respect the order between them.</p><p>This also affects feature engineering. (but that is a topic for another day) So why do we have to treat time series differently?</p><h3><strong>No Mixture</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/0*Yy91DjWd7S6YCRCn.jpg" /><figcaption><a href="https://www.ourniche.com/2017/04/12/jelly-bean-cocktails/">https://www.ourniche.com/2017/04/12/jelly-bean-cocktails/</a></figcaption></figure><p>Most general cross-validation techniques are not correct when it comes to time-series data/problems. Bootstrapping resampling (apart from time series bootstrapping), k-fold or stratified k-fold shuffles the data and does not ensure that there is the same coherence in your validation folds as compared to your actual test set. In fact, recall that your test data will be some period from the future.</p><p>A good way to understand is by doing so, <strong>the valid vs test distribution will not be the same</strong>. Not only are you attempting to learn from future data and predicting past validation, but you will also be creating validation scores that may not be accurate.</p><p>In kaggle, we often encounter what is known as a leaderboard shakeup. This happens because of reasons like</p><p>1. overfitting on small % of the test set (Leaderboard scores)</p><p>2. test set distribution is different from validation which results in bad model selection.</p><p>(This is definitely a topic on another level) But my point is to point out the importance of doing validation, especially for time-series data. Otherwise, you would not be able to distinguish the rotten apples!</p><p>Most time-series models/problems, in reality, also grows in size. For example, our training data grows every time period. We might be predicting short term (next month) or extrapolating some horizon h depending if we are using classical time series models, machine learning or neural networks. In the subsequent period, we will gain more data and the process repeats. Also, most of the time the model needs to be fitted / train with the new data before being able to forecast horizon h again.</p><p>This makes sense to use what is known as the walk-forward cross-validation / expanding window cross-validation.</p><h3><strong>Walking- forward</strong></h3><p>With that in mind, The usual train-test split will definitely work better than the k-fold approaches. By ordering your data from past to present and splitting the later half as valid data. However, the train-test split might not be a good gauge since we might want to avoid overfitting to your particular split.</p><p>In other words, where you choose to split plays a part in your validation result. To avoid luck as a factor and have a more robust result that we can trust, we can expand on this concept by doing what is known as walk-forward validation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*k5rqfNr1RXK5BnOAGI8gRA.png" /><figcaption>Hyndman, R.J., &amp; Athanasopoulos, G. (2018) <em>Forecasting: principles and practice</em>, 2nd edition, OTexts: Melbourne, Australia. OTexts.com/fpp2.</figcaption></figure><p>Professor Rob Hyndman illustrates this concept very well with the diagram above. In fact, we are doing ‘multiple’ split across the different time period, with the training data expanding each fold. In many cases, especially the work I personally do for product demand forecasting, this provides a more robust gauge of your model performance.</p><p>We then average the performance across the different folds based on the metric you decide (I.e MAPE, WMAPE..etc)</p><p>Of course walk forward validation is not restricted to just expanding by one period. Here is where you would want to match your test data as closely as possible. Depending on your data’s frequency, model type (arima, ets, GBM…etc) or even your objective, you might want to define a different initial length, period of data gain as well as horizon to validate on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*1JVA5-KVizOuSh9uk8W2xQ.png" /><figcaption>Hyndman, R.J., &amp; Athanasopoulos, G. (2018) <em>Forecasting: principles and practice</em>, 2nd edition, OTexts: Melbourne, Australia. OTexts.com/fpp2.</figcaption></figure><h3>My <strong>Python </strong>solution — walk forward cv</h3><p>If you are using Professor Hyndman’s forecast package in R, then you can simply call the <em>tsCv </em>function which wraps around. You will need to define a function that takes in your data x as well as horizon h, which you will need to fit into <em>tsCv().</em></p><pre>#Fit an AR(2) model to each rolling origin subset far2 &lt;- <strong>function</strong>(x, h){forecast(Arima(x, order=c(2,0,0)), h=h)} </pre><pre>e &lt;- tsCV(lynx, far2, h=1)  #Fit the same model with a rolling window of length 30 e &lt;- tsCV(lynx, far2, h=1, window=30) </pre><p>But python users are out of luck. For sklearn, there is a time series split. But it does not allow customization of an initial period for training (which is important, for instance, if you would like to train with minimum 2–3 years of data to capture seasonality), define a period of data that will be added at each step forward as well as horizon h. Sklearn version only allows us to define n_splits, where the splits between train and validation are defined as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*ZFrIa3bKz191HtE8W_rpwA.png" /><figcaption>Based on sklearn — <a href="https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html#sklearn.model_selection.TimeSeriesSplit">https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html#sklearn.model_selection.TimeSeriesSplit</a></figcaption></figure><p>As such, I have written my own version of the expanding window that follows the grammar of sklearn below:</p><p>It works just like other sklearn CV splits which returns your data index.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d498a2d1cba652d413b792b7b363c4ca/href">https://medium.com/media/d498a2d1cba652d413b792b7b363c4ca/href</a></iframe><h3>Closing</h3><p>Time series cross-validation is not limited to walk-forward cross-validation. A rolling window approach can also be used and Professor Hyndman also discussed Time-series bootstrapping in his textbook. Perhaps I will touch on it in another post. But for now, hope that the expanding window approach will provide an easier method to back-test for time series data!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8534dd1db51a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/time-series-cross-validation-a-walk-forward-approach-in-python-8534dd1db51a">Time Series Cross-validation — a walk forward approach in python</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Casino’s Big and Small — using Monte Carlo Simulation]]></title>
            <link>https://medium.com/eatpredlove/casinos-big-and-small-using-monte-carlo-simulation-3936f9bcf4bf?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3936f9bcf4bf</guid>
            <category><![CDATA[simulation]]></category>
            <category><![CDATA[casino]]></category>
            <category><![CDATA[gamblin]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Sat, 24 Aug 2019 18:37:07 GMT</pubDate>
            <atom:updated>2020-02-13T13:25:31.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>Casino’s Big and Small — using Monte Carlo Simulation</h3><h3>Background</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*E-x68jwwWr-7M7STdNJQJQ.jpeg" /><figcaption>I did not take any pictures of any casinos in Macau, so… credit: smarttravelasia</figcaption></figure><p>Back in 2018, it was my first experience at a casino in Macau (It was a dedicated day trip from Hong Kong). We chose one of the easiest (is that so?) game to play: <a href="https://en.wikipedia.org/wiki/Sic_bo">Big and Small</a> (Also known as Sic Bo). The rule is simple: choose either big or small.* The dealer will shuffle 3 dice and if the total sum is between 4 to 10, betting on small means you will win. If the total sum is between 11 to 17, betting on big means you will win. Winning net a payout of 1:1.</p><p>At this point, you might be thinking, what if I get a sum of 3?. There are special wins known as <strong><em>three of a kind</em></strong>: getting the same for all die. So 3 is one such possible combination (1,1,1) and results in a higher payout. [1]</p><p>Long story short, after watching a couple of games (maybe a little too much), we decided to bet on small after seeing that it was <strong>big for many games</strong>. This is where I fell to <a href="https://en.wikipedia.org/wiki/Gambler%27s_fallacy">gambler’s fallacy</a>. In fact, they have a monitor that outputs the result of the last 20 games (granting gamblers’ the illusion of control).</p><p>No price for getting the guess correct: I lost. Lucky for me, losing one game (100$) was bad enough and we decide to cash out and went on to visit other areas in Macau.</p><p>* There are many ways to place the bet. Big and small is one way and for simplicity, let’s stay with this.</p><h3>Applying Monte Carlo</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*7aaG6RKQSwjNPlvlxU-APg.jpeg" /><figcaption>Simulation like Black Mirror’s San Junipero</figcaption></figure><p>Wouldn’t it be good if life is like a game where we can reset whenever something goes wrong? Suppose we have infinite chance and money and if we were to continue betting in big and small, will we actually win? Was it a one-time off thing that we lost?</p><p>I am curious if I were to continue (assuming infinite wealth), what would be the outcome? Monte Carlo simulations will allow us to answer some of that.</p><h3>Assumptions and some simple math</h3><p>Big and small does have some additional rules on top of what I had described above. However, to simplify this exercise, let us simply assume:</p><ol><li>All payout will be 1:1</li><li>Let us also exclude the special wins: three of a kind (1,1,1…etc)</li><li>The choice in big and small results in the same probability, so it does not matter if we choose big or small. Mathematically, choose big all the way or small all the way gives us the small probability of winning anyway. As such, all we need to do is to simulate the same probability of the actual game in our simulation!</li></ol><p>Therefore, it is important to know what is the probability of winning. One easy way to compute this probability is to take the possible combinations for small divided by the total possible combinations of 3 dice. It is enough to focus on computing the probability of winning ‘small’. (Computing the probability for small is the same as big)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*uBNWDhX0aLv6uXsdrHQDcw.png" /><figcaption><a href="https://www.thoughtco.com/probabilities-for-rolling-three-dice-3126558">https://www.thoughtco.com/probabilities-for-rolling-three-dice-3126558</a></figcaption></figure><p>Also, remember that we should exclude three of a kind. Possible combinations are (1,1,1) to (3,3,3) for small, which we need to exclude. This will give us 107–2 = 105 combinations out of 216 = odds of winning to be 48.61% as verified [2]</p><p>In other words, this meant that the <strong>house edge</strong> is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*fxyliy7oKZGu9t1tsvxZcg.png" /><figcaption>House edge of -2.78%</figcaption></figure><p>You can also see the above as the expected value. Seems like the odds are already against us before we start betting.</p><h3>The Simulation (Actual)</h3><p>Now, for the actual simulation, all we need to do is to simulate the same odds as we derived. <em>I will post the link to the code at the end of the article.</em></p><p>Suppose I have 1000$. For each game, let us attempt to bet 100$. If we decide to go all out, we have the opportunity for 10 games. Now, in reality, we only have 10 chances. But now, in a simulated reality, we can play 10 games, reset, play 10 games..etc. So let us try to simulate 2000 instances with 10 consecutive games each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9gQ415FRXrde_5cDTyIFQ.png" /><figcaption>redline = expected value = $971</figcaption></figure><p>In order to visualize the results, we can simply plot the 100 instances out with each color lines representing an instance. (So there are 100 instances or lines). Let us view the distribution to have an even better idea of the 100 instances.</p><p>In order to visualize the results, we can simply plot the 2000 instances out with each color lines representing an instance. (So there are 100 instances or lines). Let us view the distribution to have an even better idea of the 2000 instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-1N_z0Fhcrbf95Z1cutMQ.png" /></figure><p>There is near 50–50 chance of either losing or winning above your initial capital (chances moving towards losing as we can see from our expected reward). Let&#39;s repeat this with more instances (5000 instances) to see if the conclusion remains the same.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaKdggU_v63bWzkE1OhZOQ.png" /><figcaption>redline = expected value = $972</figcaption></figure><p>At 5000 instances, we get a pretty similar result as 2000 instances, with expectation below our initial capital on average across all instances.</p><p><strong><em>Other analyses have shown that longer games lead to an even lower chance of winning</em></strong> [2] Is this similar for the case of sic bo? Let&#39;s see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KTi1Lnxs-g0vfz0tobZ5ew.png" /><figcaption>redline = expected value = $715</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G3qxZ5I11wHjXxLXj2TpAQ.png" /></figure><p>The above is the histogram of 100 games per instance and we went for 2000 instances. In this scenario, we can see some instance reaching negative capital and the overall expectation is much much lower than 10 consecutive games. We definitely should not play a longer game.</p><p>** Also keep in mind, in order to play beyond your capital, we have to assume that there is some form of leverage or loan involved. But since we are in simul land, we can go beyond what we started.</p><h3>Conclusion</h3><p>It is interesting to simulate our gambling experience again using Monte Carlo with some simple loops and plotly to visualize our results. The results might not be conclusive. We can improve by adding including more accurate sic bo rules as well as setting more instances to get a better distribution. Try it yourself! You can pretty much simulate any games as long as you know the probability as well as the rules.</p><p>Keep in mind that such games are meant to bring out the gambling nature in us. Sometimes we just want to believe that we are able to overcome the odds.</p><h3>Code</h3><p>The code is available at <a href="https://github.com/germayneng/simple_monte_carlo_big-and-small">https://github.com/germayneng/simple_monte_carlo_big-and-small</a></p><h3>References</h3><p>[1] <a href="https://wizardofodds.com/games/sic-bo/">https://wizardofodds.com/games/sic-bo/</a></p><p>[2] <a href="https://towardsdatascience.com/the-house-always-wins-monte-carlo-simulation-eb82787da2a3">https://towardsdatascience.com/the-house-always-wins-monte-carlo-simulation-eb82787da2a3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3936f9bcf4bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/casinos-big-and-small-using-monte-carlo-simulation-3936f9bcf4bf">Casino’s Big and Small — using Monte Carlo Simulation</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kaggle Home Credit, a silver solution (Top 5%)]]></title>
            <link>https://medium.com/eatpredlove/kaggle-home-credit-solution-20328c80a226?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/20328c80a226</guid>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[kaggle-competition]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Fri, 21 Dec 2018 08:07:07 GMT</pubDate>
            <atom:updated>2019-08-22T07:21:45.410Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*F9359FbLmjD_wwn2-O0Iew.png" /></figure><h3>Overview</h3><p>After the end of the competition 3 months ago, there were heavier workload as well as more commitments in real life. Therefore, this is really very overdue. But “Better to be late than never”. I briefly posted my thoughts previously <a href="https://medium.com/germayne/wrapping-up-kaggles-home-credit-competition-c660c2c55524">here</a>. In this article, I will not go through the details ( I believe there are many gold solutions out there) but instead, share what I did differently.</p><p>Back to business: This competition requires kagglers to build a credit-scoring model of sorts. The main objective is to classify if a given individual did not repay the loan (1) and otherwise (0). The fun part is that we are given lots of data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s6uRljTMIgyBCD1ok4gfrg.png" /><figcaption>Source: <a href="https://www.kaggle.com/c/home-credit-default-risk/data">https://www.kaggle.com/c/home-credit-default-risk/data</a></figcaption></figure><p>Essentially, we have the main data (application) as well as different information of the users. (credit card, previous loans, installments… etc) In order words, we have to find methods to combine them. (since the target variable is in the main application df) This also gave room for creativity when it comes to feature engineering.</p><h3>Features Engineering</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r5N3pq9D8MI617YO_Cirxg.jpeg" /><figcaption>Early whiteboarding</figcaption></figure><p>Features engineering is the place where we data scientist expresses our creativity.</p><p>The features engineering process can be split into 2 phase:<br>1) Side Data</p><p>2) Main Data</p><p>Side data includes <strong>bureau, credit, installments, cash </strong>as well as the <strong>previous loans</strong>. They have to be aggregated before merging to the main data(application_train/test). We can see, for example, multiple entries of customer A, while in the main data, we only have unique entries of a customer. (1 customer A)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErmztgQYb0Tep33SkJIy9w.png" /><figcaption>A look at<strong> preprocessing.py</strong>. Feature engineering of side data.</figcaption></figure><p>Some of them are time series data, as such, we can take into account things like the latest or earliest K data before aggregation.</p><p>Aggregation usually involves the standard statistics: <strong>Mean, Mode, Median, Sum, Variance/Std, Kurtosis, Skew</strong>, as well as <strong>Linear regression</strong>. Linear regression involves regressing the grouped data with a time index and using the beta coefficient as features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*vhvXVDiJS0cyzimBIx527Q.png" /><figcaption>An illustrated example of side data. Multiple entries for a customer</figcaption></figure><p>Apart from the multiple numerical entries that we need to aggregate, there are also various categorical features. Since it is a many to one mapping to the main data, we must think of some methods to aggregate them. Some methods to do so will be to one-hot-encode them and taking the average. Other methods include target-encoding and averaging the encoded categorical.</p><p>Once features engineering are done on the side data, we can apply the same to the main data.</p><h3>Features Embedding</h3><p>Similar to word2vec, we are also able to get the embedding spaces for some of the categorical variables. For more information, you can refer to this <a href="https://arxiv.org/abs/1604.06737">paper</a>. By training on all the data, with embedding layers for the categorical variables, we can later extract the embedding layer as features for our main model. (XGB/LGBM)</p><p>At the same time, the same Feed Forward NN which I used for the embedding extraction can also be used as a different model for ensembling. However, it is not really useful (Not surprising here since I did not do much tunning on its overall architecture)</p><p>Structure of the NN is as such:</p><ul><li>Multi-head input model taking in the different categorical variables</li><li>Embedding layer for each input to reduce the dimension space</li><li>Flatten layer after each embedding layer</li><li>Usually 2 super dense RELU layer (1000, 500)</li><li>End with a sigmoid</li></ul><h3>Features Interactions</h3><p>Features interaction is something that I focused on as well. There are 2 main ways in which I induced features interactions in the model: Compute <a href="http://helios.mm.di.uoa.gr/~rouvas/ssi/sigkdd/sigkdd.vol3.1/barreca.pdf">target/mean encoding</a> grouped by the collection of variables. I.e if I need the interaction of V1 and V2, I can compute the mean encoding of V1-V2 combination.</p><p>I used a custom function to do it because I want to have more flexibility and control during the genetic algorithm stage (see below). Otherwise, you can find a module to implement it here. (I have not used it personally so I am not sure if it is the same)</p><p>The target encoding will be introduced in each cross-validation layers after the splitting and before the modeling. This ensures no leakage from the valid data sets while the encoding is computed only from the train. Other measures I added is to split the train into yet another inner 20 fold before computing the encoding.</p><p>Another way to induce features-interaction is to make use of LibFM. The paper is described <a href="https://www.csie.ntu.edu.tw/~b97053/paper/Rendle2010FM.pdf">here</a>. Of course, I was inspired by <a href="https://www.kaggle.com/cpmpml">CPMP</a> for this approach. Using Keras, we can build an NN and extract its embeddings trained on the features in which we want to induce its interaction. This concept runs heavily on factorized machines for recommendation systems.</p><p>We will extract these paired interactions as:</p><blockquote><em>Factor + Bias</em></blockquote><p>Another additional point is the flexibility to define the number of latent variables we want. With the factor and bias extracted, we can add them as features to your main model. I have created several interactions and extracted the factor + bias as features for various models. I will include them later in the stacking process.</p><h3>Modeling &amp; Cross-validation</h3><p>My main go-to algorithm in this competition is <a href="https://lightgbm.readthedocs.io/en/latest/">LightGBM</a>. Due to the large dimension of the dataset (especially after Features engineering), I prefer the speed that LGBM offers. One thing that I found out late was that after LGBM version 2.1.2, there is this parameter known as boost_from_average. <a href="https://github.com/Microsoft/LightGBM/issues/1487">By default, it is True</a>. As such, most of my models from AWS are based on this parameter. I had to re-trained some of the models with the setting turned to False. But this actually provided me with even more diverse models, which added to the diversification needed in stacking later on.</p><p>I also tried Xgboost early on in the competition but ended up sticking to LightGBM throughout. Catboost was not used since I have my own encoding pipeline but I might try them out in future (Catboost’s core advantage over others is in its own encoding functions).</p><p>Not forgetting <a href="https://blog.keras.io/introducing-keras-2.html">Keras 2.0</a>, utilizing it for embedding weights as well as libFM. I kind of love the new standard way of defining the Neural network.</p><p>As for cross-validation, I am sticking it with the usual 5-fold CV. No particular reason why it is preferred over stratified 5-fold CV apart from the fact that it provides the same directional relationship with the leaderboard (positive correlation). This ensured that I can believe in my local 5-fold cv and not overfit to the public leaderboard.</p><p>An important point to note is to ensure the same validation split to have:</p><ol><li>Fair comparison across models</li><li>No leakage when staking later on (since this affects the OOF)</li></ol><p>I have also spent time setting up my own personal modeling code structure in this competition (including the validation structure). This helps in future and especially later on for my genetic selection, where you would have more control to automate the modeling process.</p><h3>Genetic Selection</h3><p>This was the main reason for my USD100 AWS cost at the end of the competition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWJJfLTNC-IRukPUvB8J5Q.png" /><figcaption>Bot timestamp (collected on telegram) of each generic runs ran on AWS</figcaption></figure><p>This is also inspired by a fellow kaggler known as <a href="https://www.kaggle.com/jacekpoplawski">Jacek</a> who briefly described this in a previous competition (Porto). The best kagglers are often the ones who learned from the best. Based on my understanding of his description, I implemented my own version. The idea is very simple:</p><ol><li><em>Select a base of good features. I believe I started with 160 features. There are many ways to do this. Either via forwarding selection or by features importance gain. I ran a base model with LightGBM on the entire features space, extract the features importance and subset to those with importance gain &gt; 1000.</em></li><li><em>Create a master list of features (3000) as well as interactions (any possible interactions). I played pretty safe and only interacted non-cat with non-cat as well as cat with cat.</em></li><li><em>Generation 1: Randomly select features not in your base model (160) from the master list and interaction list.</em></li><li><em>Run Generation 1 over 20 times? — select the best 2 models.</em></li><li><em>Take the total distinct features of the 2 models. Simply: Distinct(Features_Model_1 + Features_Model_2)</em></li><li><em>Create a “mutation layer” for (5). and add random features from the master list of features (3000) as well as interactions (any possible interactions). </em><strong>This layer also takes a proportion of the new subset of features (I set to P= 0.8). Reason for this is that I do not want the number of the subset of features to grow for each generation. As such, I want to introduce a form of ‘dropping’ features.</strong></li><li><em>Generation 2: Repeat (3) and (4) while using the product from (6) as the base.</em></li><li><em>Run this over Nth generation, where for each generation we take a good subset of features and add some random element.</em></li></ol><p>Basically, I wanted an automatic approach to select the best features. This approach allows me to systematically try different features interactions amongst the features. Moreover, it is largely automatic. The algorithm runs in AWS while I get to monitor the progress on my phone (I ran the algorithm mostly overnight, through work..). I could disable AWS easily via the AWS mobile app.</p><h3>Final Essemble/ Stacking and fingers crossed</h3><p>I have the advantage of a diverse number of models ran on a different subset of features as well as interactions. I believe by the end of the competition, I have nearly 1000 automatically generated models.</p><p>The final solution is a blend of 2 different stacks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hNvDOOEfuJMg8roxCtac6w.jpeg" /><figcaption>Typical stacking pipeline</figcaption></figure><p>Stacking is where we train the out-of-fold predictions of each model and apply it to the test-predictions. The idea is that it will optimize the weight of each model (think regression: intersection + w1 * Model_1 + w2 * Model_2… )</p><p>In this case, I have tried using Xgboost as the stacker but through experimentation, Ridge regression/ logistic regression gave the best results (CV). In the end, I decided to use Ridge regression as the main stacker. (level 1 stacker)</p><ol><li>Stack A using Ridge regression on a myriad of Good Models (Genetic), as well as different libFM models</li><li>Stack B using Ridge regression on other sets of Good Models (Genetic) as well as different libFM models. Some of the models I ran it again using <strong>LGBM</strong>’s <em>boost_from_average = False</em></li><li>Apply a blend (weighted average) on 1 + 2. The blend weight is estimated using 5 fold CV (the same fold used in modeling) for the highest ROC-AUC.</li></ol><h3>Closing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OY_j_PGqc3hV3Q2L9e7AtA.png" /><figcaption>Final closing placement. Total of 92 submissions</figcaption></figure><p>This is definitely a good experience. Not my first solo kaggle competition and not my last. But I definitely learned a lot more when it comes to optimizing my code (as I structured it for AWS). Also pretty contented that I remained pretty stagnant in the leaderboard (no overfitting).</p><p><em>Now, when shall I begin my journey for my gold medal? (Last piece to a kaggle master)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20328c80a226" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/kaggle-home-credit-solution-20328c80a226">Kaggle Home Credit, a silver solution (Top 5%)</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wrapping up Kaggle’s Home credit competition]]></title>
            <link>https://medium.com/eatpredlove/wrapping-up-kaggles-home-credit-competition-c660c2c55524?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c660c2c55524</guid>
            <category><![CDATA[competition]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[homecredit]]></category>
            <category><![CDATA[kaggle]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Thu, 30 Aug 2018 09:53:42 GMT</pubDate>
            <atom:updated>2018-12-27T10:26:18.535Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hgcevWk-efKZeMhJeWWL8w.png" /><figcaption>Credit: Yahoo Finance</figcaption></figure><p>Despite being busy with my schedule recently, I managed to obtain a silver medal (top 5% placement) in this competition. I did struggle because i was doing it alone, which meant that I had to juggle the entire competition pipeline with other commitments / work. But I am glad the effort did pay off eventually. :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2IbL0kR5K1bC7QSgeYqjEw.png" /><figcaption>silver placing: 344th out of 7198 participants</figcaption></figure><p>However, I felt that I could do better. I will elaborate more when I explain some of the methodologies that I have adopted in this competition in another post. At the same time, I made a costly mistake: not selecting my best submission. Luckily, this did not cost me heavily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CCEHP-lASXG6faenBMxNWQ.png" /><figcaption>solution 0.79639 gives a 292th ranking</figcaption></figure><p>I am definitely more adventurous in this competition, utilizing more tools (LibFM as well as Keras). But due to time/ resource constraints, I am not able to do everything I had planned out.</p><p>On a side note, the cost of this silver medal is pretty hefty. Looking at how much AWS cost I racked up…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uKTx7W1G7TRul7PSXtQCEw.png" /><figcaption>101 USD</figcaption></figure><p>Most of the time, I am using t2.2xlarge since it is the most cost efficient instance in my opinion. ( If you guys have better / cheaper options, do share with me! ) If I am getting memory error or I need some of the big guns (i.e GPU), I will either use c5.4xlarge (computation), r4.2xlarge (memory) or the g3.4xlarge (cheap gpu).</p><p>In conclusion, this is definitely a competition that is very intense and fun. I definitely learned more regarding credit scoring. On hindsight, I definitely should use all the variables in the data, which should give a stronger model. I will be posting the unique strategies that I had utilized in another post once I have cleared and clean everything up.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c660c2c55524" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/wrapping-up-kaggles-home-credit-competition-c660c2c55524">Wrapping up Kaggle’s Home credit competition</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Filling in gaps in time series data]]></title>
            <link>https://medium.com/eatpredlove/filling-in-gaps-in-time-series-data-50e240e1e31f?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/50e240e1e31f</guid>
            <category><![CDATA[r]]></category>
            <category><![CDATA[timeseries]]></category>
            <category><![CDATA[data-cleaning]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 09:29:13 GMT</pubDate>
            <atom:updated>2018-12-23T07:27:07.711Z</atom:updated>
            <content:encoded><![CDATA[<p>In my current job, I deal with lots of time-series based data. As opposed to cross-sectional data, the temporal ordering of each row is very important. This also makes working with time-series based data more tedious. ( you have to take extra care, else you might make some mistakes. But that is a story for another day)</p><p>Today, I will want to discuss on a particular problem: gaps in time-series data. Imagine you have a data set on 1000 stores across a time period of 2014 to 2017 monthly data. There will be scenarios where some stores, say store 1, only recorded data in certain months. For the sake of this example, let us assume that store 1 has missing data points for some months in 2016 and 2017 while everything is intact. At the same time, store 2 has missing data points for some months in 2014 and 2015. Essentially, all 1000 stores do not have a full 36 monthly data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*2j1PEi1-GdEGb-4nDjCJXw.png" /><figcaption>Typical missing data which you do not find in Kaggle</figcaption></figure><p>The problem arises when you want to create some time features, and a basic one that comes to mind will be ‘’previous month’’. A simple way to do so will be applying a lag of 1 period grouped by the stores. However, since the data across the 1000 stores are having different periods, doing a lag transformation will result in a wrong output.</p><p>A simple solution is to do a pivot on the data and revert back to the original form. Doing so will automatically generate the missing period. If you are a R user, it will be tidyr::separate and tidyr::gather while if you are a python user, it will be the .pivot and then .melt method from pandas. Below is an example in R. You can apply the same logic for pandas. (In fact, you can refer to another article that I have regarding pandas pivot)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dffe0717fd3df293a3f093128fb0c40/href">https://medium.com/media/4dffe0717fd3df293a3f093128fb0c40/href</a></iframe><h3><strong>What if all the stores have incomplete data?</strong></h3><p>So the above scenario works out if one of the stores has the complete date. For example, if monthly, then one of the stores should have 12 months of data. If it is daily, then one of the stores should have 365? rows of daily data. Otherwise, one simple hack is to append a “mock data”. With this mock data, you can generate with the same headers (as your main data frame) as well as generate a sequence of date. Below I will illustrate this example for daily data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0fabe132575faa615dba65788a9b73e0/href">https://medium.com/media/0fabe132575faa615dba65788a9b73e0/href</a></iframe><p>if you are on python, You can do this similarly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4359c3e30b1ecaed0d47da0d81df2822/href">https://medium.com/media/4359c3e30b1ecaed0d47da0d81df2822/href</a></iframe><p>Once you append it, continue pivoting (tidyr on r/ pivot on python) and undo the pivot and you should have all the respective stores with all the dates as well as NA for the sales. Now you can either leave it as such or replace them with 0.</p><p>So I hoped that these little tips helped you in manipulating these pesky time series data!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50e240e1e31f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/filling-in-gaps-in-time-series-data-50e240e1e31f">Filling in gaps in time series data</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About…]]></title>
            <link>https://medium.com/eatpredlove/about-me-f70a17c7e14?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f70a17c7e14</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[germayne]]></category>
            <category><![CDATA[about]]></category>
            <category><![CDATA[data-scientist]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Mon, 02 Jul 2018 05:40:05 GMT</pubDate>
            <atom:updated>2018-12-24T03:14:17.273Z</atom:updated>
            <content:encoded><![CDATA[<p>Eat, Pred, Love is a medium where I express my interests in data science, computer science as well as any mathematical concepts which I find interesting from my journey in the data science magical realm.</p><p>Data science is an up and coming field in various industries or verticals. One can also argue that it is simply a rebranding of statisticians or computer scientist.</p><blockquote>So what is a data scientist?</blockquote><p>Josh Wills once quote on <a href="https://twitter.com/josh_wills/status/198093512149958656?lang=en">twitter</a>:</p><h3>Data Scientist (n.): Person who is better at statistics than any software engineer and better at software engineering than any statistician.</h3><p>Another good analogy would be to compare data scientists to chefs. The data will be equivalent to the raw ingredients. Machine learning algorithms, R, python will be similar to kitchen equipment. It is the art for data scientists/ chefs to wipe up something good from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*26tLzd-yczS5bFZa.png" /></figure><h3>About myself…</h3><p>My personal interests are in state of the art machine learning and deep learning application. I feel that embarking on a data science route requires you to not be afraid of learning. The development currently is rapid and new technologies, APIs, papers are being released on a daily basis.</p><p>Since young, I have been intrigued by how artificial intelligence works (see Will Smith’s I,Robot). In my free time, I love to participate in kaggle competitions. If you are curious about the application of data science in different industries, there is no platform as extensive as kaggle.</p><p>I hope this platform can bring about some food for thoughts/ help anyone. Feel free to leave some comments in any of the posts :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f70a17c7e14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/about-me-f70a17c7e14">About…</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy guide to installing keras + Tensorflow]]></title>
            <link>https://medium.com/eatpredlove/easy-guide-to-installing-keras-tensorflow-3444b1379fed?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3444b1379fed</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Fri, 27 Oct 2017 02:00:00 GMT</pubDate>
            <atom:updated>2018-12-27T10:33:56.944Z</atom:updated>
            <content:encoded><![CDATA[<p>Getting ready for deep learning is not as hard as you might think. (minus the modelling and architecture process, underlying mathematics)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*T-OuwWLoSqRTt9Ax.png" /></figure><p>In this post, we will go through a simple tutorial to get started with deep learning on your pc/ laptop. Many people are freaked out at the initial set up process. It is not as complex as you think so, let us get on to it! At the end of this post, you will be able to install tensorflow with keras backend on your laptop and you will be able to start running some deep learning models like a scientist!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/0*CWqnz5fZel0yBvbK.jpg" /><figcaption><em>what i feel when i think of deep learning</em></figcaption></figure><p>I will assume you have <a href="https://www.anaconda.com/download/">anaconda3</a> environment installed, because it is really the best environment when it comes to doing data science using python.</p><p>Also, make sure you have a pretty decent Nvidia graphics card if you are using a laptop. (although this pretty much applies to desktop) Personally, I use a gaming laptop for doing much of my data science work.</p><p>With that, let us begin.</p><h3>Tutorial</h3><ul><li>There will be 2 prerequisites to be able to run deep learning. We need to have <strong>CUDA Toolkit 8.0</strong> as well as <strong>cuDNN v5.1 for CUDA 8.0</strong>. As for now, you have to exact version of the 2 programs.</li></ul><p>we will get cuDNN v5.1 <a href="https://developer.nvidia.com/rdp/cudnn-download">here</a> as well as Cuda 8.0 under the archives <a href="https://developer.nvidia.com/cuda-toolkit-archive">here</a></p><ul><li>Once you have downloaded them. Install CUDA 8.0. I believe at the point where I was installing, they also required me to install Microsoft visual studios. If during installation, you were prompt, then go ahead and <a href="https://www.visualstudio.com/downloads/">install MVS</a> then return to install Cuda. (I downloaded the community version)</li><li>Now, place your entire cuDNN file (unzipped) into your C: directory. Once that is done, you will have to add this to the environment path.</li></ul><pre>C:\cudnn-8.0-windows10-x64-v5.1\cuda\bin</pre><p>If you do not understand about environmental path, what you need to do is: Right click my computer &gt; advanced system settings &gt; environmental variables. You will see system variables. Scroll to this PATH variable and add the above line into it.</p><ul><li>Create a new python environment solely for this. To do so, open <strong>anaconda prompt</strong> and type this:</li></ul><pre>conda create -n deeplearning python=3.5 numpy scipy matplotlib spyder ipython notebook</pre><p>You can replace deeplearning with any name you want to. deeplearning is the name of the new python environment you will be creating. In this tutorial, I will be creating my environment as deeplearning</p><ul><li>Once done, you must activate this environment. In future, if you want to do your deep learning, you must first activate this environment before proceeding:</li></ul><p>Then with deeplearning environment activated,</p><pre>pip install --ignore-installed --upgrade <a href="https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.1-cp35-cp35m-win_amd64.whl">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.1-cp35-cp35m-win_amd64.whl</a></pre><p>Once it is done, continue to install keras:</p><ul><li>At this point, you are done! <a href="https://github.com/antoniosehk/keras-tensorflow-windows-installation/blob/master/examples/mnist_mlp.py">Download this</a> sample py file and run it. It should take few minutes, indicating everything is done correctly.</li></ul><p>To run the file, again, go to anaconda prompt,</p><pre>activate deeplearning python mnist_mlp.py</pre><h3>Others</h3><ul><li>if for some reason you are not installing correctly, you can check if tensorflow is using gpu. You should see <strong>GPU</strong> appearing.</li></ul><pre>from tensorflow.python.client import device_lib print(device_lib.list_local_devices()) </pre><h3>Future</h3><p>In future, I will go through some compiled methods to set up your own cloud instances (AWS.. etc), since most people will not have a powerful local machine to go for deep learning. Moreover, there is a chance that running keras/tensor on your machine might damage it in the long run.</p><p><strong>Tags: </strong><a href="https://germayneng.github.io/tags/#deep">deep</a>, <a href="https://germayneng.github.io/tags/#keras">keras</a>, <a href="https://germayneng.github.io/tags/#learning">learning</a>, <a href="https://germayneng.github.io/tags/#python">python</a>, <a href="https://germayneng.github.io/tags/#tensorflow">tensorflow</a></p><p><strong>Categories: </strong><a href="https://germayneng.github.io/categories/#tutorial">tutorial</a></p><p><strong>Updated:</strong> October 27, 2017</p><p><em>Originally published at </em><a href="https://germayneng.github.io/Getting_started_with_deep_learning.html"><em>germayneng.github.io</em></a><em> on October 27, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3444b1379fed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/easy-guide-to-installing-keras-tensorflow-3444b1379fed">Easy guide to installing keras + Tensorflow</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The new kids on the block - Elastic net, LASSO and ridge]]></title>
            <link>https://medium.com/eatpredlove/the-new-kids-around-the-block-elastic-net-lasso-and-ridge-faf4523474db?source=rss-395dc0d8af0d------2</link>
            <guid isPermaLink="false">https://medium.com/p/faf4523474db</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[germayne]]></category>
            <category><![CDATA[regularized-regression]]></category>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[statistics]]></category>
            <dc:creator><![CDATA[germayne]]></dc:creator>
            <pubDate>Thu, 22 Jun 2017 03:00:00 GMT</pubDate>
            <atom:updated>2018-12-27T10:35:24.551Z</atom:updated>
            <content:encoded><![CDATA[<h3>The new kids on the block — Elastic net, LASSO and ridge</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wkgTiMP8jKFwhaSf.jpg" /><figcaption>The new kids</figcaption></figure><p>Elastic net, lasso and ridge are the new cool kids that joined your neighborhood. They provide the union of statistics and machine learning. They are known as pernalized regression models.</p><h3>“ My personal bias is this: In this day and age, if you are building linear models without any regularization, you must be really special. Always regularize. It’s required.” — <a href="https://nycdatascience.com/blog/meetup/featured-talk-1-kaggle-data-scientist-owen-zhang/">Owen Zhang, NYC data science academy</a></h3><p>Penalized regression helps to deal with 2 major issue in regression: feature selection and multicollinearity. It helps to prevent overfitting and outputs a model that fits the training data less well as compared to OLS but able to capture the generalization better and less sensitive to variation from outliers. Elastic net is a general form of ridge and lasso. Think of it as a combination of both. Recall in usual regression, we make use of OLS — minimizing the sum of squares of the difference between actual and predicted values.</p><p>Assuming we have M number of features and N number of data points:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*--CVq5KnJDldsGwpOEB_Eg.png" /><figcaption>The original OLS</figcaption></figure><p>Whereas the elastic net regularization estimate process will minimize the sum of squares and a penalty based on the size of the estimated coefficient. We call these penalties the L1 / L2 Norm</p><p>The hyperparameter lambda controls the weight of the penalty. The optimal value of alpha and lambda is obtained using a grid search method for the best cv value (k-fold cv)</p><p>Depending on which penalty is imposed, it will be known as Ridge (L2 ) or Lasso (L1).</p><h3><strong>Ridge Regression</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*HhT9Bbz3064asY2P3n-_tQ.png" /><figcaption>Residual sum of squares with additional penalty (L2)</figcaption></figure><ul><li>Ridge helps to deal with the instability of estimates of coefficient of linear models when they are collinear.</li><li>Coefficients of unimportant features will shrink to <strong>near zero</strong></li><li>Hyperparameter alpha = 0</li><li>Minimize the objective (RSS + L2 Norm)</li><li>As lambda increases, RSS increases and model complexity decreases</li></ul><h3>Lasso regression</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*iwkex__FnZYoQtF8t1wvIA.png" /><figcaption>Residual sum of squares with additional penalty (L1)</figcaption></figure><ul><li>Lasso perform feature selection that forces coefficents for some variables to be zero.</li><li>Hyperparamter alpha = 1</li><li>Minimize the objective (RSS + L1 Norm)</li><li>As lambda increases, RSS increases and model complexity decreases</li><li>Note that LASSO will remove variables (giving coefficient 0) so as lambda increases, expect high sparsity.</li></ul><p>Theoritically, if lambda = 0, then it will be minimizing only the RSS and this will be the regular regression that we know. However, as pointed out by <a href="http://ellisp.github.io/blog/2016/08/13/fitbit-lasso">peter</a>, the result output by <strong>glmnet</strong> will be different due to numerical calculation issues.</p><h3>The best of both worlds?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*IO3BTHuQz_vr24hMZUVwow.png" /></figure><p>By having both penalties together, it will give us the elastic net regularization. (2005)</p><p><em>Originally published at </em><a href="https://germayneng.github.io/Elastic_Net_Regularization.html"><em>germayneng.github.io</em></a><em> on June 22, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faf4523474db" width="1" height="1" alt=""><hr><p><a href="https://medium.com/eatpredlove/the-new-kids-around-the-block-elastic-net-lasso-and-ridge-faf4523474db">The new kids on the block - Elastic net, LASSO and ridge</a> was originally published in <a href="https://medium.com/eatpredlove">eat-pred-love</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>