<?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 Dragos Cojocari on Medium]]></title>
        <description><![CDATA[Stories by Dragos Cojocari on Medium]]></description>
        <link>https://medium.com/@dragoscojocari?source=rss-b88d487d1e82------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QBIDfPWp6rpFOIEW</url>
            <title>Stories by Dragos Cojocari on Medium</title>
            <link>https://medium.com/@dragoscojocari?source=rss-b88d487d1e82------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 04:35:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dragoscojocari/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[Machine Learning — please report to the yogurt stand]]></title>
            <link>https://dragoscojocari.medium.com/machine-learning-please-report-to-the-yogurt-stand-12673c02737a?source=rss-b88d487d1e82------2</link>
            <guid isPermaLink="false">https://medium.com/p/12673c02737a</guid>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Dragos Cojocari]]></dc:creator>
            <pubDate>Fri, 26 Aug 2022 13:16:25 GMT</pubDate>
            <atom:updated>2022-08-26T13:41:14.782Z</atom:updated>
            <content:encoded><![CDATA[<h3>Machine Learning — please report to the yogurt stand</h3><p><strong>Practical ML</strong></p><p>When ML and AI are brought up in a conversation, it’s usually Neural Networks, image recognition, computer generated art , autonomous robots and lots of other wondrous things that we first think of.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/0*Bt-GATTms44PdQ3g.png" /><figcaption>A robot eating yogurt — image created by AI at <a href="https://hotpot.ai/s/art-maker/8-aFgoNDEnWuNOtsh">https://hotpot.ai/s/art-maker/8-aFgoNDEnWuNOtsh</a></figcaption></figure><p>But we can and we need to apply this technology to solve tasks that are far simpler yet have an equally large impact. <strong><em>What if we’d be able to predict that yogurts are about to expire on the shelves and thus prevent food waste?</em></strong></p><p>This problem is certainly not as cool as the autonomous robots from <a href="https://www.bostondynamics.com/">Boston Dynamics</a> but it saves the store employees from doing tedious tasks, allowing them to use time for more creative endeavors.</p><h4>Where we are?</h4><blockquote>A <a href="https://www.capgemini.com/gb-en/wp-content/uploads/sites/3/2020/06/AI-powered-enterprises_30June2020-1.pdf">study made by Capgemini</a> shows that <strong>only 13% of the companies that adopted ML use the technology in a consistent, continued manner</strong>. We are talking about multi-billion-dollar companies that have <em>the will, the need and the resources</em> to support such projects. And yet the results are sub-par which leads to the question: is Machine Learning that difficult to use on daily business processes?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfVdAOcjGDZlQiumBJzTMA.png" /></figure><h4>So what is this article about?</h4><p>There is a huge amount of data generated by industrial and business processes, data gathered without ever being used. This happens despite many claiming that <strong>data is the oil of the 21st century</strong>. We partnered with one of the major wholesales networks to use this data in an application that <strong>prevents food waste and increase revenue</strong>.</p><blockquote>We’ve built a ML model that predicts the number of items expected to be sold for products about to expire. Applied to a range of markdown values, the predictions help choosing the markdown value that maximizes the revenue while minimizing waste (the item is not sold and must be destroyed).</blockquote><p>The pilot project was a success and the application is now used by hundreds of employees in more than 100 stores.</p><p>For the rest of the article, I will describe <strong>what is required to use ML to solve a concrete business problem</strong>.</p><h4>What you will not find in this article and why?</h4><p>I will not try to deep-dive in any specific algorithm or Machine Learning techniques. Instead, I recommend <a href="https://towardsdatascience.com/">https://towardsdatascience.com</a> and <a href="https://kaggle.com/">https://kaggle.com</a> for such articles.</p><h4><strong>What is required to apply ML in a business problem?</strong></h4><p>First things first, the bill of materials. I’m not claiming this is the definite list as each project is particular, but it is a beginning.</p><ol><li>The data</li><li>Domain knowledge and the ability to analyze the data</li><li>Model Selection</li><li>Model Operationalization</li><li>A test plan and monitoring the solution</li><li>Buy-in from the stakeholders</li></ol><h4>Buy-in from the stakeholders</h4><p>I’ll start with the last item on the list as without this one the project is bound to become “<a href="https://en.wikipedia.org/wiki/Shelfware">shelf-ware</a>” or remain a PoC (Proof of Concept). The buy-in is conditioned by the ability of the development team to explain and to a certain extent, to demonstrate the way the solution works.</p><p>For an ML professional, the model metrics and the understanding of the math behind the technology are sufficient to “trust” the model. The person responsible for the financial results however needs more than just metrics. You need to be able to <strong>explain the model predictions and to simulate the model’s behavior</strong> in order to go live.</p><blockquote>Sometimes a weaker but a more explainable algorithm (Linear Regression, Decision Tree etc.) may be preferable to a stronger algorithm that is difficult to explain. The later category includes black-box type of models such as Neural Networks.</blockquote><p>We have documented the metrics (R2, RMSE etc.) and we’ve simulated the impact on the sales for each iteration of the model. In this way the non-technical stakeholders were able to understand and know what to expect.</p><h4>The Data</h4><p>This is the single most important ingredient of the solution. No algorithm, irrespective of how strong it is, is able to compensate lack of data or poor data quality.</p><p>ML algorithms give better results if more data is available, both in terms of number of records as well as number of properties. A richer set of data permits the data science team to formulate and test more hypothesis and solutions.</p><p>The <strong>data quality</strong> is as important as the <strong>data quantity </strong>but it’s a more difficult problem to solve. When data is not sufficient, we ca try to increase the speed with which the data is collected, we can try to identify new data sources or simply increase the duration of the data collection process. On the other hand, it’s difficult to “fix” data collected throughout the years by relatively rigid business processes.</p><p>In our case we’ve hit a problem with the data quality, as only three values of the markdowns made more than 90% of all the data. This means that we can reasonably expect the model to only learn and predict these three values, nullifying the whole effort. <strong>Garbage in, garbage out</strong> is quite applicable here as well. Without going into details, we’ve partially solved the issue by rounding and binning the prediction output which led to a broader set of recommendations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*BBjRNJBjiUMIOjAMjyYdLg.png" /><figcaption>Reduction % used for Best Before Date mardownds</figcaption></figure><h4>We have the data, now what?</h4><p>A good understanding of the domain, doubled by the skills necessary to analyze the data are also required. Annual and seasonal trends, “product cannibalization”, change in suppliers or supply chains, the company strategy are factors to consider when analyzing price recommendations.</p><blockquote>Great model metrics can hide predictions that are meaningless or not applicable due to legal or commercial reasons. This is why <strong>domain experts need to work with the development team </strong>and asses the model’s predictions.</blockquote><p>The “development team” includes the data scientists, data analysts, software developers, software designers, QA engineers etc.</p><h4>Model Selection</h4><p>Selecting the model to use is a cyclical process and it does not end even when the model is in production. We’ve used Jupyter Notebooks and ScikitLearn to explore the data, experiment creating models and selecting the most suitable one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*6JVllUP19m8b324pGDwmjA.png" /><figcaption>ML Cycle</figcaption></figure><h4>Pilot Stage</h4><p>The model used in this stage was a simple linear regression (OLS — Ordinary Least Squares). Despite OLS being one of the oldest and a relatively simpler algorithms, the results were excellent. The number of products destroyed decreased and the slightly lower markdown values helped increase revenues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*OnGFtknvjQ2zekYH5-1J1A.png" /><figcaption>Basic Model</figcaption></figure><h4>Production Stage</h4><p>In this stage we’ve extended the usage of the solution in over <strong>100 stores</strong>.</p><p>We’ve replaced the OLS model with a stacking model composed of a linear regression (still OLS) applied on top of a decision tree <strong>(GradientBoostingRegressor)</strong>. The tree model estimates the demand for the product which is combined by the OLS model with the markdown value to give the final prediction.</p><p>The stacking model is about 15% better than the OLS one while still being explainable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/1*aE5Z8yk7bPQ_PEwC0Z0L-Q.png" /><figcaption>Enhanced Model</figcaption></figure><p><em>For a good explanation of “stacked models” please see this </em><a href="https://towardsdatascience.com/stacking-machine-learning-models-for-multivariate-time-series-28a082f881"><em>article</em></a><em>.</em></p><h4>Model Operationalization</h4><p>I’ve started this paper with the number of models that end up being used in production. Using a model in production requires more than creating a model in Jupyter Notebooks. To use the model we’ve built an <a href="https://hazelcast.com/glossary/machine-learning-inference/">inference service</a> and integrated it in the existing application suite of our partner.</p><p>For implementation we had to choose between Go (or Java, Rust, Node.JS) and Python.</p><p><strong><em>Go</em></strong></p><ul><li><strong>(+)</strong> Optimized for networking tasks</li><li><strong>(+)</strong> Small footprint</li><li><strong>(-)</strong> Requires a separate process/container to load and use the model</li></ul><p><strong><em>Python</em></strong></p><ul><li><strong>(-)</strong> Fast, scalable networking tasks are not Python’s strong point</li><li><strong>(+)</strong> The model can be directly loaded and used in the service</li></ul><p>We’ve went for Python as we were able to compensate the somewhat reduced serving performance through the use of a WSGI service (Waitress/Gunicorn) and Flask. This gave us the ability to load and use the models in the service thus keeping the solution simpler and easier to maintain, with no real performance hit overall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*VOh0_7iyWT6fJH6GrWj-zg.png" /><figcaption>Inference Service Structure</figcaption></figure><p>The service logs and performance metrics are automatically collected and centralized with <a href="https://www.datadoghq.com/">DataDog</a> for an overall image of the service’s performance and the ability to easily investigate possible issues.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMgocjM6_iS_VDTnxyjcdw.png" /><figcaption>Response Times</figcaption></figure><p>The service serves roughly 300000 prediction requests weekly with a latency of under 50ms (P95). The number is not overwhelming but combined with the performance metrics it does validate the implementation choice. Furthermore, there is room to grow as the current usage accounts for 10% of the provisioned capacity in Google Cloud Platform: 2 pods, each having 1 CPU and 2Gb of RAM.</p><h4>Test plan and solution monitoring</h4><p>We have the model, the inference service is up and running, what’s next? Returning to the “acceptance” discussion we need to monitor and validate the business results. In other words, did we achieve the targets we set for ourselves?</p><p>To assess the model quality and determine if <strong>the changes are due to the model or just chance,</strong> we have implemented 2 distinct tests in the two stages of the project.</p><h4>Pilot Stage — A/B Testing</h4><p>We’ve split the stores in 2 groups comparable in terms of number of customers, sales values etc. The first group, the test group, use the model’s predictions to choose the markdown value. The second group, the control group, continue to set the markdowns manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*gftzJjlk2kUKhgv2LKjOpA.png" /><figcaption>Classic A/B Test</figcaption></figure><p><strong>Halfway through the test period we’ve switched the groups</strong>, the test group became the control group and vice versa.</p><blockquote>The first conclusion is that it’s difficult to meet the conditions to setup an A/B test.</blockquote><p>Here are some reasons for it:</p><ul><li>The 2 test halves are not comparable as they may contain special events (holidays, COVID restrictions etc.) and belong to different seasons which result in different buying patterns</li><li>Human factor — the manual markdowns are inconsistently applied across stores and periods</li><li>The stores are far from being identical</li></ul><blockquote>The second conclusion was that <strong>the solution is viable but we need a better way to measure it</strong>.</blockquote><h4>Production Stage — Block Design Testing</h4><p>With the lessons learned from the POC we’ve replaced the A/B Testing method with “<a href="https://en.wikipedia.org/wiki/Block_design">Block Design Testing</a>”. In this test method, for each store a number of products belong to the test group and other products belong to the control one. This way the store and time period no longer impact our ability to analyze the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*4mxEiQGtMLZ4ayOHbtuW0A.png" /><figcaption>Block Design Test</figcaption></figure><p><strong>Conclusion</strong></p><p>The ML technology can be applied to solve mundane tasks with good results. The process automation is a gain by itself as it removes the human error and allows for more creative usage of one’s time.</p><p>The decisive factor in the success of an ML project is the ability to explain the solution. It may sound strange but the algorithm used may be the least important factor to the solution’s success. <strong>Yes, neural networks are amazingly powerful but, in most cases, the humbler linear regression may be sufficient (and less expensive).</strong></p><blockquote><em>I’ll end with a recommendation: make an inventory of your data, review what you have and think what you could learn from them. This is the first and most important step for using Machine Learning and AI.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12673c02737a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why feature engineering matters]]></title>
            <link>https://dragoscojocari.medium.com/why-feature-engineering-matters-97ff607f66da?source=rss-b88d487d1e82------2</link>
            <guid isPermaLink="false">https://medium.com/p/97ff607f66da</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[training]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <category><![CDATA[training-courses]]></category>
            <dc:creator><![CDATA[Dragos Cojocari]]></dc:creator>
            <pubDate>Tue, 13 Jul 2021 09:46:07 GMT</pubDate>
            <atom:updated>2021-07-13T09:56:26.115Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>Three reasons why you should not overlook it</em></h4><p>When talking about Machine Learning many times we start with the algorithm: linear regression, decision trees and more often the rather spectacular neural networks. This is particularly visible when talking to people new to the domain.</p><p>The algorithms are certainly important but the discussion should usually start with the quality and the quantity of the data available to us. And while the answer to the <a href="https://www.quora.com/In-AI-is-data-more-important-than-algorithms">“<em>is data more important than the algorithm</em>”</a> is not a simple yes or no, the way data is prepared does have a large impact in the performance of the training process and the quality of the model produced by it.</p><p>In this article I want to <strong>briefly</strong> mention <strong>three reasons</strong> why feature engineering, the humbler step of the training flow, is a critical piece of the said flow and why it should be given as much attention as the algorithm itself.</p><p><strong>1. Feature Engineering allows you to use all the relevant features in your data</strong></p><p>This one is fairly simple but not always obvious. Most training algorithms require numerical values but not all data is numerical. If we take the famous Titanic dataset as an example, you will notice that the sex of the passengers is not usable in the training process while being one of the more important predictors. Performing <strong>categorical encoding</strong> on this feature allows us to use this feature in the training process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*5e7itrqbra3n1wKhC9jiEw.png" /></figure><p><strong>2. Feature Engineering can improve the speed of the training process</strong></p><p>A number of algorithms perform better in certain conditions. Gradient Descent algorithms that use regularization are such an example and you will find them used in linear regression implementations and in neural networks alike.</p><p>As a concrete example, in our <a href="https://www.datagridsoftware.com/training-courses/5-practical-machine-learning">Practical Machine Learning Course</a> we’ve recently showcased the impact of feature scaling: using <a href="https://archive.ics.uci.edu/ml/datasets/automobile">UCI’s Automobile Dataset</a> the training algorithm (we’ve used <a href="https://scikit-learn.org/stable/modules/linear_model.html#ridge-regression-and-classification">Ridge</a>) converged in <strong>846 iterations</strong> on the raw data while it only needed <strong>12 iterations</strong> after normalizing the data.</p><p>Consider that we were using a dataset with only 10 features. Now put this in the context of a more complex dataset and we could be talking hours versus days in training.</p><p><strong>3. Feature Engineering can help build better models</strong></p><p>Returning to the Titanic example, the accuracy of a logistic regression model trained on the data improved by 13% after being able to use the sex feature.</p><p>Another example where feature engineering can help is the <strong>removal of outliers</strong>. Outliers can have a huge impact on how a model is built, as show by the 3rd and 4th images in this rendering of the <a href="https://en.wikipedia.org/wiki/Anscombe%27s_quartet">Ascombe’s Quartet</a>. Removing them can significantly improve the model’s quality.</p><figure><img alt="Ascombe’s Quartet" src="https://cdn-images-1.medium.com/max/1024/0*kkNgHvkRZtASrmIc.png" /></figure><p>Last but no least, using clever feature generation techniques <strong>you can resolve problems faster and more cheaply with simpler algorithms</strong>. One such example is the famous <strong>XoR problem</strong>. I’ll leave you the pleasure to discover this problem and the clever solution to it. And no, it’s not by using a multi layer neural network.</p><p><strong>Conclusion</strong></p><p>I’m sure more examples can be added and I welcome you to post them in the comments. But the ones presented should show that going directly to the algorithm (even if a very strong one) is is not the best way to approach an ML problem and why feature engineering cannot be omitted.</p><p>If you need assistance getting started or taking your ML project to the next level we at <a href="https://datagridsoftware.com/">DataGrid Software</a> would be happy to assist you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97ff607f66da" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>