<?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 Matheus Pessoa on Medium]]></title>
        <description><![CDATA[Stories by Matheus Pessoa on Medium]]></description>
        <link>https://medium.com/@matheuspessoa16?source=rss-116366a31db1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*ZMMVxaV78-yAd6q47sKXOg.jpeg</url>
            <title>Stories by Matheus Pessoa on Medium</title>
            <link>https://medium.com/@matheuspessoa16?source=rss-116366a31db1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 17:27:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@matheuspessoa16/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[Heroku e Travis-CI: deploy de uma aplicação Java com CI/CD]]></title>
            <link>https://matheuspessoa16.medium.com/heroku-e-travis-ci-deploy-de-uma-aplica%C3%A7%C3%A3o-java-com-ci-cd-8e0b8d0a4153?source=rss-116366a31db1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e0b8d0a4153</guid>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[travis-ci]]></category>
            <dc:creator><![CDATA[Matheus Pessoa]]></dc:creator>
            <pubDate>Sat, 26 Dec 2020 23:46:12 GMT</pubDate>
            <atom:updated>2020-12-28T17:08:05.114Z</atom:updated>
            <content:encoded><![CDATA[<p>Um assunto que muito me interessa e que tenho estudado recentemente é o processo de desenvolvimento dirigido por testes (<em>Test Driven Development </em>ou<em> </em>TDD) e sua combinação com integração e entrega contínuas (<em>Continuous Integration</em>/<em>Continuous Delivery</em>).</p><p>Apesar de ainda não praticar TDD no meu dia a dia como programador, estou empenhado no processo de aprender e colocá-lo em prática. Meu primeiro passo então foi comprar um curso na Udemy sobre o tópico e começar a praticar. Sou desenvolvedor Java há algum tempo, mas só recentemente comecei a trabalhar profissionalmente com a linguagem. Assim, aprendi (e estou aprendendo) a dureza de não ter testes no projeto e de não ter processos de integração contínua (quem nunca corrigiu um <em>bug</em> e subiu dois outros?).</p><p>O curso ensina como testar utilizando a JUnit 5, Mockito e o Spring uma API Rest construída usando o processo de TDD e BDD. Os conceitos apresentados de testes unitários e de integração foram bem rápidos e já partiu para a prática de codificação. O curso cobre outros tópicos muito interessantes utilizando Spring e uma certa dose de DevOps (monitoramento, o próprio <em>pipeline</em> de CI/CD). Eu já tinha noção dos conceitos básicos, mas foi muito bom rever os conceitos envolvidos no TDD.</p><p>O último módulo do curso foi colocar a API em produção no <a href="http://www.heroku.com/">Heroku</a> integrando com o <a href="https://travis-ci.com/">Travis-CI</a>. As configurações do Travis para realizar a integração contínua no repositório são fáceis de seguir. Basta escolher logar com o Github, escolher o repositório que será integrado e aceitar os termos.</p><p>Após isso, é necessário criar um arquivo de configurações do Travis chamado .travis.yml. Nesse arquivo estarão os comandos necessários para dar <em>deploy</em> e usar o Java na versão do código. Meu arquivo de configurações ficou da seguinte forma</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/1*x6Nd01AFziJXVtfVt_Uj6A.png" /><figcaption>Arquivo de configuração do Travis</figcaption></figure><p>No início do arquivo declaramos qual linguagem será utilizada e a versão da jdk. Atenção para os espaçamentos, pois a indentação importa nesse tipo de arquivo. O parâmetro dist: trusty indica em qual versão do Ubuntu será executada a virtualização no Travis (Ubuntu Trusty 14.04). Por fim, é necessário dar permissão de execução ao Maven na máquina virtual através do comando chmod +x mvnw antes do processo de integração começar, por isso, usamos o before_install. As configurações de <em>deploy</em> serão explicadas mais abaixo.</p><p>Após configurar o .yml, é necessário dar um <em>push</em> disso para o repositório para o processo de build ser iniciado no Travis. No Travis é possível acompanhar o status e os <em>logs</em> de execução. O meu fica da seguinte forma</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kW0oWJabWSeTlUUaL_kz8g.png" /><figcaption>Meus repositórios e builds no Travis.</figcaption></figure><p>Após finalizar a integração com o Travis e verificar a execução dos testes sempre que um <em>push</em> é feito para a <em>branch</em> <em>master</em>, o passo seguinte foi realizar o <em>deploy</em> da aplicação no Heroku. Como no meu dia a dia costumo fazer o <em>deploy</em> do resultado do <em>build, </em>seja ele um .war ou um .jar, procurei tornar o processo o mais próximo possível do que já faço, facilitando a utilização dos conceitos aprendidos. Para executar o .jar, criei uma aplicação no Heroku chamada library-loan-api. Um repositório é iniciado automaticamente com o nome da aplicação e é nesse repositório que ficará a aplicação que será colocada no ar.</p><p>Para conectar seu repositório local com o repositório remoto, basta fazer</p><pre>heroku git:remote -a &lt;nome_do_app_heroku&gt; </pre><p>usando a ferramenta de linha de comando heroku-cli. Após isso, já é possível dar um <em>push </em>para heroku master. Com essas partes configuradas, já é possível escrever o trecho de <em>deploy </em>no arquivo .travis.yml. Primeiro precisamos instalar a travis-cli, outro utilitário de linha de comando. Após a instalação é preciso conectar com sua conta do Github para a ferramenta ter acesso ao repositório e fazer os processos necessários. Para conectar fazemos</p><pre>travis login --pro --github-token=&lt;token_pessoal_github&gt;</pre><p>É possível logar com as credenciais do Github, porém, não consegui fazer isso e preferi usar a chave de acesso. Para criar uma, abra o Github, clique em <em>settings</em> (clique na imagem da sua conta no header da página), depois em <em>Developer Settings </em>e clique em <em>Personal acess token. </em>Clique no botão <em>Generate new token</em> e configure as permissões de acesso (permissões de leitura em para repositórios públicos, usuário e <em>workflow</em> devem ser suficientes para garantir o acesso do Travis).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*yv9_B-OnviaXRaYIcCBOAg.png" /></figure><p>Após fazer o login na aplicação, podemos usar o comando de <em>encrypt</em> para criptografar a chave de acesso ao Heroku, necessária para o Travis fazer o <em>deploy</em>. Essa chave fica em <em>Account Settings</em> na seção <em>API Key. </em>No terminal, acessamos o diretório do projeto para gerar a chave criptografada. Para isso, usamos o comando</p><pre>travis encrypt &lt;chave_do_heroku&gt; --add deploy.api_key --pro</pre><p>O comando acima irá gerar a linha que contém a API-Key criptografada no arquivo .yml. O arquivo .travi.yml agora pode ser finalizado para o processo de deploy. Adicionei algumas coisas na configuração do meu <em>deploy</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*iEJYNYLIi7f-2z19kKTpEA.png" /><figcaption>Configurações do deploy</figcaption></figure><p>Além da api_key adicionada com o comando do Travis, é preciso colocar o <em>provider</em> que é para onde fazemos o <em>deploy. </em>Nesse caso usamos o Heroku, mas poderia ser configurado para Azure, AWS entreoutros. Coloquei também o nome da aplicação no parâmetro <em>app. </em>O parâmetro <em>edge </em>especifica a última versão da ferramenta de <em>deploy</em> para o <em>provider</em> escolhido. Por fim, especifiquei qual a <em>branch</em> do repositório seria colocada em produção. Nesse ponto é possível configurar <em>deploys </em>para múltiplos ambientes baseado na <em>branch</em> especificada.</p><p>Após essas configurações, basta dar um <em>push</em> do arquivo.travis.yml e esperar o <em>pipeline</em> de integração do Travis finalizar para checar se o <em>deploy</em> foi feito corretamente no Heroku.</p><p>Era isso que eu tinha para compatilhar hoje. Gostei bastante do curso e achei muito interessante mudar um pouco o processo para ganhar mais domínio sobre o processo de automação de teste, integração e entrega contínuas.</p><p>Espero que seja útil para todos que lerem esse post. Quem sabe eu dê continuidade com o monitoramento da aplicação usando ELK Stack (também quero testar isso).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e0b8d0a4153" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Understand Your Machine Learning Model]]></title>
            <link>https://medium.com/analytics-vidhya/how-to-understand-your-machine-learning-model-d4606c40a774?source=rss-116366a31db1------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4606c40a774</guid>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Matheus Pessoa]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 02:38:05 GMT</pubDate>
            <atom:updated>2019-10-20T14:42:24.917Z</atom:updated>
            <content:encoded><![CDATA[<h4>What should I use to understand the features and their importance to my model?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FfSKyDWJTQIF6dtx" /><figcaption>Photo by <a href="https://unsplash.com/@codestorm?utm_source=medium&amp;utm_medium=referral">Safar Safarov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Machine Learning models are complex things to understand and evaluate. The features originated from the dataset and used to train the models are crucial to their performance.</p><p>Given the importance that these models have upon the decision making, it’s important to understand how each feature affects the model prediction. To do so, we are going to use some techniques as classical feature importance (just white box ML algorithms) and partial dependence.</p><p>In this article, we are going to use the famous lib <a href="https://scikit-learn.org/stable/">scikit-learn</a> and some techniques like RandomForest and DecisionTree to predict and evaluate the results from dataset. The data is the <a href="https://archive.ics.uci.edu/ml/datasets/census+income">census income</a> from UCI repository.</p><p>First things first. Let’s build a model and use some aspects to analyze the data.</p><h3>Building the model</h3><p>In this article, I going to reuse some codes from the notebook made by my professor. The code can be found <a href="https://github.com/ivanovitchm/EEC1509_Machine_Learning_2019_2/blob/master/Lesson%2308/Lesson_08_Ensemble_Learning_I.ipynb">here</a>. So, the first part is to build a model and tune it. We will search for the right algorithm among three options Decision Tree, Random Forest or Bagging Classifier. All these options can be found on the scikit-learn lib.</p><p>Before I show the code, it’s important to explain what is a bagging classifier. Bagging is a technique that subsample randomly a dataset with replacement. We create many subsets that can have repeated data (because of the replacement) and use these to train different predictors. With bagging, the most common estimator used with bagging is Decision Tree. This estimator is easily overfitted when used separately. You may ask “But if the decision tree is easily overfitted, what guarantees that will we obtain the right answer on a different dataset?”. Well, it’s exactly what the bagging does. Overfit means that the model has a high variance (it can’t predict well on a new data) and a low bias (the predictor is quite sure that its answer for the training data is right).</p><p>When we aggregate the predictions across statistical mode, we are creating a smoothed curve on the variance. Using the most frequent prediction, we try to guarantee that models that know the data predict it right. The others have a high variance when the data is new and will be wrong.</p><p>Bagging is a really clever technique to avoid overfitting. A paper that explains it better can be found <a href="https://arxiv.org/pdf/1905.12787.pdf">here</a>. Now, we can see the code to select the best model. I’m showing just a part of the code. The complete code can be found on the repository of my professor on <a href="https://github.com/ivanovitchm/EEC1509_Machine_Learning_2019_2/tree/master/Lesson%2308">GitHub</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65f3b84795f65465cf3ec7de83176df6/href">https://medium.com/media/65f3b84795f65465cf3ec7de83176df6/href</a></iframe><p>It took almost 40 minutes to search for the best model on Google Colab. After this process, the result is presented in the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*ZLfCVu-bORsCBaDggqH3hA.png" /><figcaption>Best model and params</figcaption></figure><p>The BaggingClassifier was the best model found. I forced the bootstrap with replacement in the configuration. This first part is just to show what bagging is and how it can improve classification and avoid overfit. In the second part of the article, we will build a model that uses bagging and evaluate the results of the training.</p><h3>Feature Importance</h3><p>One of the important things about machine learning is feature selection. The understanding of which features are relevant and how each of them impacts the model decision helps to reduce the complexity of the model through feature reduction, avoid biased models and helps to interpret better the results to increase confidence in the model predictions.</p><p>We going to compare here the classical feature importance from the ensemble algorithms provided by the scikit-learn with partial dependence, local interpretation and SHAP values. The classifier used here is the Random Forest. We choose it because the random forest is an algorithm that allows bagging and with its own feature importance evaluation.</p><p>First, let’s build the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7808c9b649dd0026e6732e4c04acab1c/href">https://medium.com/media/7808c9b649dd0026e6732e4c04acab1c/href</a></iframe><p>I reused the pipeline created before to convert the data to the right format. In the “train_test_split” the result is keeping the proportion of the classes on the dataset across the param stratify. The predictor is a RandomForest optimized with GridSearchCV. I choose this model instead the Bagging showed on the first part because RandomForest has a property that lets you get the features importance.</p><p>After train the model, let’s evaluate using the oob_score and the test data and compare if both results are similar.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ca47214ba3d81fe9ee92e1e277c1903/href">https://medium.com/media/8ca47214ba3d81fe9ee92e1e277c1903/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*3hrRG57ZuzOubBnn5FxF_g.png" /><figcaption>Evaluation of the model</figcaption></figure><p>In the image above, we can see the complete evaluation of our model. The first line it’s the validation with the out-of-bag values (the values that weren’t chosen when the dataset was subsampled). The second output is the accuracy of the model with the test set. As expected, the oob_validation is close to the test evaluation, which makes oob a good choice to validation.</p><p>With the model ready, we can start to analyze the importance of the features. First, let’s see what the scikit-learn give us with the standard analysis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87f50367f9f9392bb26dab1bc3370cf3/href">https://medium.com/media/87f50367f9f9392bb26dab1bc3370cf3/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*5XSRZIHKBSJPI3H8GEx2DQ.png" /><figcaption>Feature importance</figcaption></figure><p>The graph above shows the importance of all the nine features used by the model. The four most important are “marital_status”, “capital_loss”, “capital_gain” and “workclass”. The method used to calculate these importances is the average gain of the feature when it is used in trees.</p><p>Let’s compare the default result with <a href="https://eli5.readthedocs.io/en/latest/index.html">ELI5</a> evaluation. To do that, we just need to call the function “show_weights” with the classifier and columns name as parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a988fbccbbffc86174dece471d5aae28/href">https://medium.com/media/a988fbccbbffc86174dece471d5aae28/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/252/1*gTYBg2l1YRXxryZVSntkcg.png" /><figcaption>Features weights</figcaption></figure><p>The result obtained with ELI5 and showed above is the same as the default gave by scikit. It means (and the documentation confirms) that ELI5 uses the “gain” as default parameter to compute the importance.</p><p>Another excellent thing about ELI5 is that we can evaluate the feature weight in the decision. Bellow, I show the weight of each feature in the value predicted by the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e699fa96a2c7afd23a8ead562c79749d/href">https://medium.com/media/e699fa96a2c7afd23a8ead562c79749d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/305/1*SrLMG3Q-bj2iCwdpq-pnyQ.png" /><figcaption>Explanation of prediction</figcaption></figure><p>ELI5 is a great framework to evaluate models and understand the importance of the features, but it’s limited to linear models and tree-based models. Another limit is that ELI5 doesn’t partial dependence analysis. So, to overcome that, let’s use the <a href="https://oracle.github.io/Skater/overview.html">Skater</a> framework.</p><p>Skater is a model agnostic framework that offers a great set of tools to analyze feature importances of black-box models. Here, we will explore the partial dependence plot of our most important features.</p><p>First, let’s plot the rank of the features.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9856d0ca05e5307550335480dee9331c/href">https://medium.com/media/9856d0ca05e5307550335480dee9331c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*RKOxfgbo0-vCbeeXtXgLiQ.png" /><figcaption>The rank of the features</figcaption></figure><p>The plot is similar to what ELI5 computed too. The most important features are the same. Now, we can plot the partial dependence of some features and understand the behavior. Partial dependence is a technique that allows understanding the impact of a feature on model prediction, keeping the other values constant. It can show if the relationship between the target and the feature is linear, monotonic or more complex.</p><p>The most important feature is the “marital_status”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4cf58e317232f034e9618a13ebbb3b1/href">https://medium.com/media/c4cf58e317232f034e9618a13ebbb3b1/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*h9YdR4KNMnO4CQbHI_A_uw.png" /><figcaption>Marital status partial plot</figcaption></figure><p>In the figure above, the most frequent status of income greater than $50K are divorced (0) and separated (5), accordingly to the model.</p><p>The second most important feature is capital gain. In the figure below is the graph presents the normalized gains on the X-axis. Values greater than $7k presents more chances to have a high income.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df8a21d6e3070e25f03cbf1f020c20e2/href">https://medium.com/media/df8a21d6e3070e25f03cbf1f020c20e2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*2zJCufEh_5a6w6tJTdLGNA.png" /><figcaption>Capital gains partial plot</figcaption></figure><p>The last partial plot shows the “workclass” importance. It seems like that who works to the government, federal employee (1) and local government employee (2), have more probability of a high income.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71eb49764ed898e0c6c551f8199566f2/href">https://medium.com/media/71eb49764ed898e0c6c551f8199566f2/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/408/1*vOaw_0SXtcPbrQWLKWvoFw.png" /><figcaption>Workclass importance</figcaption></figure><h3>Conclusion</h3><p>This article is part of the evaluation of the machine learning class and here I tried to cover the basic parts about techniques to avoid overfit and how to analyze a model and understand the features of the dataset and how each of them impacts the predictions of the model. I’m opened to comments and critics about what I should do to make better.</p><p>Thanks.</p><h3>References</h3><ul><li><a href="https://towardsdatascience.com/explainable-artificial-intelligence-part-3-hands-on-machine-learning-model-interpretation-e8ebe5afc608">Hands-on Machine Learning Model Interpretation</a></li><li><a href="https://becominghuman.ai/machine-learning-bias-vs-variance-641f924e6c57">Machine Learning: Bias VS. Variance</a></li><li><a href="https://www.quora.com/What-does-Bagging-reduces-the-variance-while-retaining-the-bias-mean">What does &quot;Bagging reduces the variance while retaining the bias&quot; mean?</a></li><li><a href="https://towardsdatascience.com/explaining-feature-importance-by-example-of-a-random-forest-d9166011959e">Explaining Feature Importance by example of a Random Forest</a></li><li><a href="https://github.com/ivanovitchm/EEC1509_Machine_Learning_2019_2/tree/master/Lesson%2308">ivanovitchm/EEC1509_Machine_Learning_2019_2</a></li><li><a href="https://github.com/matheus-pessoa16/MachineLearning">matheus-pessoa16/MachineLearning</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4606c40a774" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/how-to-understand-your-machine-learning-model-d4606c40a774">How to Understand Your Machine Learning Model</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>