<?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 Camila Barbosa on Medium]]></title>
        <description><![CDATA[Stories by Camila Barbosa on Medium]]></description>
        <link>https://medium.com/@camilagomss?source=rss-22379a3109d1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*m_z_pGZfgiSVvSB_.jpg</url>
            <title>Stories by Camila Barbosa on Medium</title>
            <link>https://medium.com/@camilagomss?source=rss-22379a3109d1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 06:17:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@camilagomss/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[Classification Pipeline for Stock Management: a Competition approach]]></title>
            <link>https://medium.com/@camilagomss/classification-pipeline-for-stock-management-a-competition-approach-f2a1a639827e?source=rss-22379a3109d1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f2a1a639827e</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[classification-models]]></category>
            <category><![CDATA[xgboost]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Camila Barbosa]]></dc:creator>
            <pubDate>Tue, 24 Nov 2020 02:19:37 GMT</pubDate>
            <atom:updated>2020-11-24T02:25:34.626Z</atom:updated>
            <content:encoded><![CDATA[<h4>Deciding whether a vending machine needs restocking or not</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*MDO7L3rQgf3vAUIC1BA3hQ.png" /><figcaption>Automatic vending machine <a href="https://www.123rf.com/photo_141999779_moscow-russia-february-8-2020-red-bull-e-on-energy-drinks-in-metal-cans-in-a-transparent-glass-windo.html">https://www.123rf.com/photo_141999779_moscow-russia-february-8-2020-red-bull-e-on-energy-drinks-in-metal-cans-in-a-transparent-glass-windo.html</a></figcaption></figure><p>Throughout the year 2020, Latin American IBM hosted a coding marathon that included challenges using some of the most disruptive technologies in the market, such as cloud computing, machine learning, IoT, containers, Natural Language Processing (NLP), data science, among others.</p><p><a href="https://maratona.dev/pt">Home | Maratona Behind the Code</a></p><p>These challenges were based on real problems faced by the sponsors of the competition. The one <a href="https://medium.com/u/cc68e740d0e6">Lucas Solano</a> and I are going to talk about in this article consists of a challenge proposed by TNT, a brand of energetic drinks.</p><p>The problem they were facing consists of managing the stock of their vending machines in the subway stations of São Paulo. To overcome this problem, a classification pipeline was proposed in order to classify whether the vending machine needed to be restocked or not.</p><h4>The Data</h4><p>The data was gathered through an IoT gadget and it consisted of about 17k rows with the following features:</p><ul><li>ID</li><li>Time</li><li>Station</li><li>Latitude</li><li>Longitude</li><li>Movement</li><li>8 kinds of flavors</li></ul><p>The target has only two possible values: <em>normal</em> or <em>restock</em>.</p><p>The picture below exemplifies the structure of the data we collected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5dhGVvKzNP1R9q1mq_TtUg.png" /><figcaption>A small visualization of the dataframe</figcaption></figure><h4>Feature Engineering</h4><p>After understanding the dataset, we cleaned, prepared, and manipulated the data. First of all, we made sure that there were no duplicates in the dataset — what was possible, given that the data was acquired via IoT gadgets. After that, we also made sure that through the data there were no null values.</p><p>Then, two features were created with both the mean and the median of the number of cans from each flavor. From the date and time of each row, we also extracted the feature <em>day of the week</em>.</p><p>For the categorical feature, the <em>subway stations, </em>we converted each subway station into a new column and assigned a or 0 (True/False) value to the column. This has the benefit of not scaling a value improperly and it’s called one-hot encoding. We implemented using one of the simplest ones, with pandas and the method <em>get_dummies().</em></p><h4>Balancing Data</h4><p>Since the dataset was not balanced in terms of the target values, we choose the approach known as SMOTE. In a few words, it works by creating new data based on the existing dataset.</p><p>The difficulty of working with imbalanced datasets consists in the fact that most machine learning techniques will have poor performance on the minority class, although typically it is the performance on the minority class that is most important.</p><p><a href="https://machinelearningmastery.com/smote-oversampling-for-imbalanced-classification/">SMOTE for Imbalanced Classification with Python - Machine Learning Mastery</a></p><p>In our case, the minority class was the target <em>restock</em>. On our data, we had a lot more examples from the <em>normal</em> label of the target feature than from the <em>restock, </em>the most important piece of information we aim to extract from this analysis.</p><h4>Feature Selection</h4><p>Finished the data treatment we go on with the pipeline into the feature selection. We already cleaned the dataset, created more features, and handled categorical data, now we’re going to use a feature selection technique in order to determine with which features our model will perform better.</p><p>The method used was the Recursive Feature Elimination (RFE). The following description explains briefly how the algorithm works, the link to the documentation is also below.</p><blockquote>Recursive feature elimination (RFE) is a feature selection method that fits a model and removes the weakest feature (or features) until the specified number of features is reached. Features are ranked by the model’s coef_ or feature_importances_ attributes, and by recursively eliminating a small number of features per loop, RFE attempts to eliminate dependencies and collinearity that may exist in the model.</blockquote><p><a href="https://www.scikit-yb.org/en/latest/api/model_selection/rfecv.html">Recursive Feature Elimination - Yellowbrick v1.2 documentation</a></p><p>After running the feature selector with an XGBClassifier, the features with the best outcomes were:</p><ul><li>all the flavors</li><li>weekday</li><li>and the subway stations</li></ul><h4>AutoML</h4><p>Automated Machine Learning (AutoML) refers to techniques for automatically discovering well-performing models. It consists of trying several classifiers in order to select the best one — given a specific metric. In this scenario, we choose to use the TPOT Classifier.</p><p>TPOT is an open-source library for performing AutoML in Python. It makes use of the popular Scikit-Learn machine learning library for data transforms and machine learning algorithms. It works based on a stochastic search algorithm to efficiently discover a top-performing model pipeline for a given dataset.</p><p><a href="https://machinelearningmastery.com/tpot-for-automated-machine-learning-in-python/">TPOT for Automated Machine Learning in Python - Machine Learning Mastery</a></p><p>The low-point of most AutoML algorithms is that the more variables and the more scenarios you want to test, the longer it will take to run. There’s a great computational cost involved. So, given the limited time, we ran our TPOT with only 10 generations.</p><p>The result was, with not that much surprise, the XGBoostClassifier, one of the most applied techniques in the machine learning competition world. The complete output from the TPOT method is the following:</p><pre>XGBClassifier(learning_rate=0.001, max_depth=9, min_child_weight=9, n_estimators=100, nthread=1, subsample=0.4)</pre><h4>Model Evaluation</h4><p>The dataset was split in an 80/20 proportion for train/test purposes. And we obtained the following outcomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*nKHlebgta0Hh9ZkeCNV4sg.png" /><figcaption>Metrics from the model ran</figcaption></figure><p>The confusion matrix is also available below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*Dau_KIrPacF7YqltBlWfGw.png" /><figcaption>Confusion matrix from the model ran</figcaption></figure><p>As we can see in the situation that matters the most for the business (the <em>restock </em>option), the model was able to successfully predict the entire test set correctly. And, for the operation, even when the model as wrong, it was not harmful to the system, since restocking a vending machine that does not need restocking at the moment is not as bad as not refilling one that does need.</p><h4>Conclusion and some remarks</h4><p>With this machine learning application, we not only practiced an entire classification pipeline but also solved a real-world problem that could be easily implemented by the sponsor company to optimize their operation: restocking their vending machines in São Paulo’s subway stations.</p><p>Besides that, we could see that the performance obtained with this pipeline was satisfactory, since in the Behind the Code Marathon we both were in the Top 100 Brazil submissions. The competition had more than 70k participants.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*IOHNH1o8A8T-fqujoX_ZAg.png" /><figcaption>Printscreen of the ranking for the challenge</figcaption></figure><p>The code exemplified in this article is available at <a href="https://github.com/camilabga/tnt-challenge/">https://github.com/camilabga/tnt-challenge/</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2a1a639827e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>