<?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 anitakivindyo on Medium]]></title>
        <description><![CDATA[Stories by anitakivindyo on Medium]]></description>
        <link>https://medium.com/@anitakivindyo?source=rss-2aa6c4b77317------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*L1fr7YrnkVHHngTJWkNfvA.jpeg</url>
            <title>Stories by anitakivindyo on Medium</title>
            <link>https://medium.com/@anitakivindyo?source=rss-2aa6c4b77317------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 17:07:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anitakivindyo/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[The F1-Score Unveiled : Part 1]]></title>
            <link>https://medium.com/@anitakivindyo/the-f1-score-unveiled-part-1-47861c6748c7?source=rss-2aa6c4b77317------2</link>
            <guid isPermaLink="false">https://medium.com/p/47861c6748c7</guid>
            <category><![CDATA[f1-score]]></category>
            <category><![CDATA[model-evaluation]]></category>
            <category><![CDATA[precision]]></category>
            <category><![CDATA[recall]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[anitakivindyo]]></dc:creator>
            <pubDate>Mon, 04 Mar 2024 07:01:02 GMT</pubDate>
            <atom:updated>2024-03-04T07:01:02.452Z</atom:updated>
            <content:encoded><![CDATA[<h3>The F1-Score Unveiled : Part 1</h3><p>In the machine learning realm, evaluating models is as crucial as training them. This involves assessing various statistical metrics like accuracy, recall, precision, and the F1-score to gauge the model’s predictive quality.</p><p>This article zeroes in on the F1-score, a pivotal metric for evaluating classification models. We will delve into what the f1-score is used to measure, what classification problems are, what other metrics make the f1-score, and why the said metrics are a good fit in measuring the f1-score while also highlighting some of their challenges and limitations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZ-DEYTXlJbPyEfVdGS2QQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@thisisengineering?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">ThisisEngineering RAEng</a> on <a href="https://unsplash.com/photos/woman-in-black-long-sleeve-shirt-GzDrm7SYQ0g?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Model evaluation helps us understand how well your model is performing on new/unseen data. It is a very crucial step in the machine learning process. Check <a href="https://medium.com/@anitakivindyo/an-introduction-to-machine-learning-164bf4963794?source=friends_link&amp;sk=40448f846ef5fc6b6f3b0d7e16a880e2">An Intro to ML</a> -where I have highlighted all the key ML steps.</p><p>Consider a Supervised model, there are typically two common phases of model evaluation:</p><ol><li><strong>The Training Phase</strong>: here, the model is trained on a labeled dataset, also known as the training data. During training, adjustments are made to the model’s parameters to minimize <strong>training loss</strong>. However, it’s important to note that in this phase, we can only assess <em>how well the model fits the training data</em>, but we can’t predict how it will perform on new, unseen data.</li><li><strong>The Evaluation Phase</strong>: After the model is trained, it undergoes evaluation on a separate dataset, often referred to as the <strong>validation data</strong>. Ideally, the model is also tested on a completely different dataset known as the <strong>test data</strong>, which it has not ‘seen’ during the training process. This evaluation phase is focused on understanding how good or bad the model generalizes to new data.</li></ol><p>These two phases can be iterative, with adjustments made as needed until desired results are archived.</p><p>Now we can see why model evaluation is a particularly important step, since this is where we answer the questions:</p><ol><li>How good is the model?</li><li>How well does it compare to others?</li></ol><p>To do this, we need a GOOD evaluation Metric.</p><h4><strong>Classification Problems — (Supervised Learning)</strong></h4><p>Classification problems are common in the ML realm and in Supervised learning, their output is generally grouped into either positives or negatives.</p><p><strong><em>positives</em></strong><em> — the class/category of interest</em></p><p><strong><em>negatives</em></strong><em> — not the class we are looking for.</em></p><ol><li><strong>Binary Classification</strong></li></ol><p>Consider a simple binary classification problem where we only have two options, i.e., male or female, spam email or not spam email, fraud or not fraud, cancer cells or no cancer cells…etc. These cases the outputs are simply either positive or negative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/211/1*hGkPnVlhyuEaVcsQu_gCuw.png" /></figure><p><strong>2. Multi- Class Classification</strong></p><p>Consider a classification problem with more than two classes, for example, classifying animals into different species</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/451/1*dWOfwHvHiCOGMv_MUiSSTg.png" /></figure><p>Where we have to correctly categorize each input into the correct class.</p><p>And there are different algorithms to solve this problem, depending on the size of the dataset, nature of the dataset, computation resources etc.</p><p>Generally, there are some algorithms that inherently support multiple classes, like Logistic regression, Random Forest, Support Vector Machines (SVMs), K-Nearest neighbor (KNN), Naive Bayes, Gradient Boosting algorithms (e.g., XGBoost, LightGBM).</p><p>And some algorithms that transform binary classifiers into multi-class classifiers using some strategies like One-vs-All (OvA) or One-vs-One (OvO).</p><p>We then move to the model evaluation step.</p><h3><strong>Deriving the F1 score: part 1</strong></h3><p>The F1-score is a metric commonly used to evaluate the performance of a classification model, by <strong>combining the harmonic mean of precision and recall into a single metric.</strong></p><p>Hmmm…. What is <em>precision</em>? What is <em>recall</em>? What is a <em>confusion matrix</em>? and why not just use <em>Accuracy</em>? Why the <em>harmonic mean</em>? You may ask.</p><p>Let me try to break down these concepts with an example.</p><p>Say, we train a model to solve a binary classification problem where it should predict whether an image is a giraffe(positive) or not giraffe (negative).</p><p>And this is how it performs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*Viuzy5QloCyWmKfqrF-uRg.png" /><figcaption>model performance</figcaption></figure><p>We can see the model made some predictions and some are correct, and others aren’t.</p><p>Let’s take the predicted values as our base and observe what the model predicted as <strong>Giraffes (the positives)</strong> — all the <strong>6</strong> predictions.</p><p>How many of the 6 Giraffe predictions did the model predict correctly?<strong> 4. </strong>This value is called <strong>True Positive </strong>— remember<em> Positive</em> in this context refers to the class we want, and <em>True </em>references the ‘true value’.</p><p>Then, how many of the 6 Giraffe predictions did the model predict wrongly? <strong>2. </strong>This value is called <strong>False Positive </strong>— where <em>False</em> refers to the ‘true value’ which in this case is a wrong output, and <em>Positive </em>because it is the outcome of the class, we want which is Giraffes.</p><p>Now, still looking at the predicted values, let’s observe the other class which in our case, the model predicted as <strong>Not Giraffe (the negatives)</strong>. There are <strong>4</strong> predictions in total.</p><p>Using the same analogy, we first compare the predictions, which in this case are the negatives, to ‘true values.</p><p>We then have <strong>2 True Negatives — </strong>(2 correct outputs for the Negative class)<strong> </strong>and <strong>2 False Negatives — </strong>(2 wrong outputs for the Negative class)</p><h4><strong>Confusion Matrix</strong></h4><p>Now that we understand what True Positives (<strong>TP</strong>), False Positive (<strong>FP</strong>), True Negatives (<strong>TN</strong>) and False Negatives (<strong>FN</strong>) are, we can go ahead and look at the confusion matrix, since these values are what make up the <strong>Confusion Matrix</strong> as illustrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*PoCwxCgZtQhc6MQO1AjN8g.png" /></figure><p>These values in the confusion matrix are what we use to calculate <strong>recall</strong>, and <strong>precision</strong>… we will get into the ‘how’ in a minute.</p><p>Let’s first observe how many predictions our model got right? <strong>6</strong></p><p>That is called <strong>Accuracy — </strong>how many predictions were right (true), both negatives and positives.</p><p>In our case we got <strong>6/10</strong> hence our Accuracy is <strong>0.6</strong></p><h4><strong>Accuracy</strong></h4><p>The formulaic definition of accuracy is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*5vdrOvWCllms9hSL5vltnQ.png" /></figure><p>Accuracy is a metric used when the goal is to <strong>make as few mistakes</strong> as possible.</p><p>However, accuracy has its limitations, and this becomes very apparent when dealing with bias datasets.</p><p><em>Imagine we have a dataset with 1% positive labels and 99% negative labels. The model will be biased to output only the negative predictions correctly and almost zero guesses of the positive labels. This model will still have archived 99% accuracy. Yikes!</em></p><p>This can be fatal if we use accuracy to evaluate a sensitive case like disease prediction, or system fault detection where in the datasets you find that the normal labels usually outnumber the abnormal labels, therefore accuracy doesn’t correctly measure how good the model performs in predicting the abnormal labels(which is the lesser class).</p><p>This is where a metric like Precision comes in.</p><h4><strong>Precision</strong></h4><blockquote>“When thinking of precision, think of the predicted values as our baseline.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qaNZtdg8nSGIfKLmw0mOOQ.png" /></figure><p>Let’s again observe the Predicted values from our model…</p><p>How many times did the model guess Giraffe(positive) correctly? <strong><em>4 times out of the 6 guesses </em>— 4/6 = 0.66</strong></p><p>This value is what we refer to as <strong>Precision</strong>, it is <strong>how well you guess the positive labels in question </strong>and below is the formular. (key word-positive)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*RCRpGSFfnLBEh2WHvH557w.png" /></figure><p>It solves the issue of accuracy, which is also known as<strong> cheating.</strong></p><p><em>Let’s take our previous case example: We need to find the number of people infected with a disease and 99% of the dataset is healthy and 1% infected. If the model guesses 99% of people as healthy, which in our case is the negative label (not what we are looking for). The precision score will almost be = 0.0 because the model will make almost 0 positive guesses. Precision penalizes the model for not guessing the positives. Yaaay?</em></p><p>Not quite…</p><p>Precision cannot paint the full picture, as it <strong>does not observe the negatives.</strong></p><p><em>Let’s take our case example: We need to find the number of people infected with disease and 99% of the dataset is healthy and 1% is infected. If our model happens to make </em><strong><em>only 1 correct positive </em></strong><em>guess and </em><strong><em>99 wrong negative guesses</em></strong><em>, the model will have a score of 100% precision. But it failed to identify the negatives correctly. Yikes!</em></p><p>This is where a metric like Recall comes in.</p><h4><strong>Recall</strong></h4><p>Recall is like a counterpart to precision, and it is different as it takes the negative labels into question.</p><blockquote>“When thinking about recall, always think of the True Values as your baseline.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3VntWmx_i4vt_hYyR2-qLQ.png" /></figure><p>Let’s go back to our model and observe the True Values.</p><p>How many <strong>True</strong> Giraffe values are there? <strong>6</strong></p><p>And how many guesses did our model get right on Giraffe(positives)class?<strong> 4</strong></p><p>So, Recall is, <strong>out of all the Positive True Values how many did we get right. </strong>And this is the formular.</p><p>So, for our model, Recall will be<strong> 4/6= 0.66</strong></p><p>We use recall when the goal is to find the <strong>greatest number of positive labels/ positive true values</strong>… How well were the positive true values recalled?</p><p>Therefore, Recall solves the issue of precision cheating.</p><p><em>Back to our case example: If our model makes 1 correct guess as positive, and all other guesses as false negatives. Recall will penalize the model by giving it a score of 0.00. Yaay??</em></p><p>Not quite… as recall alone has a problem, let’s look at an example:</p><p><em>In an extreme case where the dataset is highly skewed and all labels are labeled positives(i.e. all instances are of the positive class) , the model will predict everything as positive, therefore resulting in no false negative, resulting in a perfect recall score of 100%….but in hindsight no negatives were really observed. And precision would be 0% as it would penalize the model for the many false positives. Yikes!</em></p><p>So now we have these two metrics, sort of doing a dance with each other and balancing out the other.</p><p>Precision and Recall complement each other <strong>as can prevent cheating of the other score</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*pf7dFj9rFl8ppwb-V_Uqdw.png" /></figure><p>In Summary</p><ul><li>Precision measures the ‘accuracy’ of the <strong>positive predictions</strong> made by the model</li><li>Recall measures the model’s ability to <strong>find all the positive</strong> instances.</li></ul><p>Since we need one to penalize the other, can precision and recall be calculated at the same time?</p><p>Yes!!</p><p>As we have observed, there is a trade-off between precision and recall, and improving one, may affect the other. The aim is to find a balance between them. That is how the f1-score is derived.</p><h3><strong>Summary</strong></h3><p>Now that we understand what model evaluation is and the importance of using a Good metric. We have also briefly discussed the two main types of classification problems in Supervised learning. Then we went ahead and looked at accuracy (the metric) its goal and its limitation. We also looked at precision and then recall while intuitively understanding what they measure and their limitations as standalone metrics, especially in highly skewed datasets. Part 1 touched on <strong>what</strong> makes up the f1-score and <strong>why</strong> we use precision and recall.</p><p>In my next blog — Part 2, we will look at <strong>how </strong>precision and recall are used to derive the f1-score. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47861c6748c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are Generative Pre-trained Transformers (GPTs)?]]></title>
            <link>https://medium.com/@anitakivindyo/what-are-generative-pre-trained-transformers-gpts-b37a8ad94400?source=rss-2aa6c4b77317------2</link>
            <guid isPermaLink="false">https://medium.com/p/b37a8ad94400</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[gpt-3-openai]]></category>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[gpt]]></category>
            <dc:creator><![CDATA[anitakivindyo]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 08:11:11 GMT</pubDate>
            <atom:updated>2023-12-14T09:46:32.825Z</atom:updated>
            <content:encoded><![CDATA[<p>From chatbots, to virtual assistants, many AI-powered language-based systems we interact with on a daily rely on a technology called GPTs. But what exactly are GPTs, and how do they enable systems to generate human-like texts? This article answers that question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hubdx4EIWCPHprIYoNhiVQ.jpeg" /><figcaption>Photo by DeepMind on Unsplash</figcaption></figure><p>Generative Pre-Trained transformers are a type of Large Language Models that use deep learning to produce natural language texts based on a given input.</p><p>A user will feed the model with input like a sentence and the generative pre-trained transformer (GPT) creates a paragraph based on information extracted from publicly available datasets. They Can process a wide range of text inputs from text paragraphs, code, even creative writing and they provide insights, analysis or even summaries based on the input given.</p><p><strong>How do GPTs do this?</strong></p><p>Well, as mentioned earlier GPTs are large Language models (LLMs) They are considered “large” because they have been trained on a massive amount of text data, talk about billions of texts. This alone allows the model to learn a vast array of linguistic patterns and associations therefore building a rich knowledge base.</p><p>There are other examples of Large Language Models like BERT — with 110 million parameters, GPT-3 — with 178 million parameters, PaLM — with 540 million parameters.</p><p>Parameters here in the context of LLMs refer to the values in the neural network that are optimized during training. These include different learning rate values, the number of connections between the neurons in the model…and so on.</p><p>The number of parameters in the model determine how complex the model will be and the amount of information it can both process and store. Therefore, it goes without saying, the larger the number of parameters the more sophisticated the model is, but also the more computationally expensive it is to train and use. <em>Have you experienced downtime while using ChatGPT? That is probably why.</em></p><p><strong>Transformers</strong> are at the core of GPTs (it’s even in the name). They were introduced in the 2017 paper — ‘<a href="https://arxiv.org/abs/1706.03762">Attention is all You need’ b Vaswani et al</a></p><h4><strong>What exactly are Transformers?? </strong>🧐</h4><p>They are a type of deep learning model that is widely used in NLP tasks like translation and text summarization. Transformers can process both categorical and numeric data, and are particularly effective in processing sequential data such as texts, audios and videos.</p><h4><strong>What makes Transformers different from traditional Neural Networks? </strong>🤔</h4><p>Unlike traditional neural networks where information flows in one direction through the layers, transformers allow each layer to address all other layers, enabling the network to focus on different parts of the input sequence as it processes the data at different stages. This key mechanism is known as ‘<strong>Self- attention</strong>’ or ‘<strong>Attention</strong>’.</p><p>Self- attention works by computing a set of attention weights for each input token. The weights then show the relevance of each token compared to other tokens. The transformer then uses the attention weights to assign more importance to the most significant parts of the input, and assigns less importance to the less relevant parts.</p><p>In the case of GPTs, the transformer predicts the next word in a sequence based on the input sequence of words.</p><h4><strong>How does the Transformer in GPTs predict the next word?</strong></h4><p>The deep learning model is trained to generate similar text to the input.</p><p>It does this by <strong>maximizing the probability </strong>of generating the next word in the sequence. Once the model is trained, it can be used to generate new text by sampling from the <strong>probability distribution</strong> of potential next words based on the current input. Pretty cool ,right?</p><p><strong>In conclusion</strong>, Transformers can be considered a valuable and effective tool for generating sequential data, as demonstrated by <a href="https://chat.openai.com/chat"><strong>ChatGPT</strong></a>, the popular third-generation Generative Pre-trained Transformer model, also known as GPT-3 developed by OpenAI. If you have ever interacted with a language-based AI system there is a good chance you have encountered GPTs or Generative Pre-trained Transformers.</p><p>Like its predecessors, GPT-3 has shown significant advancements in generating high-quality language output that is almost indistinguishable from human writing. This is a significant leap forward in natural language processing, and GPTs have the potential to transform how we interact with language-based systems.</p><p>You can also have a look at what Generative Ai models entails, <a href="https://medium.com/@anitakivindyo/explaining-generative-artificial-intelligence-models-generative-a-i-1c38793a0fb">here</a>.</p><p><strong>References</strong></p><p><a href="https://arxiv.org/abs/1706.03762">Attention is all You need’ b Vaswani et al</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b37a8ad94400" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explaining Generative Artificial Intelligence Models (Generative A.I)]]></title>
            <link>https://medium.com/@anitakivindyo/explaining-generative-artificial-intelligence-models-generative-a-i-1c38793a0fb?source=rss-2aa6c4b77317------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c38793a0fb</guid>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[anitakivindyo]]></dc:creator>
            <pubDate>Fri, 16 Dec 2022 14:58:08 GMT</pubDate>
            <atom:updated>2022-12-19T09:00:43.270Z</atom:updated>
            <content:encoded><![CDATA[<p>This article explains what generative models are and how different their approach is, in solving machine learning problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tmp2FPekfJQwYbYSzG8ipw.jpeg" /><figcaption>Photo by DeepMind on Unsplash</figcaption></figure><p>One of the biggest advancements of Artificial Intelligence is its ability to create new things. Until recently, most of the Machine Learning models that powered A.I applications made use of discriminative models.</p><p>What are discriminative models ? you may ask, and how are they different from generative models?</p><p>A discriminative model is simply a conditional model, these models tend to answer the question ‘how can the model best classify some data’ or ‘how can the model best predict a value’</p><p>A generative model on the other hand describes how well data can be generated.</p><p>Let’s use an example to better understand this concept.</p><p>Say we have a task to detect whether a camera is pointed at a giraffe,( this is a binary Image Classification task) <a href="https://medium.com/@anitakivindyo/an-introduction-to-machine-learning-164bf4963794"><em>how to define ML problems</em></a></p><p>The most popular approach would be to train a model over a collection of images (some of which should be giraffes and others should not). The model should then <strong>find patterns </strong>in the training images and make a prediction of whether or not the camera is pointed to a giraffe or not. This is the discriminative approach.</p><p>A generative model on the other hand would learn from the input data (of giraffe images and no giraffe) and try to find whether an image labeled “giraffe” resembles data it has seen before more closely, than an image labeled “no giraffe”. This doesn’t stop there, generative models can go ahead and support another use-case. The patterns learned in a generative model can be used to <strong>generate new data</strong> which look similar to the data it has seen before. So new giraffe images.</p><p>In summary, discriminative models draw boundaries in the data space, while generative models try to ‘model’ how data is placed throughout the data space.</p><p>From a statistical point of view, a discriminative model is a model of conditional probability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*LldaVXr1jMgpGmOFS4sAqg.png" /></figure><p>A generative model is a joint probability distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*LcQgdKQYJHlQPQLeSwh2lg.png" /></figure><p>We can now have a look at 3 popular types of Generative AI models and what they do.</p><ol><li>Generative Adversarial Networks (GANs)</li><li>General autoregressive models</li><li>Transformer-based models</li></ol><h3><strong>Generative Adversarial Networks (GANs Networks)</strong></h3><p><em>***adversarial, means involving two people or sides that oppose each other***</em></p><p>This machine learning aproach involves putting two networks against each other to generate new content.</p><p>The training algorithm swaps back and forth between training a:</p><p>i) Generator network — this is produces new data</p><p>ii) Discriminator network — measures how close the generator network data represents the training data</p><h3>AutoRegressive Models</h3><p>These models are used to study systems that evolve over time, and assume the likelihood of some data occuring. However this prediction solely depends on historical data.</p><p>Such models are great at solving regressive problems like weather predictions and stock market predictions</p><h3>Transformer based Models</h3><p>These models are used to study data that occur in a sequential structure. Like the sequence of words in a sentence. So they are commonly used in modelling modern language in the field of Natural Language Processing (NLP) and modelling images Computer Vision (CN).</p><p>Generative AI algorithms can be classified as both unsupervised and semi-supervised machine learning algorithms. This alone makes them quite diverse and allows them to generate new data in the data space.</p><p>I mean, have you tried the lensa App everyone is using? yea, thats Generative A.I. cool right?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c38793a0fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Reinforcement Learning Using AWS Deepracer]]></title>
            <link>https://medium.com/@anitakivindyo/understanding-reinforcement-learning-using-aws-deepracer-dffd5a6f03cc?source=rss-2aa6c4b77317------2</link>
            <guid isPermaLink="false">https://medium.com/p/dffd5a6f03cc</guid>
            <category><![CDATA[aws-deepracer]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[aws-deepracer-league]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[anitakivindyo]]></dc:creator>
            <pubDate>Tue, 11 Oct 2022 12:37:54 GMT</pubDate>
            <atom:updated>2022-10-11T13:43:47.507Z</atom:updated>
            <content:encoded><![CDATA[<p>Understanding Reinforcement Learning Using AWS Deepracer</p><p><em>Here we will explore more about Reinforcement Learning and how to train a model using the AWS Deepracer.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bRooepouB6Sl3I_g-3HsFA.jpeg" /><figcaption>car race track from above. DJI Mavic</figcaption></figure><p>Reinforcement Learning is a subcategory of Machine learning, in which an <em>agent</em> is trained to achieve a goal based on <em>feedback</em> it receives. The <em>agent</em> collects rewards through<em> actions</em> it performs in an <em>environment</em> (an unhelpful action results in a low or no reward, a helpful action on the other hand results in a higher reward).</p><p>Because of its autonomous nature ,reinforcement learning is the closest Machine Learning has come to accurately mimicking how human beings learn…..by trial and error.</p><p>But before we get to the AWS Deepracer, let’s have a better understanding of what Reinforcement learning entails. A RL model will learn from experience and over time it will be able to identify which action leads to the best rewards.</p><p>This type of Machine learning has been used to solve real-world problems that are sequential and have long-term goals. Some of these problems are: <em>Industrial robotics, fraud detection, stock trading, autonomous driving and video game level design </em>to mention a few.</p><p><strong>What is AWS Deepracer?</strong></p><p>AWS DeepRacer car is an autonomous tiny race car designed to test RL models by racing on a physical track.It uses cameras to view the track and reinforcement learning models to control how it maneuvers the track.</p><p>The AWS Deepracer console (on AWS)however does not need you to have the physical car, it simulates an instance of the Deepracer car(agent)and a track(environment) to train the model</p><p><strong>How does an AWS DeepRacer car learn to drive by itself?</strong></p><p>Before we answer that question, here are some terms we should be familiar with to understand the reinforcement learning world.</p><ul><li><strong>Agent</strong> — the piece of software you perform the training on. In AWS Deepracer the agent is a car simulation that embodies the neural network controlling the vehicle and the goal of the car is to finish lap around a track.</li><li><strong>Environment</strong>- the surrounding area with which the agent interacts. For AWS Deepracer this is a simulated racing track. This track defines where the agent can go. The agent explores the environment to collect data to train the neural network.</li><li><strong>The state</strong>- the current position within the environment that is known to an agent. In the AWS Deepracer each state is captured by the front facing camera of the car.</li><li><strong>Action</strong>- for every state an agent needs to take an action towards achieving a goal. In the AWS Deepracer as it approaches a turn it can choose to break or turn left or go straight.</li><li><strong>Reward</strong> — this is the score given as feedback to an agent for each action it takes in a given state. While training the AWS Deepracer model the reward is returned by a<em> reward function. </em>This function can be user-defined.</li><li><strong>Episode</strong>- a period of trial and error. For AWS Deepracer an episode begins at the initial state when the car leaves the starting position and ends at the terminal state when it finishes a lap, bumps off an obstacle or drives off the track.</li></ul><h3>Training A Reinforcement Learning Model using AWS Deepracer</h3><p>Let’s say. We want the vehicle to go from start to finish following the shortest path. And each square represents a state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*MFlMRibtz7HLUC8Q" /><figcaption>Fig A: screenshot from AWS Deepracer</figcaption></figure><p>We can assign a score to each square in the grid. Since we are trying to incentivize the vehicle to learn to drive in the center,the reward will be high in the squares in the center line and low elsewhere.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/0*UQNKICFlvL7GPi7b" /><figcaption>Fig B: screenshot from AWS Deepracer</figcaption></figure><p>During training, the vehicle will start by exploring the grid until it moves out of bounds(zero reward)as shown in Fig C or until it reaches the destination as shown in Fig D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*4fSwtikNJj7yiwE7" /><figcaption>Fig C:screenshot from AWS Deepracer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*x0qJkqkxMdK0BZf_" /><figcaption>Fig D: screenshot from AWS Deepracer</figcaption></figure><p>As the vehicle is driving around the environment, it accumulates rewards from the scores that have been defined.</p><p>Reinforcement Learning algorithms are trained by repeated optimization of <strong>cumulative rewards</strong>.This simply means that the model will learn which actions result in the highest cumulative reward on the way to the goal.</p><p>However ,it is important to note that learning does not happen during the first iteration.</p><p>When the agent first starts out, it explores by wandering in random directions and the more training an agent gets, the more it learns about an environment. This experience helps it become more confident about the actions it chooses.Exploitation means the agent begins to ‘exploit’ or use information from previous experiences to help it reach its goal.</p><p>The agent needs to <em>explore </em>and see where it can get high rewards before it can <em>exploit</em> that knowledge .</p><p><strong>Note</strong> :<em> Different training algorithms utilize exploration and exploitation differently.</em></p><p>Although AWS DeepRacer may be autonomous, you have an important role to play in the success of your trained model. This can be achieved by how you are going to define the following.</p><p>1.The training algorithm</p><p>2.Action space</p><p>3.Hyperparameters</p><p>4.Reward functions</p><p><strong>1. Training algorithm</strong></p><p>This algorithm basically tells the model it needs treats. It does so by defining the model learning objective which is to maximize total cumulative reward. Training is an iterative process.</p><p>In a simulator the agent will explore the environment and build up experience. The experiences collected are used to update the neural network periodically. The updated models are then used to create more experiences.</p><p>Example of training RL training algorithms are</p><ul><li>Soft Actor Critic (SAC): this algorithm embraces exploration and is data efficient, but it lacks stability.</li><li>Proximal Policy Optimization(PPO) :this algorithm is stable but data hungry, this is because it uses two neural networks during training, a policy network and a value network.</li></ul><p><strong>2. Continuous action space</strong></p><p>An action space is the state of all valid actions,choices available to an agent as it interacts with the environment.This allows the agent to select an action from a range of values that you define for each state.It can either be a discrete action space or a continuous one.</p><p><strong>3. Hyperparmeters</strong></p><p>These are variables that control the performance of your agent during model training</p><p>For example, the <em>learning rate</em>- a hyperparameter that controls how many new experiences are counted in learning at each step.</p><p>i.e. A higher learning rate results in faster training but may reduce the model’s quality.</p><p><strong>4. The Reward function</strong></p><p>Its purpose is to encourage the agent to reach its goal. Figuring out which actions to reward is one of the most important steps in creating your model’s success.</p><p>In AWS Deepracer the reward function is a python function that is given certain parameters that describes a state that returns a numeric reward.</p><p>The parameters can include, the state of the track, position of the track, its speed, and steering angle</p><p>You can then define a reward function to encourage the driving behavior you like, using these parameters. If you want the car to stay on the track, if you want the car to follow the center line or if you want it to avoid zig-zags. All these are defined in the reward function</p><p>An example of a reward function for the agent to stay on track</p><pre>def <strong>reward_function</strong>(params):</pre><pre>&#39;&#39;&#39;</pre><pre>Example of rewarding the agent to stay inside the two borders of the track</pre><pre>&#39;&#39;&#39;</pre><pre><em># Read input parameters</em></pre><pre><strong>all_wheels_on_track = params[&#39;all_wheels_on_track&#39;]</strong></pre><pre><strong>distance_from_center = params[&#39;distance_from_center&#39;]</strong></pre><pre><strong>track_width = params[&#39;track_width&#39;]</strong></pre><pre><em># Give a very low reward by default</em></pre><pre><strong>reward = 1e-3</strong></pre><pre><em># Give a high reward if no wheels go off the track and</em></pre><pre><em># the agent is somewhere in between the track borders</em></pre><pre><strong>if all_wheels_on_track and (0.5*track_width - distance_from_center) &gt;= 0.05:</strong></pre><pre><strong>reward = 1.0</strong></pre><pre><em># Always return a float value</em></pre><pre><strong>return float(reward)</strong></pre><p><em>This reward function has the </em><strong><em>distance from the center, wheels on track and track width</em></strong><em> parameters defined</em></p><h3><strong>Reward Graph</strong></h3><p>While training your car in the AWS DeepRacer console, your training metrics are displayed on a reward graph.</p><p>Plotting the total reward from each episode allows you to see how the model performs over time. The more reward your car gets, the better your model performs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*FbvIDX4qiNDf_RDB" /><figcaption>Fig E: screenshot from AWS Deepracer</figcaption></figure><ul><li>Average reward graph- represents average reward the agent earns during a training iteration.</li><li>Average Percentage completion(training graph)- represents the average percentage of track completed by the agent in all training episodes. It shows the performance of the vehicle while experience is being gathered.</li><li>Average percentage completion (evaluation graph)- as the model updates, the performance of the existing model is evaluated — this graph is the average percentage of the track completed by the agent ,all episodes run during the evaluation period.</li><li>Best model line- shows the reward earned during a training iteration.</li><li>Reward (primary)y-axis- shows the reward earned in each iteration.</li><li>Percentage track completion (secondary) y-axis — shows the percentage of the track the agent completed during training iteration.</li><li>Iteration x-axis- shows the number of iterations completed during the training job.</li></ul><p>In a well trained model, the evaluation percentage reaches 100% , then the training percentage reaches 100% or roughly 100 or so iterations. At that point the model is well trained.</p><p>Training it further will lead to overfitting.</p><p><strong>Avoid Overfitting!</strong></p><p>Overfitting/Overtraining — can become an issue when a model is trained in a specific track for too long.</p><p>A good model should be able to make decisions based on features of the road, such as sidelines and centerlines and be able to drive on just any track.</p><p>An overtrained model, on the other hand , learns to navigate using landmarks specific to an individual track.</p><p>For example:</p><p>The agent turns a certain direction when it sees uniquely shaped grass in the background or a specific angle corner of the wall .The resulting model will run beautifully on that specific track, but perform badly on a different virtual track or even the same track in a physical environment due to slight variations in angles, textures and lighting.</p><p><strong>Adjust Hyperparameters</strong></p><p>Hyperparameters — are variables that essentially act as settings for the training algorithm that control the performance of your agent during training.</p><p>The AWS Deepracer default parameters are quite effective, but occasionally you may consider adjusting them.Adjusting your parameters after training iterations of your model will tailor how you want your model to perform.</p><p><strong>Conclusion</strong></p><p>Reinforcement learning is an exciting field of ML. Now that you have a better understanding of how it works, you can implement neural networks with different training algorithms to learn by trial and error and solve real world problems like : how to go about business planning on a defined environment (say with a set budget and strategies), game optimization using simulated environments. The list is endless.</p><p>In the meantime you can go ahead and create a racer profile on AWS and train your model and join the AWS Deepracer league and participate in exciting events and competitions like formular 1 league.</p><p>References</p><p><a href="https://aws.amazon.com/deepracer/">AWS Deepracer</a></p><p><a href="https://us-east-1.console.aws.amazon.com/deepracer/home?region=us-east-1#getStarted">AWS Reinforcement learning</a></p><p><a href="https://www.udacity.com/courses/all">Udacity Reinforcement learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dffd5a6f03cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Machine Learning]]></title>
            <link>https://medium.com/@anitakivindyo/an-introduction-to-machine-learning-164bf4963794?source=rss-2aa6c4b77317------2</link>
            <guid isPermaLink="false">https://medium.com/p/164bf4963794</guid>
            <category><![CDATA[ml-process]]></category>
            <category><![CDATA[intoduction-to-ml]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[mls]]></category>
            <category><![CDATA[machine-learning-process]]></category>
            <dc:creator><![CDATA[anitakivindyo]]></dc:creator>
            <pubDate>Tue, 26 Jul 2022 18:56:07 GMT</pubDate>
            <atom:updated>2022-10-05T12:40:23.153Z</atom:updated>
            <content:encoded><![CDATA[<p>So what exactly is Machine learning? Well, before we get into the scientific terms and definitions, the name “Machine learning” can give us an idea of what it entails. In simpler terms, computers or ‘machines’ learn how to solve problems and improve from experience automatically. Cool, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CtqeFH2oNVqKEnENQAdgMg.jpeg" /></figure><p>A more scientific definition of Machine learning <em>Machine Learning is a branch of artificial intelligence that allow software applications to predict outcomes more accurately without being explicitly programmed to do so.</em></p><p>How the computers/software/machine learns can be categorized into 3 main ways.</p><p><strong>Supervised learning:</strong> here the training dataset has a corresponding label(output) associated with it, the algorithm therfore learns to predict the label (output)values</p><p><strong>Unsupervised learning</strong>: here there are no labels for training data, therefore the algorithm tries to learn underlying patterns in the given data</p><p><strong>Reinforcement learning</strong>: here the algorithm figures out which actions taken that maximize a reward on the way to achieving a specific goal.</p><p>There are 5 major steps that have simplified the Machine learning process, and these are.</p><p>Step1:Problem definition</p><p>Step 2:Building the dataset</p><p>Step 3:Training the Model</p><p>Step 4:Evaluating the model</p><p>Step 5:Using the model/model Inference</p><h4>1.Problem Definition</h4><p>This step involves specifically defining the machine learning task by understanding the problem. Is it going to be a supervised learning task? Is the data categorical or continuous? Is it going to be an unsupervised learning task? or do we implement reinforcement learning?</p><p>For example</p><p>An e-commerce company wants to know whether it should focus more on website development or on mobile application development since it launched both applications 5 years ago.</p><p>How do we define the problem statement? This problem is quite vague, we need to get more specific and ask very specific questions.</p><p>A better example could be:How does the time users spend on the mobile application compare to the time users spend on the website application?</p><p>This can help us come up with the ML task to proceede with. In this case, it is a supervised learning task since the data we will use, will probably have the solution (a label), and we will implement continous regression since we will be using numeric data.</p><h4>2. Build the Dataset</h4><p>Now we collect the data that matches the Machine learning Task defined. This can be achieved by performing direct SQL queries to a database, Web Scrapping or even running a model over data to generate needed labels.</p><p>After collecting data, we inspect the quality of the data. This is a very important step. Here we remove outliers, check for incomplete values and transform and preprocess data. Keep in mind, we need our data to be consistent because poor quality of data can affect the performance of our model.</p><p>We then perform some summary statistics to check if the data is consistent to the assumptions made. This involves calculating mean, Inter-Quartile range, standard deviation. This gives us insight of the scope, shape and scale of the dataset.</p><p>We can then visualize the data, to have a better understanding of the dataset. Especially if you are trying to show the existing trends in the data to company stakeholders, graphs are your friends . It makes everyone’s work easier, trust me.</p><h4>3. Model Training</h4><p>So now our dataset is all clean, preprocessed ,and we have a better understanding of the data. Its now time to train our model. Yay!</p><p>To feed our data to the model we need to split the dataset into the training dataset and testing dataset. Most of the time this is done 80% ,20% respectively. So we train our model using the training dataset first, then we test our trained model using the test dataset.</p><p>The training process involves, feeding training data into the model, computing the loss function of the result and updating the model parameters(weights) to reduce the loss. The loss function measures how far or close our model’s values are from the actual values. During training we try to minimize this loss without underfitting or overfitting our model.</p><p>This step can be iterative as we try to compare different model training algorithms and how good they perform in a specific use case.</p><p>Some model examples include : linear models,tree-based models, deep learning models.</p><h4>4.Model Evaluation</h4><p>After we’ve collected data and trained our model we have to now evaluate how well our model is performing.</p><p>We can use different statistical Metrics to evaluate our model.</p><p>Some statistical metrics include; accuracy (the most common),log loss,Mean Absolute Error, precision, adjusted square ,R-squared (R²), Mean Square Error, Root Mean Square Error among others.</p><p>However, note that the metrics used for evaluation are specific to the problem defined and the training algorithm used.</p><p>For example.</p><p>For a linear regression model,accuracy is harder to illustrate because it is quite impossible to predict the exact value, but rather how close your prediction is against the real value. The metrics for model evaluation in linear regression can be R-square/adjusted r-square (note that these 2 are performed differently), Mean square error or Root mean square error and mean absolute error.</p><h4>5 Inference/ Use the model</h4><p>After evaluating our model and are satisfied by the results. We can now use our model to generate predictions on real-world problems using ‘unseen data’ in the field. This is called<strong> Inferencing.</strong></p><p>Note that the machine learning process is very iterative, so dont loose heart. You will need to monitor the model and its results during inferencing. You might even need to re-investigate the data, modify some parameters in the training algorithm or even change the model type for the training.</p><p>However the case, the Machine learning process can be a very interactive and iterative process. It can be fun and quite eye-opening. You can kickstart your journey by using existing frameworks that have working implementations of models and training algorithms.</p><p>Let’s get modelling :) <a href="https://www.kaggle.com/">https://www.kaggle.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=164bf4963794" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>