<?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 Samar Deen on Medium]]></title>
        <description><![CDATA[Stories by Samar Deen on Medium]]></description>
        <link>https://medium.com/@samar-deen?source=rss-76c1e8243537------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*25cTXJhfRnKnDMwGllspyw.jpeg</url>
            <title>Stories by Samar Deen on Medium</title>
            <link>https://medium.com/@samar-deen?source=rss-76c1e8243537------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:53:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samar-deen/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 modular MLOPs-ready Python code for easy explainability and interpretation]]></title>
            <link>https://medium.com/data-science-at-microsoft/writing-modular-mlops-ready-python-code-for-easy-explainability-and-interpretation-20538e901914?source=rss-76c1e8243537------2</link>
            <guid isPermaLink="false">https://medium.com/p/20538e901914</guid>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[modular-code]]></category>
            <category><![CDATA[argparse]]></category>
            <category><![CDATA[python-module]]></category>
            <dc:creator><![CDATA[Samar Deen]]></dc:creator>
            <pubDate>Tue, 17 Oct 2023 07:16:38 GMT</pubDate>
            <atom:updated>2023-10-17T07:16:38.228Z</atom:updated>
            <content:encoded><![CDATA[<p>By <a href="https://www.linkedin.com/in/samar-deen-phd-2064389/">Samar Deen</a> and <a href="https://www.linkedin.com/in/cerenaaa/">Ceren Altincekic</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*JQUANOq9H71s2fAynosarQ.png" /><figcaption>Modular lives: Image generated by Microsoft-internal implementation of DALL·E 2.</figcaption></figure><p>The continuing growth of data science has led many professionals without a coding background to learn Python to experiment with various Machine Learning methods. Among these, Python scripting and notebook execution have become popular tools to generate proofs of concept and build non-productionized but nevertheless useful models.</p><p>Given the widespread use of these scripts both in online blogs and in workplaces, we thought it would be useful to outline some coding principles to enable citizen data scientists to move their coding to the next level and get their models ready for MLOps.</p><p>In this article, we discuss what MLOps is and what is required to productionize Python scripts into fully fledged outputs ready for use in actual business cases. We also provide an overview of the Python main function and its importance in getting code to be production ready.</p><h3>MLOps: The sustainable way to deploy ML models</h3><p>MLOps, short for Machine Learning Operations, refers to the practice of applying <a href="https://en.wikipedia.org/wiki/DevOps">DevOps</a> principles and practices to the lifecycle management of Machine Learning models. It aims to automate the deployment, monitoring, and management of ML models at scale. It ensures reproducibility and version control of models, allowing easy tracking of changes and facilitating model governance. Ultimately, MLOps helps organizations deliver reliable and scalable Machine Learning solutions in a more efficient and effective manner.</p><p>Typically, a data science project starts with <a href="https://en.wikipedia.org/wiki/Exploratory_data_analysis">exploratory data analysis</a> (EDA) and a <a href="https://en.wikipedia.org/wiki/Proof_of_concept">proof of concept</a> (PoC) in which the data scientist builds a simple model to demonstrate the feasibility of the solution needed by business stakeholders. Once the task is deemed to be achievable, the data scientist improves the PoC by training and optimizing the model, applying various ML algorithms and evaluating its performance using appropriate metrics. Then, the model is tested on unseen data and validated for performance and generalizability. After the data scientist is satisfied with the outcome, the results must be <em>productionized</em> — in other words, prepared and deployed in a production environment for use in real-world applications. This is the point at which MLOps comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*nIFdlJv40qj1qeMe7UimHg.png" /><figcaption>Source: <a href="https://learn.microsoft.com/en-us/training/modules/introduction-development-operations-principles-for-machine-learn/1-introduction?ns-enrollment-type=learningpath&amp;ns-enrollment-id=learn.wwl.introduction-machine-learn-operations">Introduction to DevOps principles for machine learning</a>.</figcaption></figure><h3>Converting ML experiments into production-ready Python code</h3><p>For a script to work seamlessly in the production environment, the data scientist must change the script into functions that can be automatically run by ML engineers, who are the ones responsible for automating predictive models. The steps of this transition include cleaning nonessential code, refactoring notebook code into functions, creating a Python main function, and creating unit tests for each Python file. We describe each of these in turn.</p><h4>Cleaning nonessential code</h4><p>In the development environment, the data scientist runs cells or scripts that test the code, check dates, and create visualizations. While these are essential in a development environment, they must be removed in the production environment. That’s because the code must run seamlessly, without interruptions, to generate the final output.</p><h4>Refactoring Azure Synapse, Jupyter, or Databricks notebook code into functions</h4><p>Wherever the data scientist implements their experiment, the initial stage typically involves stand-alone code snippets instead of packaged functions. For MLOps, the code must be refactored into reusable functions with a specific task. This ensures the reusability and the testability of the production output.</p><p>One of the most common practices in the transformation of stand-alone code to production-ready code for MLOps is the introduction of the Python main function.</p><h4>Creating a Python main function</h4><p>In MLOps, creating a main function is essential for establishing a standardized and organized entry point for your Machine Learning pipeline or workflow. The main function serves as a central control hub, allowing you to define the sequence of steps, data processing, model training, evaluation, and deployment processes. This promotes code modularity, maintainability, and reproducibility, making it easier to collaborate with team members, automate tasks, and track the entire lifecycle of your Machine Learning projects.</p><p>The main function enables the data scientist’s model script to run as a standalone executable script. The main function has all the necessary code to initialize, import modules, and call functions (such as the user-built <strong>utilities.py</strong> functions, which we introduce later) to execute the program.</p><p>To learn more about the main function, see the following tutorial: <a href="https://python-tutorials.in/python-main-function-with-examples-understand-__main__/">Python Main Function with Examples</a>. Beyond this point, your objective should be to get your code set up such that it can run end to end within the bounds of this main function.</p><p>As an example, let’s start with creating a simple Python main function. You can get access to the code here: <a href="https://gist.github.com/SamarDeen/fd210f07d9e39072b019a5962ef24e4b">The main function (simple) (github.com)</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd86a37b13845a5e94bd11bcbec91775/href">https://medium.com/media/dd86a37b13845a5e94bd11bcbec91775/href</a></iframe><p>This simple main function simply reads a <a href="https://en.wikipedia.org/wiki/Comma-separated_values">csv</a> file and writes it to the output folder. Think of the code above as a structure within which you will embed the code from your ML model. You can call this script <strong>mymainfile.py</strong> from your terminal with the code:</p><pre>py simple_main_function.py --input_folder  &quot;Desktop/Script/Input&quot; --input_file_name test.csv --output_folder &quot;Desktop/Script/Output&quot;</pre><p>We recommend that you get familiar with the <strong><em>argparse </em></strong>module (see <a href="https://docs.python.org/3/library/argparse.html">argparse — Parser for command-line options, arguments and sub-commands — Python 3.11.5 documentation</a>), which makes it easy to write user-friendly command-line interfaces.</p><p>The code above parses the input folder name, input file name, and output folder name from the command line to the main function. This information will be used to define the input path for the modeling data and the output path for the scored data.</p><h4>Creating unit tests for each Python file</h4><p>Now modularize your ML model into segments that logically separate your code via functions. These can be structured so that debugging during production can be isolated. One such modularization of code is:</p><ol><li>Read data</li><li>Clean data and create model features</li><li>Train model</li><li>Test and validate model</li><li>Score and save model output</li></ol><p>The code below is one such example in which an additional Python script <strong>utilities.py </strong>can have modularized functions. You can name this Python script anything really — the idea is to include all user-defined modularized Python functions that you need to execute your script. This ensures that the main function does not get cluttered with too many commands. The modular approach also makes it easier to debug.</p><p>Here is an example of what a function in the <strong>utilities.py</strong> looks like! Feel free to augment this with your own functions as you build your model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4b929839bd8f27ea8410718c01a01b2/href">https://medium.com/media/f4b929839bd8f27ea8410718c01a01b2/href</a></iframe><p>The code below shows how the main function makes use of the utilities package we created to compile our modularized pipeline into the final output in (code also available in <a href="https://gist.github.com/SamarDeen/b101a72f11d474a95b694a01e17d0c71">the main function (github.com)</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/395b218c47d8ef3b7eef980071ee07a8/href">https://medium.com/media/395b218c47d8ef3b7eef980071ee07a8/href</a></iframe><p>If you’ve made it this far, now is the time to test it out! If your main function runs error free, consider your code ready for handoff to a Machine Learning engineer or to the data engineer responsible for moving your code from the development environment to the production infrastructure. A perk of using this approach is that your code is agnostic to the choice of Machine Learning platform.</p><h3><strong>Conclusion</strong></h3><p>In this article we introduced the concept of MLOps, which stands for Machine Learning Operations, highlighting its role in applying DevOps practices to manage the life cycle of Machine Learning models. MLOps automates deployment, monitoring, and management of ML models at scale, ensuring reproducibility, adding version control, and facilitating model governance. As an example, we detailed the progression of a data science project from exploratory data analysis to the deployment of a production-ready model.</p><p>In this way, MLOps becomes pivotal in orchestrating the seamless transition of the model from development to deployment, offering a sustainable approach to deploying ML models effectively for real-world applications. We also discussed the transformation of stand-alone code into production-ready code by refactoring it into reusable functions and introducing the Python main function. Ultimately, we underscored the significance of structured code for successful MLOps implementation.</p><p>To recap, what are we trying to achieve with MLOps? A core part of MLOps is that the process of testing, integrating, building, packaging, and deploying a Machine Learning solution should be automated. MLOps aims to combine software development and post-deployment operations (from <a href="https://www.packtpub.com/product/machine-learning-engineering-with-python/9781801079259"><em>Machine Learning Engineering with Python</em></a>, Andrew McMahon, 2021.)</p><p>Whether you are aiming to build an online or batch Machine Learning system (see <a href="https://csmoon-ml.com/index.php/2020/05/30/batch-vs-online-learning/">Batch vs. Online Learning — Things to Know about Machine Learning (csmoon-ml.com)</a> and <a href="https://www.analyticsvidhya.com/blog/2015/01/introduction-online-machine-learning-simplified-2/">Online Machine Learning Algorithm | Online Vs Batch Learning (analyticsvidhya.com)</a>) your development code must be structured such that the transition from the development environment to the production infrastructure seamlessly executes the Machine Learning tasks and reproduces desired results.</p><p>Our next article in the MLOps series will dive deep into Azure Machine Learning (AML) Experiments: After you productionize your code, you can set up your first AML experiment to see how the pipeline works and whether you get useful results.</p><p><em>Note: The authors would like to acknowledge that the content in this article is derived from numerous knowledge sharing sessions with colleagues at Microsoft, with a special shout out to </em><a href="https://www.linkedin.com/in/manish-shukla1/"><em>Manish Shukla</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20538e901914" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-at-microsoft/writing-modular-mlops-ready-python-code-for-easy-explainability-and-interpretation-20538e901914">Writing modular MLOPs-ready Python code for easy explainability and interpretation</a> was originally published in <a href="https://medium.com/data-science-at-microsoft">Data Science + AI at Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Five questions to ask before using secondary data for data science]]></title>
            <link>https://medium.com/data-science-at-microsoft/five-questions-to-ask-before-using-secondary-data-for-data-science-833c8b77b889?source=rss-76c1e8243537------2</link>
            <guid isPermaLink="false">https://medium.com/p/833c8b77b889</guid>
            <category><![CDATA[secondary-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[data-validation]]></category>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <dc:creator><![CDATA[Samar Deen]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 08:16:58 GMT</pubDate>
            <atom:updated>2023-10-12T22:00:41.592Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VlBFZfFM2j6QVHMl" /><figcaption>Photo by <a href="https://unsplash.com/@ravinrau?utm_source=medium&amp;utm_medium=referral">Ravin Rau</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Imagine for a moment that you just inherited a rich feature set of secondary data, and you plan to use it to augment your dataset for a data science project. Before you start celebrating (or panicking… depending on your personality), it’s important to pause and do some exploratory data analysis (EDA).</p><p><em>Secondary data</em> is that which has been acquired from third-party sources or lent out from a successful team that, for example, has just productionalized a solution after numerous months of work and planning. We may want to use secondary data to leverage this type of good work, promote a second use-case, or simply fast-track our own data science solution. Whatever the motivation, it’s important to create a checklist of data validation steps to ensure that you can trust the inherited data for your solution.</p><p>While I’ve written at length about fostering <a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898?source=friends_link&amp;sk=8523ecb31d85109919c47287ccb021a4">trust </a>in a data science solution, the question can be flipped. Should <em>you</em> trust secondary data? The answer is, simply, no — at least not without applying some due diligence first. Here are <strong>five </strong>key questions that you must address before you give the green light to your team and start investing in ingesting this data for your own data science solution.</p><p>But first things first: Assume you’re working with the right beast! (This reminds me of the <a href="https://en.meming.world/wiki/Dog_vs._Werewolf">dog versus werewolf</a> meme.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nstOOQFF1BStehwznQZmsQ.png" /><figcaption>Captions edited by author</figcaption></figure><p>Then ask the following questions:</p><ol><li><strong>Is the data optimized for the same outcome? </strong>What is the outcome variable of these features? If the dataset is not optimized for a specific outcome feature, then you can move on to the next question. If the features have been built to answer a specific research or business question, however, then determine how aligned that is with your own key variable of interest. Try to get into the mindset of the scientist who created this dataset. By looking through the feature list, create the list of hypotheses that correspond to the features. Subset the data to test the features that match your hypothesis. Now determine whether there are any missing features that you may also want to test. Acknowledge that any model results built on this data may have <a href="https://www.statology.org/omitted-variable-bias/">omitted variable bias</a>, given that you have not tested all your hypotheses.</li><li><strong>Is it the same population of interest? </strong>While you can build a model with certain features eliminated, missing data can be a significant limitation. Say that you want to build a model to predict customer preference for products. The customer base includes commercial, consumer, and enterprise. The customer is geographically located in the United States, Canada, and Mexico. The secondary data has a rich feature set of buying behavior and other online behaviors. <strong><em>First</em></strong><em>,</em> get the distribution of data for these key demographic groups using the secondary data and compare with your own customer base. When you do this exercise, don’t be surprised if you find that the secondary data covers only a subset of the groups. Say that the secondary data is limited to commercial customers in the USA. Don’t be dismayed by this new insight. Figure out what percentage of the population in your customer base consists of commercial customers in the USA. If it is, for example, 60 percent, that’s not so bad. You can build a model for this segment. Again, acknowledge that, and make sure you communicate it to your leadership team. If you use the data for the entire customer base, then you’re introducing a population bias into your model, and 40 percent of the features in the secondary dataset will be <em>null</em>. Your <strong><em>second</em> </strong>exercise is to identify a unique identifier to merge the secondary data to your own dataset, and then figure out the match rate. If 80 percent of the commercial customers in the USA get matched to the unique identifier in the secondary dataset, then you’re in the clear. The lower this match rate, however, the more you risk losing key insights. You can further drill down and identify whether there is any other segment of the population that is missing. Say, for example, that the industry segment Automotive and Aviation is not covered — make a note of it. The <strong><em>third</em> </strong>exercise is to determine time-related dependencies. Are these user behaviors shifting over time? Does the secondary data have a timestamp to which we can match the attributes? Was the data collected two years ago? Has the customer pool shifted since that time? Is that the reason for the missing 20 percent of customers? Understanding time-related dependencies can prevent any additional biases that may creep into the data and skew your results. If the data is better populated for older customers, for example, then any predictions made for new customers will be less accurate. In this case, further segment your proof-of-concept (POC) model to account only for older customers.</li><li><strong>Is there transparency in the data engineering process? </strong>Data dictionaries and well-documented scripts are just as helpful as getting secondary data in the first place. These can be particularly valuable when outliers are found or when features are one-hot-encoded. Leverage these to understand the features that represent <a href="https://www.investopedia.com/terms/r/rfm-recency-frequency-monetary-value.asp">recency and frequency</a>. The scripts can also be used to identify the data source, and any logic necessary for you to replicate if you decide to include these features in your data pipeline. <strong><em>Do not</em> </strong>productionalize the solution unless you have tested and validated the features in the secondary data for your solution in a development environment. You must test for drift coming from upstream engineering.</li><li><strong>Is the model refreshed regularly and does the feature set remain constant? </strong>Are you using any propensity scores from the secondary data? If the answer is yes, then there are specific questions to ask before using the score from a solution. Is the model static or is it a constant learner? Does the model automatically change the features that are used for predicting the score? If the answer is yes to all, then you may not want to use the score. Any drift in the score will immediately introduce a drift in your dataset.</li><li><strong>Is the data GDPR compliant? </strong>The<strong> </strong><a href="https://gdpr.eu/">General Data Protection Regulation (GDPR)</a> is a data-governing directive that places certain constraints on how businesses may profile customers and process personal data. It’s important to be sure that your secondary data is GDPR compliant, and more importantly, to discuss with your legal team whether there are any additional approvals that you must fulfill before you use any data that may be considered to be <a href="https://www.gdprsummary.com/gdpr-definitions/personally-identifiable-information/">personally identifiable information (PII)</a>. In case GDPR compliance is expressly stated in the secondary data, confirm it first to prevent inheriting legal baggage.</li></ol><h4><strong>I said “No” to most of the questions above… but I am an optimist. Will this data suffice for a proof of concept?</strong></h4><p>What if I need to develop a quick proof of concept (POC) but I have limited resources? If you are unable to say “Yes” to all five questions, it doesn’t necessarily mean that you must discard it. For an economist this is not a novel situation. Secondary data is often used in economic studies to prove social theories. The trick is to ensure that you acknowledge the limitations of the data, the population covered, and any other assumptions that you as a scientist may have made during the scientific process. For an example, read the assumptions of any economics paper. These include the hypothesis testing, feature selection, feature engineering, identification of the outcome variable, choice of unit of analysis, model selection, and eventually building out the model. Acknowledging the caveats may help you address any limitations in the data. As you build out the second iteration of the solution you can address any biases (such as outliers, omitted variables, population of interest, historical and behavioral features, and so on) that the secondary data may have.</p><h4><strong>So then… am I actually saving time?</strong></h4><p>It depends. Secondary data is great for building out POCs. Ultimately, you want to build out your own pipeline and incorporate the feature engineering task. But at the outset, yes, you do save time by testing out the data for your particular use case.</p><h4>Want to learn more?</h4><p>I found this “<a href="https://careerfoundry.com/en/blog/data-analytics/secondary-data-analysis/">guide to secondary data analysis</a>” useful for further analysis on secondary data. Also, this quick introduction video from Cassie Kozyrkov to <a href="https://youtu.be/8uC9uJQBfck">wrangling inherited data</a>, and an interesting article on how to deal with <a href="https://medium.com/data-science-at-microsoft/reducing-omitted-variable-bias-with-fixed-effects-regression-models-8a132a8f2c44?source=friends_link&amp;sk=b0c54996e136a01b92e5fec25688e82a">omitted variable bias</a>.</p><p><em>Samar Deen is on </em><a href="https://www.linkedin.com/in/samar-deen-phd-2064389/"><em>LinkedIn</em></a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=833c8b77b889" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-at-microsoft/five-questions-to-ask-before-using-secondary-data-for-data-science-833c8b77b889">Five questions to ask before using secondary data for data science</a> was originally published in <a href="https://medium.com/data-science-at-microsoft">Data Science + AI at Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trust in AI versus trustworthy AI: Why is it important? (Part 3 of 3)]]></title>
            <link>https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-3-of-3-c9aef3cb2478?source=rss-76c1e8243537------2</link>
            <guid isPermaLink="false">https://medium.com/p/c9aef3cb2478</guid>
            <category><![CDATA[z-test]]></category>
            <category><![CDATA[false-positive]]></category>
            <category><![CDATA[confusion-matrix]]></category>
            <category><![CDATA[false-negative]]></category>
            <category><![CDATA[trustworthy-ai]]></category>
            <dc:creator><![CDATA[Samar Deen]]></dc:creator>
            <pubDate>Tue, 13 Sep 2022 07:16:58 GMT</pubDate>
            <atom:updated>2022-09-13T12:49:18.448Z</atom:updated>
            <content:encoded><![CDATA[<p>This is the third article in a series focusing on trust in AI. In <a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-1-of-3-af28195b7612?source=friends_link&amp;sk=9122af2b26dcd4971bf514e89b374094">Part 1</a>, I addressed the question of why developing responsible and trustworthy AI is important. In <a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898?source=friends_link&amp;sk=8523ecb31d85109919c47287ccb021a4">Part 2</a>, I reviewed four key business scenarios that I have routinely encountered where I would often question how my AI solution is fostering trust and whether it is trustworthy. In this article, I review some basic statistical applications that can help data scientists build trust in their models:</p><ol><li>Using a confusion matrix to prioritize false positives or false negatives</li><li>Binning to make model results discrete</li><li>Measuring model drift</li><li>Other recommended Python packages</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ebwG1AzbsQP7rsUu" /><figcaption>Photo by <a href="https://unsplash.com/@araltasher?utm_source=medium&amp;utm_medium=referral">Aral Tasher</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><h3>Using a confusion matrix</h3><p>In this example, I simulate a binary class classification problem and model results for simplicity. I use the confusion matrix to inform model performance. The <a href="https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html"><em>sklearn.metrics</em></a> Python library has useful functions that can be called to measure performance. True Positive Rate (TPR<em>) </em>represents sensitivity: the fraction of true labels correctly identified, given a threshold. False Positive Rate (FPR) is 1–specificity: the fraction of true labels incorrectly identified. As a rule of thumb, use the target mean in the training set as the threshold value (cutoff) for classification.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d75c69f70aeddcd6158e2bbec42e9f7f/href">https://medium.com/media/d75c69f70aeddcd6158e2bbec42e9f7f/href</a></iframe><p>The code above generates the confusion matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*MU7lSIL0TBiKD-dAxj_AGA.jpeg" /><figcaption>Confusion matrix. Check out this <a href="https://medium.com/@dtuk81/confusion-matrix-visualization-fc31e3f30fea">article</a> for information on how to visualize a confusion matrix.</figcaption></figure><p>In the confusion matrix above, three of the 38 true labels are not identified, while 14 are incorrectly identified as true labels. The results suggest that this is a good model, with a TNR of 0.829, FPR of 0.171, and TPR of 0.921. When training your model you must ask the question, is it more costly for your business to get higher false positives or false negatives? Pick one and retune the model by adding more features, re-engineering features, or removing features that introduce high variance in the predicted probabilities.</p><h3>Binning</h3><p>In this example, I use the <a href="https://r-data.pmagunia.com/dataset/r-dataset-package-islr-default">default.csv</a> dataset for the binning exercise. This data is also used in <a href="https://www.statlearning.com/"><em>An Introduction to Statistical Learning with Applications in R</em></a>.</p><p>The threshold value is used to predict a classifier. An alternative is to use the <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.qcut.html">quantile-based discretization function</a>, if you work in a business that wants to make model results discrete such that scores are binned into score segments. The code below can help you make discrete results from a binary class classification and tweak threshold values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c973a9327db1f5ebab45780845b6aae/href">https://medium.com/media/8c973a9327db1f5ebab45780845b6aae/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*HCjv_t17XOoGMOi-HhZ2iw.jpeg" /><figcaption>Bins represent score segments.</figcaption></figure><p>Binning can help you identify the right threshold for either increasing or decreasing false positives. It also helps you get a better understanding of how many true labels will be missed based on your choice of threshold. In the example above, if you optimize for minimal false positives, only 34 percent of the target values will be captured with a higher lift of 1.6 above average.</p><pre>lift = (33/625)/cutoff</pre><p>However, if you want to capture or <em>recall </em>75 percent of the target values, you will do so at the expense of a lower lift, namely 1.2 above average.</p><pre>lift = ((33+18+21)/(625*3))/cutoff</pre><p>As a side note, this model has very low accuracy and results need to be improved by adding more explanatory variables, a different functional specification, or more data, among others.</p><h3>Dummy data for model drift</h3><p>I generated a dummy dataset to demonstrate model drift. This dataset has two features: A categorical feature, <em>Person</em>, and a numerical feature, <em>Blood Pressure</em>. I also created test data to introduce drift in the features. You can see the difference in the probability distribution between the <em>drift</em> and <em>no_drift</em> features.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bbf897ef5ccf4f4f264621297c518fb0/href">https://medium.com/media/bbf897ef5ccf4f4f264621297c518fb0/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*tz4yJGIGt2Um-rnvyZS5Tw.jpeg" /><figcaption>Visualizing natural drift.</figcaption></figure><p>A simple visualization (like the one above generated from the dummy data) can provide substantial evidence to support the presence of drift.</p><h3>Measuring model drift</h3><p>For numerical features, you can detect drift across the training and test data by performing the Kolmogorov-Smirnov test to determine whether they have similar distributions. If the p-value is less than 0.05, you can reject the hypothesis that the feature in the test and training data is from the same distribution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a81f6e573a0bdd8850849cb7c56b71d1/href">https://medium.com/media/a81f6e573a0bdd8850849cb7c56b71d1/href</a></iframe><p>The code below can help you detect drift in categorical features. You can use it to prioritize the top ten categorical features based on <a href="https://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html">feature importance</a>. As a rule of thumb, you can expect drift to have an impact on model performance if the difference in proportions across a category is greater than 5 percent. You can also run a <a href="https://www.statology.org/one-proportion-z-test-python/#:~:text=One%20Proportion%20Z-Test%20in%20Python.%20To%20perform%20a,number%20of%20successes%3B%20nobs%3A%20The%20number%20of%20trials">proportions test </a>to check whether the difference is statistically significant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25b30456375bc58ff6d7f146e63dff1c/href">https://medium.com/media/25b30456375bc58ff6d7f146e63dff1c/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ft9Uzh8b2FCuUoFiOAzMDg.jpeg" /><figcaption>The df_prop_test table can help identify natural drift in categorical features.</figcaption></figure><p>The table above shows how the proportions for a categorical feature have shifted such that there are new categories. In this type of situation, if this feature is an important categorical feature and is also representing a key demographic, then pay close attention to how the model performance changes with drift and whether any biases are entering the results.</p><h3>Other <em>Python</em> packages and libraries</h3><p>Beyond the basics, there are multiple libraries and packages that are dedicated to detecting drift and achieving greater accuracy, trust and interpretability. This list is not exhaustive, but is a great place to start:</p><ol><li><a href="https://www.microsoft.com/en-us/research/publication/interpretml-a-unified-framework-for-machine-learning-interpretability/">Interpret ML</a> + <a href="https://github.com/interpretml">Interpret ML GitHub</a></li><li><a href="https://github.com/interpretml/gam-changer">Gam-Changer</a></li><li><a href="https://docs.deepchecks.com/en/stable/checks_gallery/tabular/train_test_validation/plot_train_test_feature_drift.html">Deepchecks</a></li><li><a href="https://github.com/TorchDrift">Torchdrift</a></li><li><a href="https://pypi.org/project/alibi-detect/#:~:text=Alibi%20Detect%20is%20an%20open%20source%20Python%20library,and%20PyTorch%20backends%20are%20supported%20for%20drift%20detection.">Alibi-detect</a></li></ol><p><em>Samar Deen is on </em><a href="https://www.linkedin.com/in/samar-deen-phd-2064389/"><em>LinkedIn</em></a>.</p><h4>Be sure to check out the prior two articles in this series:</h4><ul><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-1-of-3-af28195b7612">Trust in AI versus trustworthy AI: Why is it important? (Part 1 of 3)</a></li><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898">Trust in AI versus trustworthy AI: Why is it important? (Part 2 of 3)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c9aef3cb2478" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-3-of-3-c9aef3cb2478">Trust in AI versus trustworthy AI: Why is it important? (Part 3 of 3)</a> was originally published in <a href="https://medium.com/data-science-at-microsoft">Data Science + AI at Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trust in AI versus trustworthy AI: Why is it important? (Part 2 of 3)]]></title>
            <link>https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898?source=rss-76c1e8243537------2</link>
            <guid isPermaLink="false">https://medium.com/p/77e5edebe898</guid>
            <category><![CDATA[precision]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[bias-in-ai]]></category>
            <category><![CDATA[recall]]></category>
            <category><![CDATA[model-predictive-control]]></category>
            <dc:creator><![CDATA[Samar Deen]]></dc:creator>
            <pubDate>Tue, 06 Sep 2022 07:16:02 GMT</pubDate>
            <atom:updated>2022-09-14T12:54:16.384Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jUH6FGCrg6FnAojr" /><figcaption>Photo by <a href="https://unsplash.com/@ivalex?utm_source=medium&amp;utm_medium=referral">Ivan Aleksic</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is the second article of a series focusing on trust in AI. In <a href="https://medium.com/data-science-at-microsoft/causal-inference-part-1-of-3-understanding-the-fundamentals-816f4723e54a?source=friends_link&amp;sk=47046a453bd0514b4627a40ee4f28118">Part 1</a>, I addressed the question of why developing responsible and trustworthy AI is important. I went over the current landscape of AI, especially as it pertains to ethical considerations, and why it is important to foster trust in your AI solution through greater accountability. I also reviewed challenges that data scientists at mid-sized companies experience when attempting to build trustworthy AI solutions.</p><p>In this article I review four key business scenarios that I have routinely encountered where I would often question how my AI solution is fostering trust and whether it is trustworthy. I introduce at a high level the simple statistical techniques that data scientists can use to achieve these goals. I contrast that with the business context within which data scientists develop solutions — essentially a sneak peek into a day in the life of data scientists and how they can deal with different aspects of trust and trustworthy AI.</p><p>The key takeaway is to embed the six AI principles of inclusiveness; accountability; fairness; transparency; privacy and security; and reliability and safety within the data science lifecycle through the application of simple statistics. In other words, start simple and cover the basics if you want to build trust in your AI solution.</p><h3><strong>Business scenarios</strong></h3><h4><strong><em>Foster Trust in AI: The model works — but do people and processes adopt it?</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PoUQa_A3yrEgJRl3oxQ0_Q.jpeg" /></figure><p>The figure above represents typical conversations I have had with stakeholders. Both stakeholders, the executive and the client, are speaking a different language. As a result, expectations are often misaligned and so the best way to move forward is to improve those gaps in perception.</p><p>Re-evaluate (if you haven’t done so already) what the executive or the field seller cares about more: false positives or false negatives? If there is a heavy loss in revenue from false negatives — that is, Type II errors — then you may want to adopt strategies to minimize these Type II errors. As shown in the figure above, Type II errors can discredit the effort of data scientists even though they may have statistically proven the model’s recall. If Type II errors are important, then there are approaches for addressing them:</p><ol><li>Optimize the algorithm to satisfy the recall, given that recall is simply the complement of the type II error rate, i.e., <em>1 </em>–<em> Type II error rate</em>.</li><li>For classification problems, adjust the threshold to minimize the false negative rate. Setting higher thresholds will minimize the Type II error, but also has implications for the Type I error, which will increase. The data scientist should assess the impact that Type I and Type II errors have on their decision boundary and communicate the implications to the client.</li></ol><h4><strong><em>Should I prioritize recall or precision?</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*LN6EAk6J61A2JXq_-hj4VA.jpeg" /></figure><p>Precision and recall are commonly used metrics in classification settings. A best practice is for algorithms to be optimized for one metric, while the remaining can be a “satisfying metric.” Recall is the percentage of actual positive labels correctly identified by the model, and precision is the percentage of correct positive predictions. For more information on recall and precision, see the article, “How to calculate precision, recall, F-measure for imbalance classification.”¹</p><p>Let’s say the confusion matrix above shows the results of a classification model. You can choose any metric — but business objectives must guide the choice of metric, precision, or recall. This case is tricky because there is an imbalanced class. There are only eight true labels out of a total of 2,050. If the business wants to ensure that false negatives are minimized, it’s best to retune the model for recall. If you tune the model to optimize recall, you can use score ranking and quantile ranking techniques to improve precision for the highest quantile. If the cost of false positives is high for the business, then tune the model for precision to increase the percentage of positive cases accurately predicted.</p><p>When presenting the model results, benchmark them in comparison to model performance in industry. This is more to level set expectations. To represent the results of a random forest model, for example, choose a comparative model performance approach, where the upper bound is an industry standard, and the lower bound is either a standard model or the performance in the case of a random draw. This graphic shows how to manage expectations on model performance while prompting stakeholders to move away from a “100 percent accuracy” expectation.</p><h4><strong><em>Determine drift: The model worked and then something changed</em></strong></h4><p>Over time models degrade. Data drift often occurs when a model’s feature distributions change or the outcome variable’s distribution changes. These distribution changes can occur due to many reasons.</p><ol><li><strong><em>Drift due to feature engineering</em></strong> occurs when the logic used to create a feature across training and validation changes during the process of moving a model into production. It can also occur if there is a code upgrade in an upstream process.</li><li><strong><em>Natural drift or data drift</em></strong> occurs when a feature distribution changes over time, i.e., a change in the statistical properties of the features. For example, suppose the customer profile changes due to an exogenous shock, and the age profile changes from ages 16–24 to ages 24–50, a profile that the model has not been trained on.</li><li><strong><em>Covariate drift or concept drift</em></strong> occurs when there is a change in the relationship between the features of a model and the outcome the model is trying to predict. For example, during training X and Y have a linear relationship, but after collecting more data post-deployment the relationship turns out to be nonlinear. To mitigate this bias the model would need to be retrained to account for the new relationship.</li></ol><p>Knowing the different types of drift is important because drift reduces model accuracy, which in turn leads to biased predictions. Data scientists should regularly monitor feature distribution, model performance for drift, set thresholds, and trigger alerts highlighting the root cause of the drift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIiUxH0HNDwXfFBFPy2GSQ.jpeg" /></figure><p>The figure above illustrates a nonstationary environment where a model is built and deployed such that its predictions are unbiased. A sudden or gradual change in important feature distributions may go unnoticed, resulting in biased predictions. For example, drift had a significant impact on the performance of some models during the 2020 Covid-19 epidemic. Online consumer behaviors shifted significantly, resulting in both covariate and natural drift. To get an overview of the different types of drift, read the following article, “Drift in Machine Learning.”²</p><p>Drift can be detected by using the Kolmogorov-Smirnov (K-S) test³, a non-parametric test of the distribution of an observed random variable <em>G(X)</em> against a given distribution <em>F(X)</em>.</p><p>Another metric is the Population Stability Index (such as the Kullback-Leibler or Jensen-Shannon divergence between two distributions), which quantifies the shift in feature distribution over time by comparing model output with the predicted probability from the training data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*XWqokDzWhMATd4WNtvhJ-w.jpeg" /></figure><p>where <em>B</em> is the total number of bins, <em>A</em> is the proportion of counts within bin <em>b</em> from the target distribution and <em>E</em> is the proportion of counts within bin <em>b</em> from the reference distribution.⁴</p><p>The proportions <em>z</em>-test is also often used to determine differences across two populations (training and live data), where the hypothesis is that the two are equal. The <em>z</em> statistic is denoted by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*pl-mVK4KHcRV3RZHJNjIpQ.jpeg" /></figure><p>Where <em>p</em>1 and <em>p</em>2 are sample proportions and <em>n</em>1 and <em>n</em>2 are the sample sizes.</p><h4><strong><em>Determine drift: The model works for the data — but not for the business</em></strong></h4><p>It is well known that about 80 to 90 percent of models never make it to production. Companies continue to face challenges in their attempts to derive value from their investments in big data, Machine Learning, and Artificial Intelligence. The main challenge to successful business adoption does not come from limitations and obstacles in technology, but rather from people and processes.⁵ Failure in communication and an inability to meet business needs could possibly be one of the top five reasons. Another important factor is that Machine Learning models are highly dependent on data quality. The fanciest Deep Learning neural network will fail if it is fed low-quality data. Data quality problems include incorrect metrics, unrepresentative samples, class imbalances, and poor outlier handling.⁶ Intermediate economics teaches about the omitted variable bias and instrumental variables. Key assumptions are made when identifying proxies for missing features. Building models that predict business outcomes based on incomplete data, misidentified proxies, or biased data invariably produces biased results, especially when a concerted effort (and by that, I mean using valid statistical techniques or human intervention) is not taken to address these inherent biases, or if model results are not monitored for biases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ig9h7ZfrH0u3IugvbYflww.jpeg" /></figure><p>The figure above illustrates a common situation, where the training and live data differ. In this case the model was trained using a particular demographic and when it went into production certain groups were overrepresented while others were underrepresented. Even the most sophisticated data lakes can have unrepresentative samples and class imbalances. Going by the approaches better known as “the 80/20 rule,” “minimum viable product,” or “a model in production is better than none,” data scientists may rush into building Machine Learning solutions on biased datasets. On some occasions they may not have complete insight into the actual population for which the model will be deployed (for example, training the model on data that is restricted to a particular geographic region). When there is a disparity in the populations in the training data and the live data, biased predictions occur, such as shown with the Optum algorithm. One way to avoid extended damage from such a state is to continually monitor the results and performance of the model. Measure the differential effects across subpopulations, especially if they have serious implications on patient well-being, the bottom line, or reputational consequences. If the live data represents itself significantly different from the modeling data, retrain the model.</p><h3><strong><em>Embedding trusted AI concepts within the data science lifecycle</em></strong></h3><p>The table below highlights key questions and actions that you can take as you build out your solution. This will help you build the foundations of a model that is trustworthy and produce results that the business can trust.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LaNBkNjV7vB2EcdKfxbT4Q.jpeg" /></figure><p>You foster trust in your model when your stakeholders understand the objective of the model and its limitations. You foster trust when stakeholders understand what the model can predict and what the model’s expected accuracy is. You build a trustworthy solution when you have addressed known biases and continue to dynamically address biases that may creep in over time. <a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-3-of-3-c9aef3cb2478?source=friends_link&amp;sk=43a69dde175abc697dcca7411b243394">Part 3</a> of this three-part article series delves deeper into the specific metrics and methods mentioned in this article leveraging Python libraries such as <em>scipy.stats</em> and <em>statsmodels</em>.</p><p><em>Samar Deen is on </em><a href="https://www.linkedin.com/in/samar-deen-phd-2064389/"><em>LinkedIn</em></a>.</p><ul><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-3-of-3-c9aef3cb2478">Trust in AI versus trustworthy AI: Why is it important? (Part 3 of 3)</a></li><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-1-of-3-af28195b7612">Trust in AI versus trustworthy AI: Why is it important? (Part 1 of 3)</a></li></ul><h3>Sources</h3><p>¹ Brownlee, Jason 2020. <a href="https://machinelearningmastery.com/precision-recall-and-f-measure-for-imbalanced-classification/#:~:text=We%20can%20calculate%20the%20precision%20as%20follows%3A%201,%2F%20%2895%20%2B%2055%29%203%20Precision%20%3D%200.633">How to Calculate Precision, Recall, and F-Measure for Imbalanced Classification (machinelearningmastery.com)</a></p><p>² <a href="https://medium.com/@piotrm_69949?source=post_page-----e49df46803a--------------------------------">Mardziel</a>, Peter. 2021. Drift in Machine Learning. Why is it hard and what to do about it. <a href="https://towardsdatascience.com/drift-in-machine-learning-e49df46803a">Drift in Machine Learning. Why is it hard and what to do about it? | by Piotr (Peter) Mardziel | Towards Data Science</a></p><p>³Kolmogorov–Smirnov test. <em>Encyclopedia of Mathematics.</em> URL: <a href="http://encyclopediaofmath.org/index.php?title=Kolmogorov%E2%80%93Smirnov_test&amp;oldid=22660">http://encyclopediaofmath.org/index.php?title=Kolmogorov%E2%80%93Smirnov_test&amp;oldid=22660</a></p><p>⁴Shergadwala, Murtuza. 2022. Measuring data Drift: Population Stability Index. <a href="https://www.fiddler.ai/blog/measuring-data-drift-population-stability-index">Measuring Data Drift: Population Stability Index | Fiddler AI Blog</a></p><p>⁵R. Bean and T.H. Davenport, “<a href="https://hbr.org/2019/02/companies-are-failing-in-their-efforts-to-become-data-driven">Companies Are Failing in Their Efforts to Become Data-Driven</a>,” Harvard Business Review, Feb. 5, 2019, <a href="https://hbr.org./">https://hbr.org.</a></p><p>⁶<a href="https://towardsdatascience.com/9-reasons-why-machine-learning-models-not-perform-well-in-production-4497d3e3e7a5">Kumar, Satya. 2020. </a>9 Reasons why Machine Learning models not perform well in production. <a href="https://towardsdatascience.com/9-reasons-why-machine-learning-models-not-perform-well-in-production-4497d3e3e7a5">Reasons why Machine Learning models not perform well in production | by Satyam Kumar | Towards Data Science</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77e5edebe898" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898">Trust in AI versus trustworthy AI: Why is it important? (Part 2 of 3)</a> was originally published in <a href="https://medium.com/data-science-at-microsoft">Data Science + AI at Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Trust in AI versus trustworthy AI: Why is it important? (Part 1 of 3)]]></title>
            <link>https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-1-of-3-af28195b7612?source=rss-76c1e8243537------2</link>
            <guid isPermaLink="false">https://medium.com/p/af28195b7612</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[model-accuracy]]></category>
            <category><![CDATA[false-positive]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Samar Deen]]></dc:creator>
            <pubDate>Tue, 30 Aug 2022 07:18:03 GMT</pubDate>
            <atom:updated>2022-09-13T16:32:36.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OLqwGHxjLQYEjvbk" /><figcaption>Photo by <a href="https://unsplash.com/@mangofantasy?utm_source=medium&amp;utm_medium=referral">Tim Johnson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>.</figcaption></figure><p>Why is it relevant to understand the difference between trust in AI and developing responsible or trustworthy AI? How can understanding this difference help a data scientist build trustworthy AI solutions? What are some basic statistics that a data scientist can use to help address these two questions? In this article, the first of a three-part series, I discuss the difference between <em>trust in AI</em> versus <em>building trusted AI solutions</em> in answering these questions.</p><p>Whether we’re discussing responsible AI, trustworthy AI, trusted AI, explainable AI, ethical AI — or any combination of them — they all encompass the field of artificial intelligence (AI), which is guided by six key principles.¹ These include:</p><ol><li><strong>Inclusiveness:</strong> AI should be a true representation of the population such that specific demographics are not erroneously excluded.</li><li><strong>Accountability:</strong> The organization that designs and deploys the AI solution should be accountable for its predictions and recommendations.</li><li><strong>Fairness:</strong> AI solutions should undergo a rigorous vetting process to ensure that no demographic is unjustly empowered at the expense of others. Tradeoffs should be made between expected benefits and mitigation of expected harm.</li><li><strong>Transparency:</strong> The data and algorithms that are used to build the AI solution should be available to stakeholders. To trust an AI solution, end users need to understand it.</li><li><strong>Privacy and security:</strong> The organization owning the AI solution and the underlying end user data should have protections in place such that data privacy practices and data security are not violated.</li><li><strong>Reliability and safety:</strong> An AI solution’s performance should be benchmarked against its performance during training. AI solutions must only be deployed after rigorous stress testing and validation on all known and potential edge cases.</li></ol><p>Ethics and the discourse on morality is relevant for every field, and in the case of machine ethics dates to Isaac Asimov’s <a href="https://en.wikipedia.org/wiki/I%2C_Robot"><em>I, Robot</em></a> (circa 1942) where he introduces three laws of robotics to govern artificially intelligent, “sentient” systems. He later introduced a zeroth law.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gpFEPUjj3dCq_yfapzJxNw.png" /><figcaption>Source: Asimov, Isaac (1950). “Runaround”. <em>I, Robot</em> (The Isaac Asimov Collection ed.). New York City: Doubleday. <a href="https://en.wikipedia.org/wiki/ISBN_(identifier)">ISBN</a> <a href="https://en.wikipedia.org/wiki/Special:BookSources/978-0-385-42304-5%22%20/o%20%22Special:BookSources/978-0-385-42304-5">978–0–385–42304–5</a>.</figcaption></figure><p>As a die-hard fan of the Isaac Asimov science fiction series and as a data scientist I view these principles as lofty ideals that have profound relevance in my profession. Specifically, the zeroth law, “A robot may not harm humanity, or by inaction, allow humanity to come to harm,” which explicitly focuses on harm to humanity. I think it is a missed opportunity to have AI ethics relegated to an ethics group or a tool that needs to be purchased. Instead, trustworthy AI should be a guiding principle for all data scientists, explicitly embedded in the data science life cycle. This is particularly relevant in the current state of big data where ubiquitous use cases exist. AI systems are embedded in the products we use (such as Office 365, Google search, and social media platforms based on recommender systems), services we interact with (such as chat bots and online help desks), and help business make smarter decisions with speed, accuracy, and efficiency.</p><p>In this article I unpack why it is important to foster trust in AI and develop responsible and trustworthy AI, and how a data scientist in a medium- to small-sized company with limited resources can build trusted and trustworthy AI solutions. I begin with an introduction to the current landscape of AI with respect to trust, going over concepts such as the importance of fostering trust in AI solutions, the presence of escalating ethical considerations, and how working for a small data science team means that each data scientist is accountable for the results of their AI solution.</p><h3><strong><em>Fostering trust in your AI solution through greater accountability</em></strong></h3><p>As data scientists and ML and data engineers, we build AI solutions. Subsequently it is our responsibility to foster trust in these AI solutions. There are considerable misconceptions about AI as “the magic wand” that replaces human decision-making with 100 percent accuracy. This holds true for business executives and other non-technical professionals. In this regard, data scientists need to set expectations, rethink how to communicate model performance, and benchmark results presented to stakeholders. As counterintuitive as it may sound, most non-technical audiences, clients, and end users do not understand the business implications of a 95 percent confidence interval, 80 percent accuracy, the ROC, the null hypothesis, a z-score, or a statistically significant p-value that is less than 0.05. Providing these statistics is not sufficient for gaining trust.</p><h3><strong><em>Escalating ethical considerations</em></strong></h3><p>Inclusive AI is expected to account for differences across races, disabilities, or other backgrounds. Numerous articles have been published emphasizing the importance of ethical AI, especially ethics as they pertain to medical AI.² A recent article published in <em>Science</em> magazine critiqued an AI capability developed by Optum that identified “high risk” patients requiring follow-up health care. The AI solution had predicted health risk status for at least 100 million patients. This solution made headlines because it had misidentified (via false negatives) Black patients. Among Black patients, 18 percent were identified as “high risk.” The research identified that an additional 28 percent of Black patients should have received health care. The results were biased in favor of their non-Black counterparts because health care costs incurred by patients were chosen as a proxy for health. The Optum case is a glaring example of how inequality can be perpetuated through the unintended consequence of a biased AI system.³ A relevant question that data scientists must address is, “When is it OK to produce differential effects across subpopulations, and when is it an affront to equality?” The answers vary and cannot be found by adjusting AI algorithms.⁴</p><p>Additionally, other AI systems, such as self-driving autonomous cars, can also produce erroneous results with life-threatening consequences. Social media feeds have been known to destabilize governing institutions. Erroneous AI predictions have also been known to damage companies’ reputations, while others have resulted in legal and financial costs. As a result, AI solutions are under strict scrutiny. A relevant question to ask is whether there is a statistical boundary beyond which autonomous AI must be overridden by human intervention.</p><h3><strong><em>Where is the intelligence in AI, or shall I say, who is the intelligence in AI?</em></strong></h3><p>A social media influencer once approached me at a corporate event for an interview about my thoughts on AI and a particular AI product. I responded in a nonchalant, dry tone, “Oh, it’s just a bunch of scientists using real-world data to build algorithms to in turn predict the real world.” The corporate media team immediately did some damage control and scrubbed away my interview. I was totally onboard. That was not the response that the enthused starry-eyed influencer wanted. Even the realist in me felt crushed about disappointing her. More importantly that is not the perception that businesses or media want to relay. AI is advertised more as the “robotic being,” the “autonomous decision-maker” that adheres to the philosophical laws proposed by Asimov.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*EzmvSLmf5bIypSSiFHCA7Q.png" /></figure><p>In a similar vein, the “AI issue” of <em>Cosmopolitan</em> (June 2022), caused quite a controversy among LinkedIn AI influencers. Some of the more technically inclined pushed back on the celebration of AI. The argument was that this cover was ultimately chosen by a human after numerous iterations of the algorithm and that too much emphasis was being given to AI as a “robotic being.”</p><h3><strong><em>The “don’t leave any dollars on the table” mentality</em></strong></h3><p>Businesses expect an AI solution to minimize <a href="https://en.wikipedia.org/wiki/Type_I_and_type_II_errors%22%20/l%20%22Type_I_error">Type I</a> errors and eliminate <a href="https://en.wikipedia.org/wiki/Type_I_and_type_II_errors%22%20/l%20%22Type_II_error">Type II</a> errors. From a statistical perspective that is not possible. There is a tradeoff between the two; Type I error affects statistical power, which is inversely related to Type II error. During a recession or corporate downturn, there is immense pressure on analytical teams to build solutions that “leave no money on the table” and simultaneously perform at minimum cost. But let’s get real: AI is not a magic wand, and these are unrealistic expectations for an AI solution. As a data scientist, you should feel empowered to push back and level set on expectations.</p><h3><strong><em>Working in “AI unicorns” on a specialized data science team versus working for small non-specialized data science teams</em></strong></h3><p>I attended a talk by Micheal Li, from the Data Incubator where he described what AI at specific companies looked like. He described these companies as “AI unicorns.” <em>When we think about all that AI can achieve, we think about self-driving cars, smart home devices, personalized movie recommendations, assistance programs, and beating world class human players at chess. This is what AI at the unicorns looks like.</em> AI teams in companies such as Google, Facebook, Netflix, Microsoft, and more have the capacity and analytical maturity to produce products that describe the past, explain the past, predict the future and finally influence the future. The more that businesses want to mature and scale their AI solutions, the more they specialize. At AI unicorns, the “business and product teams” consist of software engineers, business analysts, technical program managers, product managers, and executives. The “data insights” teams consist of research scientists, quantitative analysts, data scientists, and ML scientists. The “data product” teams consist of data visualization engineers, analytics engineers, data engineers, and algorithm engineers. Within this hierarchy of dedicated experts, data “producers” are tasked with building an asset that is used to deliver an insight to the business, and the output of the insight is used to make informed business decisions or create business products.</p><p>Monitoring model performance, drift, and bias detection can be automated and baked into development life cycles. And each team can (in theory) play their part in ensuring that AI adheres to the six trust principles. Most medium- to small-size organizations have a handful of data scientists who run end-to-end AI solutions. These teams may not have access to technical human resources, or tools such as the AI 360 toolkit or Azure Machine Learning drift detection tools, to help them achieve these goals. It leaves the onus on the data scientist to do the necessary validations for model bias and routinely monitor drift.</p><p>On the bright side, data scientists encounter many situations where they can use simple analytics and statistics to achieve these sorts of objectives. In <a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898?source=friends_link&amp;sk=8523ecb31d85109919c47287ccb021a4">Part 2</a> of this three-part article series, I go over three key business scenarios that I repeatedly have dealt with in my AI work. I also provide a high-level introduction to the statistics I have used to address trust in my models.</p><p><em>Samar Deen is on </em><a href="https://www.linkedin.com/in/samar-deen-phd-2064389/"><em>LinkedIn</em></a>.</p><ul><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-2-of-3-77e5edebe898">Trust in AI versus trustworthy AI: Why is it important? (Part 2 of 3)</a></li><li><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-3-of-3-c9aef3cb2478">Trust in AI versus trustworthy AI: Why is it important? (Part 3 of 3)</a></li></ul><h3>Sources</h3><p>¹ Steller, Moritz., Buck, Alex., Thomas, Janet., and S.J., Liliane. 2021. Responsible and Trusted AI. Microsoft Cloud Adoption Framework. <a href="https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/innovate/best-practices/trusted-ai">Responsible and trusted AI — Cloud Adoption Framework | Microsoft Docs</a></p><p>² Blackman, Reid. 2022. “Why You Need an AI Ethics Committee.” <em>Harvard Business Review</em>; Longoni, C., Cadario, R., Morewedge, C.K. 2021. “For Patients to Trust Medical AI, They Need to Understand It”. <a href="https://hbr.org/2021/09/for-patients-to-trust-medical-ai-they-need-to-understand-it">For Patients to Trust Medical AI, They Need to Understand It (hbr.org)</a></p><p>³ Obermeyer, O., Powers B., Vogel, C., and Mullainathan, S. 2019. “Dissecting racial bias in an algorithm used to manage the health of populations.” <em>Science</em>, 366:6464 pp. 447–453. <a href="https://doi.org/10.1126/science.aax2342">DOI:10.1126/science.aax2342</a>.</p><p>⁴ Blackman, Reid 2022. “Why You Need an AI Ethics Committee.” <em>Harvard Business Review</em>. <a href="https://hbsp.harvard.edu/product/R2204J-PDF-ENG">Why You Need an AI Ethics Committee | Harvard Business Publishing Education</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af28195b7612" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science-at-microsoft/trust-in-ai-versus-trustworthy-ai-why-is-it-important-part-1-of-3-af28195b7612">Trust in AI versus trustworthy AI: Why is it important? (Part 1 of 3)</a> was originally published in <a href="https://medium.com/data-science-at-microsoft">Data Science + AI at Microsoft</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>