<?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 Thomas Sve on Medium]]></title>
        <description><![CDATA[Stories by Thomas Sve on Medium]]></description>
        <link>https://medium.com/@thomas.asve?source=rss-7c6a8355e59e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*T6o8EFU0myEphfYG</url>
            <title>Stories by Thomas Sve on Medium</title>
            <link>https://medium.com/@thomas.asve?source=rss-7c6a8355e59e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 05:34:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thomas.asve/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[Writing tests for data science products]]></title>
            <link>https://medium.com/godtlevert/writing-tests-for-data-science-products-2184e8d713bb?source=rss-7c6a8355e59e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2184e8d713bb</guid>
            <category><![CDATA[pytest]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[unittest]]></category>
            <dc:creator><![CDATA[Thomas Sve]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 12:41:55 GMT</pubDate>
            <atom:updated>2022-12-12T13:04:36.369Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*l73Recyf_nXGohKxbQC5gQ.png" /></figure><p>Here at LMK Group, data and machine learning have a central role in creating a good customer experience. Over the years, we have built products that are now essential to the company. As a result, writing good tests has become an increasing focus.</p><p><strong>Why testing is important</strong></p><p>It is common for testing to be underprioritized when building data science products. This can happen for a variety of reasons, such as time constraints, a focus on quickly developing and deploying a working product, or a lack of understanding about the importance of testing. However, underprioritizing testing can lead to problems in the long run, such as unreliable or faulty code, difficulty maintaining and updating the product, and potentially serious issues in production. It is important to prioritize testing as part of the development process to ensure the quality and reliability of your data science product.</p><p><strong>Unit test with </strong><strong>assert</strong></p><p>Unit testing is an important part of the data science development process. It allows you to test individual units or components of your code, such as functions or modules, to ensure that they are working properly. This can help you identify and fix issues early in the development process, before they have a chance to cause problems in the final product. Unit testing can also help you maintain and update your code over time, by providing a suite of tests that can be run to ensure that changes to the code do not break existing functionality. Additionally, unit testing can provide valuable documentation for your code, helping new team members understand how the code works and how it should be used.</p><p>For instance, imagine we have a function that calculates the maximum of a list of numbers. We can use the assert keyword to check that the function is returning the expected result. For example, if we pass the function the list [4, 7, 3, 2, 8, 1], we would expect it to return 8 as demonstrated in the block below:</p><pre>def test_max_function():<br>  l = [4, 7, 3, 2, 8, 1]<br>  assert max(l) == 8, &quot;Maximum number in list should be 8&quot;</pre><p><strong>Pytest</strong></p><p>When working with a product, we might create several function that cleans and preprocess our data. To ensure that these works as intended, we might use unit testing to test the function. For instance, below we test a function that moves dishes that has previously been recommended to the end of the list. In order to ensure that the function works properly, we need to test it with different sizes and lengths of input data using the parametrize function in pytest. This will help us determine whether the function is working properly and identify any potential issues that need to be addressed.</p><pre>@pytest.mark.parametrize(<br>    &quot;recommended_dishes, expected_output&quot;,<br>    [<br>        (<br>            [[1, 5, 21, 30], [2, 5, 1, 6], [10, 3, 5, 7]],<br>            [[1, 5, 21, 30], [2, 6, 5, 1], [10, 3, 7, 5]],<br>        ),<br>        (<br>            [[2, 3, 21, 30], [2, 5, 1, 6], [10, 3, 5, 7]],<br>            [[2, 3, 21, 30], [5, 1, 6, 2], [10, 7, 3, 5]],<br>        ),<br>        (<br>            [[1, 5, 21, 30], [2, 5, 1, 6], [10, 3, 5, 7]],<br>            [[1, 5, 21, 30], [2, 5, 1, 6], [10, 3, 5, 7]],<br>        ),<br>    ],<br>)<br>def test_deprioritize_repeated_dishes(<br>    recommended_dishes, expected_output<br>):<br>    assert (<br>        test_deprioritize_repeated_dishes(recommended_dishes)<br>        == expected_output<br>    )</pre><p><strong>Azure pipelines</strong></p><p>At LMK Group, we use Azure and as part of that, we use Azure Pipelines to perform continuous deployments for our data science products. This allows us to automatically build, test, and deploy our code whenever there are changes to the codebase. As part of the deployment process, we also run all of our tests and publish the code coverage, which provides us with important information about how much of our code is being tested and how effective our tests are at finding potential issues.</p><p><strong>Summary</strong></p><p>The data science team at LMK Group delivers product that are essential to the company and it is key that these works as intended. Writing tests is therefore very central tool and is essential when delivering high impact solutions. And just as with any other python solution, unit testing and pytest works great to make sure that our product works as intended.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2184e8d713bb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/godtlevert/writing-tests-for-data-science-products-2184e8d713bb">Writing tests for data science products</a> was originally published in <a href="https://medium.com/godtlevert">Cheffelo  — Tech &amp; Data</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>