{"id":123,"date":"2024-08-02T16:23:00","date_gmt":"2024-08-02T16:23:00","guid":{"rendered":"https:\/\/amirhooshang.com\/blog\/?p=123"},"modified":"2025-05-19T16:28:23","modified_gmt":"2025-05-19T16:28:23","slug":"machine-learning-metrics-in-federated-learning-from-theory-to-practice","status":"publish","type":"post","link":"https:\/\/amirhooshang.com\/blog\/2024\/08\/02\/machine-learning-metrics-in-federated-learning-from-theory-to-practice\/","title":{"rendered":"Machine Learning Metrics in Federated Learning: From Theory to Practice"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction: What Is Federated Learning and Why Does It Matter?<\/h2>\n\n\n\n<p>Imagine training an AI model to diagnose diseases, but patient data is scattered across hospitals, and no one wants to share raw data! This is where <strong>Federated Learning (FL)<\/strong> shines\u2014it\u2019s like a tutor who visits each student individually, teaches them, and then combines their progress <em>without ever seeing their homework<\/em>.<br>FL is used in healthcare, finance, and even your phone\u2019s keyboard (like Gboard\u2019s next-word prediction). But here\u2019s the big question: <em>How do we evaluate a model\u2019s performance when we can\u2019t access raw data?<\/em> That\u2019s where <strong>evaluation metrics<\/strong> come into play.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Evaluation Metrics: What to Measure and Why?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Functional Metrics: Accuracy, Precision, Recall, and More<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Accuracy: It\u2019s Not Always Honest!<\/strong><\/h4>\n\n\n\n<p>Suppose you build an AI model to detect skin cancer from images. If it\u2019s trained mostly on light-skinned patients, it might fail miserably for darker skin tones! High <strong>accuracy<\/strong> here could be misleading. In FL, especially with <strong>non-IID data<\/strong> (e.g., different devices have different data), local accuracy per user matters just as much as global accuracy.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Precision &amp; Recall: The Guardian Angels<\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Precision:<\/strong> Think of a bank\u2019s fraud detection system. You want every flagged transaction to <em>actually<\/em> be fraud. Fewer false alarms!<\/li>\n\n\n\n<li><strong>Recall:<\/strong> Here, catching <em>all<\/em> fraud cases is critical\u2014even if it means occasionally investigating innocent transactions.<\/li>\n<\/ul>\n\n\n\n<p>For example, in banking, <strong>high recall<\/strong> is better because missing fraud is costlier than a few false alerts.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>F1 Score: The Balance Champion<\/strong><\/h4>\n\n\n\n<p>Imagine juggling\u2014you need power <em>and<\/em> control. The <strong>F1 Score<\/strong> balances precision and recall using their harmonic mean. It\u2019s perfect for imbalanced data (e.g., 90% healthy vs. 10% diseased samples).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Mean Squared Error (MSE): How Serious Are Your Mistakes?<\/strong><\/h4>\n\n\n\n<p>If your model predicts house prices and messes up by $100K in one area and $50K in another, MSE squares these errors and averages them. Bigger mistakes get punished harder!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Communication Metrics: Weak Wi-Fi? Big Problem!<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Communication Rounds: How Often Do You Chat?<\/strong><\/h4>\n\n\n\n<p>FL is like a group chat. More rounds mean higher internet costs and battery drain. For a mobile app, forcing users to update the model 10 times a day is annoying. Reducing rounds is key\u2014but don\u2019t sacrifice model convergence.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Bandwidth: Compress Models Like Zipping Files!<\/strong><\/h4>\n\n\n\n<p>Trying to upload a 1GB video on slow internet? You\u2019d compress it! In FL, techniques like <strong>parameter quantization<\/strong> or <strong>partial model updates<\/strong> shrink data size.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Privacy &amp; Fairness: Security and Equity<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Fairness: Equal Love for All Clients!<\/strong><\/h4>\n\n\n\n<p>Imagine two clients: one with 1,000 images and another with 10. If the model trains only on the larger client\u2019s data, it\u2019ll perform poorly for the smaller one. Metrics like <strong>average user accuracy<\/strong> or <strong>accuracy disparity<\/strong> ensure the model treats everyone fairly.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Differential Privacy (DP): Add Noise, Protect Secrets!<\/strong><\/h4>\n\n\n\n<p>It\u2019s like saying, \u201cI earn between $50K and $100K\u201d at a party instead of revealing your exact salary. In FL, adding <strong>random noise<\/strong> to model updates protects user privacy. The <strong>\u03b5 (epsilon)<\/strong> metric quantifies privacy strength: smaller \u03b5 = stronger privacy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Scalability &amp; Fault Tolerance: Handling Chaos<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Client Participation: Can Everyone Join the Party?<\/strong><\/h4>\n\n\n\n<p>In an FL system with 1,000 devices, only 100 might be active. The algorithm must work even with limited participation.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Fault Tolerance: Don\u2019t Let One Bad Device Crash the System!<\/strong><\/h4>\n\n\n\n<p>Like a group project where one member ghosts, FL systems should keep training even if 30% of devices drop out.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Combining Metrics: Which Ones Matter When?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scenario 1: Non-IID Medical Data<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Example:<\/strong> Hospital A has mostly cancer images; Hospital B has healthy ones.<\/li>\n\n\n\n<li><strong>Metrics Combo:<\/strong><\/li>\n\n\n\n<li><strong>Personalized Accuracy:<\/strong> Let each hospital fine-tune its own model.<\/li>\n\n\n\n<li><strong>Fairness:<\/strong> Ensure no hospital gets worse performance.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scenario 2: Rural Areas with Poor Internet<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Example:<\/strong> IoT devices on a farm with slow connectivity.<\/li>\n\n\n\n<li><strong>Metrics Combo:<\/strong><\/li>\n\n\n\n<li><strong>Reduce Communication Rounds:<\/strong> Update weekly, not daily.<\/li>\n\n\n\n<li><strong>Bandwidth Optimization:<\/strong> Send only 10% of critical parameters.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scenario 3: Top-Secret Banking Data<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Example:<\/strong> Customer transaction histories.<\/li>\n\n\n\n<li><strong>Metrics Combo:<\/strong><\/li>\n\n\n\n<li><strong>Differential Privacy (\u03b5=0.5):<\/strong> Strong noise for maximum security.<\/li>\n\n\n\n<li><strong>High Recall:<\/strong> Catch 95% of fraud, even with some false alarms.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion: It\u2019s a Team Game\u2014Balance Everything!<\/h2>\n\n\n\n<p>Federated Learning is a trade-off game: you want accuracy <em>and<\/em> privacy, speed <em>and<\/em> low resource use. Your metric mix depends on your goal:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prioritize <strong>\u03b5<\/strong> and <strong>recall<\/strong> for privacy-critical tasks.<\/li>\n\n\n\n<li>Focus on <strong>fairness<\/strong> and <strong>personalized accuracy<\/strong> for non-IID data.<\/li>\n\n\n\n<li>Optimize <strong>bandwidth<\/strong> and <strong>fault tolerance<\/strong> in resource-limited setups.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: What Is Federated Learning and Why Does It Matter? Imagine training an AI model to diagnose diseases, but patient data is scattered across hospitals, and no one wants to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":124,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61,62],"tags":[142,144,139,113,145,143,138,98,140,141],"class_list":["post-123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","category-model-evaluation","tag-bandwidth-optimization","tag-communication-rounds","tag-differential-privacy","tag-f1-score-2","tag-fault-tolerance","tag-federated-averaging-fedavg","tag-federated-learning","tag-machine-learning-metrics","tag-model-fairness","tag-non-iid-data"],"_links":{"self":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":1,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":125,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions\/125"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/media\/124"}],"wp:attachment":[{"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amirhooshang.com\/blog\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}