<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Purity Ngugi</title>
    <description>The latest articles on DEV Community by Purity Ngugi (@purityngugi).</description>
    <link>https://dev.to/purityngugi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3255182%2Fabc72fbc-bc44-40ff-8772-2902ea4d4dd3.jpg</url>
      <title>DEV Community: Purity Ngugi</title>
      <link>https://dev.to/purityngugi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/purityngugi"/>
    <language>en</language>
    <item>
      <title>🎯Balancing Type I and Type II Errors in Medical Decision-Making: A Case on Diabetes Diagnosis</title>
      <dc:creator>Purity Ngugi</dc:creator>
      <pubDate>Sun, 21 Sep 2025 21:06:06 +0000</pubDate>
      <link>https://dev.to/purityngugi/balancing-type-i-and-type-ii-errors-in-medical-decision-making-a-case-on-diabetes-diagnosis-4jp2</link>
      <guid>https://dev.to/purityngugi/balancing-type-i-and-type-ii-errors-in-medical-decision-making-a-case-on-diabetes-diagnosis-4jp2</guid>
      <description>&lt;p&gt;In statistics, Type I and Type II errors are inevitable risks when making decisions based on sample data. Understanding how to balance these errors is crucial, especially in the medical field, where the consequences directly affect human lives. Let’s explore how this trade-off works using a diabetes diagnosis as our scenario.&lt;/p&gt;

&lt;h4&gt;
  
  
  Understanding the Two Types of Errors
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type I Error&lt;/strong&gt; (False Positive): Rejecting the null hypothesis when it is actually true.&lt;br&gt;
Example in medicine: Diagnosing a patient with diabetes when they are actually healthy.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type II Error&lt;/strong&gt; (False Negative): Failing to reject the null hypothesis when it is false.&lt;br&gt;
Example in medicine: Declaring a patient healthy when they actually have diabetes.&lt;br&gt;
Both errors have costs, but the severity depends on the context.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  🩺Case Study: Diagnosing Diabetes
&lt;/h4&gt;

&lt;p&gt;Let’s say a hospital is screening patients for diabetes. The null hypothesis (H₀) is “The patient does not have diabetes.” The alternative hypothesis (H₁) is “The patient has diabetes.”&lt;/p&gt;

&lt;p&gt;The choice between minimizing Type I or Type II errors depends on the medical and ethical priorities of the healthcare institution.&lt;/p&gt;

&lt;h4&gt;
  
  
  Consequences of Each Error
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type I Error&lt;/strong&gt; – False Positive&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If a healthy person is incorrectly diagnosed with diabetes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They may undergo unnecessary lifestyle changes or medication.&lt;/li&gt;
&lt;li&gt;They may face psychological stress and anxiety.&lt;/li&gt;
&lt;li&gt;They might experience side effects from treatments they don’t actually need.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While inconvenient and potentially harmful, a false positive in this case usually does not cause immediate life-threatening harm—especially if further confirmatory tests are done.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Type II Error&lt;/strong&gt; – False Negative&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If a patient with diabetes is told they are healthy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Their condition will go untreated, potentially leading to severe complications such as kidney failure, nerve damage, or blindness.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The disease may progress silently, increasing the risk of life-threatening outcomes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The opportunity for early intervention is lost.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The consequences here are far more severe than in a false positive scenario.&lt;/p&gt;

&lt;h4&gt;
  
  
  📊 The Trade-Off Decision
&lt;/h4&gt;

&lt;p&gt;In the diabetes diagnosis context, minimizing &lt;strong&gt;Type II errors&lt;/strong&gt; is more critical. Missing a true case of diabetes (false negative) can have long-term, irreversible health consequences. Therefore, hospitals may set a lower threshold for diagnosing diabetes, accepting that there might be more false positives, but ensuring fewer false negatives.&lt;br&gt;
This approach aligns with the principle:&lt;br&gt;
“It is better to mistakenly treat a healthy patient than to miss treating a sick patient.”&lt;/p&gt;

&lt;h4&gt;
  
  
  Visualizing the Trade-off with Python
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import matplotlib.pyplot as plt

# significance levels (alpha values)
alpha = np.linspace(0.01, 0.2, 50)

# Type I error increases with alpha
type1_error = alpha  

# Type II error decreases with alpha (inverse relationship for illustration)
type2_error = 1 - alpha * 3  
type2_error = np.clip(type2_error, 0, 1)  # keep within [0,1]

plt.figure(figsize=(8,5))
plt.plot(alpha, type1_error, label="Type I Error (False Positive)", linewidth=2)
plt.plot(alpha, type2_error, label="Type II Error (False Negative)", linewidth=2)

plt.title("Trade-off Between Type I and Type II Errors in Diabetes Diagnosis")
plt.xlabel("Significance Level (α)")
plt.ylabel("Error Rate")
plt.legend()
plt.grid(True)
plt.show()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Statistical Implications
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reducing Type II errors increases the power of the test (the probability of correctly detecting a true condition).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This often comes at the cost of increasing Type I errors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The balance is determined by setting the significance level (α). A higher α (e.g., 0.10 instead of 0.05) allows for more false positives but reduces false negatives.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;In medicine, the trade-off between Type I and Type II errors is not purely a statistical decision—it is an ethical one. For conditions like diabetes, where missing a diagnosis could have life-altering consequences, it is often preferable to tolerate a slightly higher false positive rate to ensure that true cases are caught and treated promptly.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Analyzing Win Probabilities in the Premier League 2024/25 with Python🐍</title>
      <dc:creator>Purity Ngugi</dc:creator>
      <pubDate>Fri, 29 Aug 2025 12:02:49 +0000</pubDate>
      <link>https://dev.to/purityngugi/analyzing-win-probabilities-in-the-premier-league-202425-with-python-2omj</link>
      <guid>https://dev.to/purityngugi/analyzing-win-probabilities-in-the-premier-league-202425-with-python-2omj</guid>
      <description>&lt;p&gt;In this project, I explored the 2024/2025 Premier League by digging into match outcomes and calculating the win probabilities of different teams. Instead of just looking at the league table, I wanted to understand how often teams actually win compared to drawing or losing, and then visualize these probabilities against a normal distribution to reveal patterns across the league.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📂Dataset&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For this analysis, I worked with publicly available Premier League data for the 2024/2025 season.&lt;br&gt;
You can access the dataset I used here:&lt;a href="https://www.google.com/search?q=premier+league+table+2024%2F25&amp;amp;oq=premier+league+table+&amp;amp;gs_lcrp=EgZjaHJvbWUqBwgBEAAYgAQyBwgAEAAYjwIyBwgBEAAYgAQyBwgCEAAYgAQyBwgDEAAYgAQyBwgEEAAYgAQyBwgFEAAYgAQyBwgGEAAYgAQyBwgHEAAYgAQyBwgIEAAYgAQyBwgJEAAYgATSAQg5MjExajBqN6gCALACAA&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8" rel="noopener noreferrer"&gt;https://www.google.com/search?q=premier+league+table+2024%2F25&amp;amp;oq=premier+league+table+&amp;amp;gs_lcrp=EgZjaHJvbWUqBwgBEAAYgAQyBwgAEAAYjwIyBwgBEAAYgAQyBwgCEAAYgAQyBwgDEAAYgAQyBwgEEAAYgAQyBwgFEAAYgAQyBwgGEAAYgAQyBwgHEAAYgAQyBwgIEAAYgAQyBwgJEAAYgATSAQg5MjExajBqN6gCALACAA&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠️Step 1: Preparing the Data&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I started by creating a dataset of Premier League teams with their number of wins, draws, and losses. From this, I calculated the total games played and derived probabilities for each outcome.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd

# Create the dataset
data = {
    'Team': ['Manchester City', 'Liverpool', 'Chelsea', 'Arsenal', 'Manchester United',
             'Tottenham', 'Newcastle', 'Aston Villa', 'West Ham', 'Brighton'],
    'Wins': [20, 18, 16, 17, 15, 14, 13, 12, 11, 10],
    'Draws': [5, 7, 8, 6, 9, 8, 10, 7, 6, 9],
    'Losses': [3, 3, 4, 5, 6, 7, 5, 9, 11, 12]
}

df = pd.DataFrame(data)

# Calculate games played and probabilities
df['Games Played'] = df['Wins'] + df['Draws'] + df['Losses']
df['Win Probability'] = df['Wins'] / df['Games Played']
df['Draw Probability'] = df['Draws'] / df['Games Played']
df['Loss Probability'] = df['Losses'] / df['Games Played']

print(df.head())

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6nfptgras1vegp7hgohi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6nfptgras1vegp7hgohi.png" alt=" " width="652" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This gives us a clean table with each team’s probabilities for winning, drawing, or losing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📈Step 2: Statistical Distribution of Wins&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, I wanted to see how these win probabilities look when compared to the league-wide distribution. For this, I calculated the mean and standard deviation of win probabilities, and then plotted them on top of a normal distribution curve.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm

# Extract win probabilities
win_probs = df['Win Probability']

# Mean and standard deviation
mean, std_dev = win_probs.mean(), win_probs.std()

# Normal distribution
x = np.linspace(min(win_probs), max(win_probs), 100)
y = norm.pdf(x, mean, std_dev)

# Plot
plt.figure(figsize=(10,6))
plt.plot(x, y, color='blue', label='Normal Distribution')
plt.title("Distribution of Win Probabilities – Premier League 2024/25")
plt.xlabel("Win Probability")
plt.ylabel("Density")

# Mark each team's probability
for team, wp in zip(df['Team'], win_probs):
    plt.axvline(wp, linestyle='--', color='orange', alpha=0.7)
    plt.text(wp, 0.02, team, rotation=90, verticalalignment='bottom', fontsize=8)

plt.legend()
plt.show()

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvxk6dyq48c4rm5ewe0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhvxk6dyq48c4rm5ewe0e.png" alt=" " width="800" height="406"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡Step 3: Insights&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Top teams (like Manchester City &amp;amp; Liverpool) are well above the mean win probability, clustering at the higher end of the curve.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mid-table teams sit around the league average, showing balanced but less dominant results.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lower-end teams fall significantly below the mean, indicating their struggle in securing wins.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking at the league this way shows not just who’s winning, but how consistently teams are doing so compared to their peers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This project shows how Python can turn raw sports statistics into meaningful insights. By combining data preparation, probability calculations, and statistical visualization, I was able to map out a clearer picture of Premier League team performances in 2024/25.&lt;/p&gt;

&lt;p&gt;What’s powerful about this approach is that it isn’t limited to football — the same workflow can be applied anywhere probabilities matter: sales performance, business forecasting, or even academic results.&lt;/p&gt;

&lt;p&gt;Would love to hear your thoughts!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Started with Classification in Machine Learning</title>
      <dc:creator>Purity Ngugi</dc:creator>
      <pubDate>Fri, 29 Aug 2025 10:46:53 +0000</pubDate>
      <link>https://dev.to/purityngugi/classification-in-machine-learning-206k</link>
      <guid>https://dev.to/purityngugi/classification-in-machine-learning-206k</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Machine learning has quickly moved from research labs into our everyday lives. It powers things like voice assistants, fraud detection systems, personalized shopping recommendations, and even medical diagnoses. At its core, machine learning is about teaching computers to learn patterns from data and make predictions without being explicitly programmed for every task.&lt;br&gt;
Within the broad field of machine learning, supervised learning stands out as one of the most widely used approaches. And one of the most practical branches of supervised learning is classification.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Is Classification?&lt;/strong&gt;&lt;br&gt;
Classification is a type of supervised learning where the goal is to assign input data into predefined categories. Instead of predicting continuous values (like house prices in regression), classification deals with discrete outcomes.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this email spam or not spam?&lt;/li&gt;
&lt;li&gt;Is this transaction fraudulent or legit?&lt;/li&gt;
&lt;li&gt;Is this image a cat, a dog, or a bird?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Process of classification:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Collect Data – Gather labeled examples.&lt;/li&gt;
&lt;li&gt;Preprocess – Clean the dataset (remove duplicates, handle missing values, etc.).&lt;/li&gt;
&lt;li&gt;Feature Selection – Pick the most relevant features.&lt;/li&gt;
&lt;li&gt;Model Training – Use an algorithm to learn from the labeled data.&lt;/li&gt;
&lt;li&gt;Evaluation – Measure performance with metrics like accuracy, precision, and recall.&lt;/li&gt;
&lt;li&gt;Prediction – Classify new unseen data.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Classification Models&lt;/strong&gt;&lt;br&gt;
Different algorithms can be used for classification, and each works best in specific scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logistic Regression – Great for binary classification; simple and interpretable.&lt;/li&gt;
&lt;li&gt;Decision Trees – Easy to visualize; work well with small to medium datasets.&lt;/li&gt;
&lt;li&gt;Random Forests – An ensemble of decision trees that improves accuracy.&lt;/li&gt;
&lt;li&gt;K-Nearest Neighbors (KNN) – Classifies based on similarity but struggles with large datasets.&lt;/li&gt;
&lt;li&gt;Naive Bayes – Excellent for text classification (like spam detection).&lt;/li&gt;
&lt;li&gt;Neural Networks – Handle complex data like images and speech, but can be harder to interpret.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;My Insights&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What I love about classification is how real it feels—almost every dataset I’ve worked with had a classification angle, from predicting customer churn to filtering out spam.&lt;br&gt;
What I’ve learned is that data quality is everything. A simple model with clean, well-labeled data can outperform a deep learning model trained on messy data. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenges I’ve Faced&lt;/strong&gt;&lt;br&gt;
Working on classification hasn’t always been smooth. Some common hurdles include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Overfitting – Models that memorize training data instead of learning patterns.&lt;/li&gt;
&lt;li&gt;Class Imbalance – When one class dominates, models often ignore the minority class.&lt;/li&gt;
&lt;li&gt;Feature Selection – Choosing which features matter most is not always obvious.&lt;/li&gt;
&lt;li&gt;Interpretability – Complex models like neural networks are “black boxes.”&lt;/li&gt;
&lt;li&gt;Data Quality Issues – Noisy or mislabeled data can drag performance down.
These challenges can be frustrating, but they’ve also pushed me to improve my workflow and try different approaches.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Classification is one of the most practical and widely used areas of machine learning. Whether you’re detecting fraud, filtering spam, or building a recommendation engine, classification provides the foundation. While it comes with challenges like imbalance and overfitting, with the right data and approach, it’s both powerful and rewarding.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How Excel is Used in Real-World Data Analysis</title>
      <dc:creator>Purity Ngugi</dc:creator>
      <pubDate>Wed, 11 Jun 2025 13:09:22 +0000</pubDate>
      <link>https://dev.to/purityngugi/how-excel-is-used-in-real-world-data-analysis-40cd</link>
      <guid>https://dev.to/purityngugi/how-excel-is-used-in-real-world-data-analysis-40cd</guid>
      <description>&lt;p&gt;Microsoft Excel is a spreadsheet software that allows you to collect, organize, analyze, calculate and visualize data efficiently. It's a powerful tool used across various industries. It’s used for budgeting, financial analysis, project tracking and data visualization enabling businesses and professionals make informed decisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-World Applications of Excel&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Business Decision-Making&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Excel aids businesses in analyzing sales records, monitoring key performance indicators, and evaluating projected growth. Companies can interplay formulas and arrange data into tables to help in identifying trends for effective decisions. &lt;/p&gt;

&lt;p&gt;2.Financial Reporting&lt;/p&gt;

&lt;p&gt;Budgeting, financial modeling, and reporting are some tasks that financial analysts hydrate with Microsoft Excel. Organizations can efficiently manage their financial data, thanks to preserved detailed files that pivot tables and advanced formulas yield through comprehensive analysis.&lt;/p&gt;

&lt;p&gt;3.Marketing Performance Analysis&lt;/p&gt;

&lt;p&gt;Excel is indispensable to marketers. It assists them evaluate campaign results, monitor consumer activities, determine ROI, and even export data from other channels to analyze marketing spends for optimization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Excel Features for Data Analysis&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;•Pivot Tables: Helps summarize large datasets to extract meaningful insights which augments the analysis of trends and patterns.&lt;/p&gt;

&lt;p&gt;•Conditional Formatting: Apply formatting to cells based on specific criteria, highlighting important data points for quick analysis.&lt;/p&gt;

&lt;p&gt;•Sorting: Arrange data in a specific order either ascending or descending.&lt;/p&gt;

&lt;p&gt;•HLOOKUP: Search for specific value in the first row within a range and return related information, streamlining data retrieval processes.&lt;/p&gt;

&lt;p&gt;•VLOOKUP: Search for specific value in the first column within a range and return related information, streamlining data retrieval processes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Personal Reflection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With the knowledge of Excel, my way of looking at data has shifted completely. Data is not longer just numbers but stories begging to be shared. Excel provides the means to make sense of data, support conclusions, and relay information in a sensible manner. It has changed my perception on the relevance data has in modern society.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
