<?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: Rupali Gauravaram</title>
    <description>The latest articles on DEV Community by Rupali Gauravaram (@rupaligauravaram).</description>
    <link>https://dev.to/rupaligauravaram</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4206353%2F8ab9a2fc-de4a-4060-90c2-487fa2ae05d5.jpg</url>
      <title>DEV Community: Rupali Gauravaram</title>
      <link>https://dev.to/rupaligauravaram</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rupaligauravaram"/>
    <language>en</language>
    <item>
      <title>New DEV Milestone✨</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Thu, 19 Nov 2026 03:02:53 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/new-dev-milestone-50em</link>
      <guid>https://dev.to/rupaligauravaram/new-dev-milestone-50em</guid>
      <description>&lt;p&gt;Day 7 of &lt;a href="https://dev.to/rupaligauravaram/series/46111"&gt;#30DaysOfDataScience&lt;/a&gt;: on slowing down to learn the why 🧠&lt;/p&gt;

&lt;p&gt;8 posts in, and the biggest thing I've noticed is the learning curve hiding behind "best practices".&lt;/p&gt;

&lt;p&gt;So much of what we code is industry best practice we follow without stopping to ask why. Each prompt in this challenge has made me slow down, hyper-focus on a single concept, and find creative ways to explain and build within its constraints.&lt;/p&gt;

&lt;p&gt;Some days were slow. Some days I had the technical idea but couldn't find the right words to explain it; other days the words came easily and the code didn't.&lt;/p&gt;

&lt;p&gt;Even so, it's had a really positive effect on both my technical and creative skills.&lt;/p&gt;

&lt;p&gt;Want to try it? The prompts come from a small Python script I built that picks a topic and a set of constraints each day. It's open source: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator" rel="noopener noreferrer"&gt;dev-prompt-generator&lt;/a&gt;. Grab it and start your own 30 days.&lt;/p&gt;

&lt;p&gt;And if you have a moment, I'd really value feedback on any of &lt;a href="https://dev.to/rupaligauravaram/series/46111"&gt;my posts&lt;/a&gt; so far.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>datascience</category>
      <category>learning</category>
      <category>challenge</category>
    </item>
    <item>
      <title>Regularization explained: picking Lasso, Ridge or Elastic Net to prevent overfitting</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Wed, 18 Nov 2026 16:31:39 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/regularization-explained-picking-lasso-ridge-or-elastic-net-to-prevent-overfitting-33i0</link>
      <guid>https://dev.to/rupaligauravaram/regularization-explained-picking-lasso-ridge-or-elastic-net-to-prevent-overfitting-33i0</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fabyl6xlghi3lhwng9gnc.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fabyl6xlghi3lhwng9gnc.png" alt="prompt_07" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In machine learning tasks, we often face the challenge of &lt;strong&gt;overfitting&lt;/strong&gt;. When a model is too complex or uses very little data, it can overfit on the data. In order to prevent this we have a few methods, such as &lt;strong&gt;regularizing the model with added penalties on its weights&lt;/strong&gt; , or dimensionality reduction. Among these, we’ll be looking at regularization in this post.&lt;/p&gt;

&lt;p&gt;Regularization is the process of preventing overfitting of a model by &lt;strong&gt;adding a mathematical penalty or constraint&lt;/strong&gt; during the training process.&lt;/p&gt;

&lt;p&gt;Before we discuss regularization, it is important to note that we always &lt;strong&gt;standardize the data&lt;/strong&gt; before performing regularization, &lt;strong&gt;fitting the scaler on the training set only&lt;/strong&gt;. This prevents the model from unfairly penalizing variables that are on a larger scale.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lasso or L1 regularization&lt;/strong&gt; , which stands for &lt;strong&gt;Least Absolute Shrinkage and Selection Operator&lt;/strong&gt; , penalizes the absolute weights of each feature and &lt;strong&gt;shrinks some weights to exactly 0&lt;/strong&gt; , thereby &lt;strong&gt;automatically dropping irrelevant features&lt;/strong&gt; in a dataset that may have many features.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ridge or L2 regularization&lt;/strong&gt; doesn’t shrink any feature weights to exactly 0, unlike Lasso. It penalizes the squared weights, which &lt;strong&gt;shrinks all the weights towards zero and retains all the features&lt;/strong&gt;. When features are highly correlated, it &lt;strong&gt;shares the weight between them&lt;/strong&gt; instead of dropping any.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elastic Net&lt;/strong&gt; is a &lt;strong&gt;blend of both Lasso and Ridge&lt;/strong&gt; regularization methods. It uses a ratio of how much of Lasso and Ridge to use during training, which is defined by the user and is usually &lt;strong&gt;tuned with cross-validation&lt;/strong&gt;. So not only do we get to drop the features with the weakest weights, but we also get to &lt;strong&gt;keep groups of highly correlated features together&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lasso (L1-Regularization) on NYC Airbnb price prediction:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Predicting the per-night price of a property using listing details, availability, review metrics and location features such as neighbourhood_group, neighbourhood and room_type.&lt;/p&gt;

&lt;p&gt;When we try to use this dataset and one-hot encode a column like neighbourhood (which has &lt;strong&gt;200+ distinct areas&lt;/strong&gt; ), we end up creating &lt;strong&gt;too many binary dummy columns&lt;/strong&gt;. Many of these neighbourhoods either have very few listings or aren’t different enough to shift the price away from the baseline average of their neighbourhood_group.&lt;/p&gt;

&lt;p&gt;In such a scenario, where you suspect that some features are irrelevant and &lt;strong&gt;only a few are strongly related to the target&lt;/strong&gt; , we use Lasso. This means that for listings in a rare neighbourhood, &lt;strong&gt;Lasso automatically drops their dummies&lt;/strong&gt; and keeps only the locations and room types that genuinely drive price differences.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ridge (L2-penalised logistic regression) for heart disease classification:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Heart disease classification, where the target column is a binary class, with 13 clinical features like age, restingBloodPressure, cholesterol, maximumHeartRate, oldpeak and chestPain, across 303 patient records.&lt;/p&gt;

&lt;p&gt;Unlike in the Airbnb dataset, here &lt;strong&gt;every single feature is a medical indicator&lt;/strong&gt; and none of them are considered random noise. However, this dataset has &lt;strong&gt;just about 300 patient records&lt;/strong&gt; , and some physiological markers (such as age, maximumHeartRate and exerciseInducedAngina) clinically overlap. Without regularization, a standard logistic regression model can assign &lt;strong&gt;unstable weights&lt;/strong&gt; to individual features based on a few extreme patient records.&lt;/p&gt;

&lt;p&gt;Ridge &lt;strong&gt;preserves the collective diagnostic signal&lt;/strong&gt; across all 13 clinical variables while &lt;strong&gt;preventing any single biomarker from dominating&lt;/strong&gt; the prediction on a small sample.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Elastic Net for housing price prediction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Predicting price using structural dimensions (area, bedrooms, bathrooms, stories, parking) alongside categorical amenities (mainroad, guestroom, basement, hotwaterheating, airconditioning, prefarea, furnishingstatus).&lt;/p&gt;

&lt;p&gt;This dataset combines two modelling challenges: &lt;strong&gt;grouped multicollinearity&lt;/strong&gt; and &lt;strong&gt;sparse amenities&lt;/strong&gt;. Larger houses tend to have more area, more bedrooms and bathrooms, and more stories (floors). A pure Lasso tends to &lt;strong&gt;pick just one significant feature from a group of correlated features&lt;/strong&gt; (like keeping area and dropping bedrooms and stories), risking throwing away useful information. Features like hotwaterheating (a binary feature where the majority of records are ‘no’) or furnishingstatus may add little value once major features like area and airconditioning are considered.&lt;/p&gt;

&lt;p&gt;Elastic Net’s Ridge component groups the correlated features (area, bedrooms, bathrooms and stories) so they &lt;strong&gt;share weights smoothly&lt;/strong&gt; rather than one being picked over the others, while the Lasso component simultaneously &lt;strong&gt;drops any weak or redundant feature weights to 0&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary table to compare Lasso, Ridge and Elastic Net regularization&lt;/strong&gt;&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7nttzlw0y34pkvrmrrtj.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7nttzlw0y34pkvrmrrtj.png" alt="summary comparison between lasso, ridge, elasticnet" width="750" height="578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Along with these regularization methods, what other methods do you use to prevent overfitting?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This was Day 7 of my 30 Days of Data Science writing challenge. Writing this article was a good challenge to recollect where I’ve used these regularization methods before and understand why they were used.&lt;/p&gt;

&lt;p&gt;If you’re a beginner in ML and would like to learn more about regularization and other ML concepts, I’d recommend this book: &lt;a href="https://www.statlearning.com/" rel="noopener noreferrer"&gt;&lt;u&gt;An Introduction to Statistical Learning (ISL)&lt;/u&gt;&lt;/a&gt;. It has free online editions in Python (ISLP) and R (ISLR), with its own packages and datasets for practice.&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>datascience</category>
      <category>elasticnet</category>
      <category>lasso</category>
    </item>
    <item>
      <title>Two SARIMA models, one clear winner: picking with AIC value</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Tue, 17 Nov 2026 08:54:16 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/two-sarima-models-one-clear-winner-picking-with-aic-value-1346</link>
      <guid>https://dev.to/rupaligauravaram/two-sarima-models-one-clear-winner-picking-with-aic-value-1346</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhiicet9g8yaqbr5h9g2s.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhiicet9g8yaqbr5h9g2s.png" width="800" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This prompt seemed challenging from the start. Not only did it require me to write fewer than 40 lines of code, I also had to create my own time series dataset and build at least two SARIMA models to identify the best one using the &lt;strong&gt;Akaike Information Criterion (AIC).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just as I was trying to process these constraints, I had an idea for the dataset. Where I live, we have an apartment grocery store where we buy dairy products like milk and curd almost daily. Since dairy is perishable, I decided to analyse 3 months of milk sales, which could help forecast the store’s stock requirement for the next month.&lt;/p&gt;

&lt;p&gt;I created a dataset of daily dates from &lt;strong&gt;September to November 2026 (90 days)&lt;/strong&gt;, took a one-week sample of milk packets sold, repeated it across the 90 days and added random noise (normal distribution, standard deviation of 3). I rounded the values to integers so the packets stay whole numbers, and stored everything in a &lt;strong&gt;DataFrame called packets&lt;/strong&gt;. I modelled packets rather than revenue because the shop restocks in packet numbers; revenue is just packets × ₹27, so the model choice would still be the same if I used revenue instead.&lt;/p&gt;

&lt;p&gt;Next, &lt;strong&gt;I plotted packets_sold to&lt;/strong&gt;  &lt;strong&gt;see whether the series was additive or multiplicative&lt;/strong&gt;. This matters for &lt;strong&gt;seasonal decomposition&lt;/strong&gt; (splitting the series into trend, seasonality and noise): swings that grow over time are multiplicative, while swings that stay roughly constant are additive.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx7pwzerppwufi7plc6yy.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fx7pwzerppwufi7plc6yy.png" width="543" height="413"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Plot showing packets_sold over 90 days&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The swings have a roughly constant amplitude across all 90 days, so the series is additive. I then &lt;strong&gt;split the data into train and test sets in time order (80:20)&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="c1"&gt;# train test splitX,y = packets[:-18], packets[-18:]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: shuffling time series data lets future points into training, so the model effectively sees the future and the test scores look better than they really are.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After splitting the data, I ran &lt;strong&gt;seasonal_decompose&lt;/strong&gt;  &lt;strong&gt;on the training data&lt;/strong&gt; (additive, period = 7 for the weekly cycle):&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz862axbma7ohhzmkncu2.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz862axbma7ohhzmkncu2.png" width="628" height="470"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Plot showing seasonal decompose: Trend, Seasonality and Noise&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;plot shows no real trend, so at first glance we won’t need non-seasonal differencing&lt;/strong&gt;. I then &lt;strong&gt;checked whether the data is stationary with the Augmented Dickey-Fuller (ADF) test&lt;/strong&gt;, choosing a &lt;strong&gt;significance level (alpha) of 0.05&lt;/strong&gt; before running it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: the ADF test’s null hypothesis (H0) is that the data is non-stationary. If the p-value is below alpha, we reject H0 and treat the data as stationary; otherwise we fail to reject H0, and the data needs differencing to become stationary.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The ADF test showed that the training data is stationary, so the non-seasonal differencing order is d = 0.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Next, I applied &lt;strong&gt;first-order seasonal differencing (D = 1, seasonal period of 7)&lt;/strong&gt;: today’s sales minus sales from 7 days ago.&lt;/p&gt;

&lt;p&gt;Then I plotted the &lt;strong&gt;ACF&lt;/strong&gt; and &lt;strong&gt;PACF&lt;/strong&gt; of the differenced series:&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpvagsp0zjs0wr3oey66x.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpvagsp0zjs0wr3oey66x.png" width="799" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Neither plot shows significant lags at 1–4, so p = 0 and q = 0&lt;/strong&gt;. A single negative spike at lag 7 that cuts off in the ACF points to a &lt;strong&gt;seasonal MA(1) term&lt;/strong&gt;; &lt;strong&gt;a seasonal AR(1) term is the alternative.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I built and fitted two models, &lt;strong&gt;model 1 as SARIMA(0,0,0)(0,1,1,7)&lt;/strong&gt; and &lt;strong&gt;model 2 as SARIMA(0,0,0)(1,1,0,7)&lt;/strong&gt;, and &lt;strong&gt;compared their AIC values.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AIC balances how well a model fits the data against how complex it is, and lower is better&lt;/strong&gt;. It can’t judge a single model on its own, it only compares models trained on exactly the same data.&lt;/p&gt;

&lt;p&gt;As a rule of thumb:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If the difference between AIC1 and AIC2 i.e. delta &amp;lt;= 2, the weaker model still has substantial support to be considered.&lt;/li&gt;
&lt;li&gt;If 4 &amp;lt;= delta &amp;lt;= 7, support is considerably less.&lt;/li&gt;
&lt;li&gt;If delta &amp;gt; 10, there is a significant difference between the model performances, support is low, choose the model with lower AIC value.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Model 1 scored 349.58&lt;/strong&gt; and &lt;strong&gt;model 2 scored 366.76&lt;/strong&gt; , a &lt;strong&gt;gap of -17.18&lt;/strong&gt; , so &lt;strong&gt;model 1, SARIMA(0,0,0)(0,1,1,7), is the clear winner.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Selecting a model via AIC is efficient, clean, and mathematically rigorous. It gives us an immediate compass for model selection when we’re deep in the tuning phase. Even so, &lt;strong&gt;a low AIC only tells us how well the model explains the past, not necessarily how robustly it will handle the unpredictable future.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Would you trust AIC alone, or always check the forecast error on held-out data too?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This was Day 6 of my 30 Days of Data Science writing challenge. Building this model under 40 lines with a small hand-built dataset was challenging but super fun. Through this I got a better understanding on how to pick the time series model components.&lt;/p&gt;

&lt;p&gt;You can see the complete notebook on my GitHub: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_06.ipynb" rel="noopener noreferrer"&gt;https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_06.ipynb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>challenge</category>
      <category>timeseries</category>
      <category>forecasting</category>
    </item>
    <item>
      <title>DBSCAN’s edge over K-Means clustering</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Sun, 08 Nov 2026 18:30:20 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/dbscans-edge-over-k-means-clustering-2pl0</link>
      <guid>https://dev.to/rupaligauravaram/dbscans-edge-over-k-means-clustering-2pl0</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fam8v44kqec6wvcye2jr0.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fam8v44kqec6wvcye2jr0.png" width="776" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The moment I saw this prompt, I knew I needed a dataset that was large and noisy enough to truly show how the two unsupervised models differ. So, despite the constraint to use a tiny made-up dataset, I chose an Airbnb dataset for NYC.&lt;/p&gt;

&lt;p&gt;First, I cleaned the dataset and narrowed our focus from all of New York City to just Queens, reducing the data from nearly 49,000 rows to 4,540. I also filtered out long-term rentals by capping the minimum stay at 30 nights.&lt;/p&gt;

&lt;p&gt;To prepare for clustering, I removed unhelpful columns like names and ID numbers (preventing the KMeans algorithm from misinterpreting ID values as mathematical weight), along with the neighbourhood group column, since everything is now in Queens.&lt;/p&gt;

&lt;p&gt;Because the K-Means algorithm only works only with numbers, I handled the text columns. Instead of dropping neighborhoods entirely, I converted all 48 sub-categories into numerical frequency scores. I then dropped remaining text columns like room type and last review, and stored our finalized table as queens_df.&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiwtz0opw4gohspkepatv.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fiwtz0opw4gohspkepatv.png" width="800" height="116"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;First five rows of queens_df (4,540 rows, 9 features)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before building any machine learning model, especially gradient-based and distance-based models, it’s important to standardise the data&lt;/strong&gt;. Without standardising, features with a larger range of values tend to look more important and dominate the results. I used Scikit-learn’s &lt;strong&gt;StandardScaler&lt;/strong&gt; on queens_df, standardised it using fit_transform, and called the result &lt;strong&gt;X_scaled.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For the K-Means model, I followed these steps after standardising the data:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build the K-Means model&lt;/strong&gt; and &lt;strong&gt;fit it on X_scaled&lt;/strong&gt; , with &lt;strong&gt;n_clusters=11&lt;/strong&gt; and &lt;strong&gt;random_state=101&lt;/strong&gt; for starters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Find the appropriate number of clusters in two steps:&lt;/strong&gt; plot the elbow curve to get a rough idea of possible k values, then plot the silhouette score of the base model.&lt;/li&gt;
&lt;/ol&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwqi9f8ww817ybpvp5qp3.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwqi9f8ww817ybpvp5qp3.png" width="800" height="263"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Elbow method (left) and silhouette scores (right); silhouette peaks at k = 4&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: The silhouette plot shows us a measure of how close each point in one cluster is to points in the neighbouring clusters. It provides a way to assess parameters like number of clusters visually (Silhouette scores range range from -1 to +1).&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build the final K-Means model&lt;/strong&gt; using the k value derived from the plots, and &lt;strong&gt;store the cluster labels as a column in queens_df.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Plot scatter plots to see the clusters&lt;/strong&gt; using various features (for example, price vs number_of_reviews, coloured by cluster).&lt;/li&gt;
&lt;/ol&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4hpexeudjrigb3okzlh1.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4hpexeudjrigb3okzlh1.png" width="800" height="392"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Price vs number of reviews, coloured by K-Means cluster&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Compare the median values of each cluster to see how their patterns differ.&lt;/strong&gt; Using median() makes the clusters stand out and helps draw inferences, rather than looking at each cluster’s raw data individually.&lt;/li&gt;
&lt;/ol&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq0nq314sikxjicbt9n57.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq0nq314sikxjicbt9n57.png" width="723" height="433"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Median feature values per K-Means cluster&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Next, I’ll show you how I built the &lt;strong&gt;DBSCAN model&lt;/strong&gt; , followed by a comparison of the two models, so it all makes more sense.&lt;/p&gt;

&lt;p&gt;For the DBSCAN model, it’s worth remembering the &lt;strong&gt;main difference from K-Means:&lt;/strong&gt;  &lt;strong&gt;DBSCAN doesn’t need us to specify the number of clusters, it’s intuitive, and it handles noisy datasets extremely well.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: the DBSCAN documentation mentions that scikit-learn’s implementation has a worst-case memory complexity that can occur when eps is large and min_samples is low, whereas the original DBSCAN uses only linear memory. So I tried to be mindful of these parameters.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To build the DBSCAN model, I used the same X_scaled data from the previous model and followed these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rule of thumb for &lt;strong&gt;min_samples: 2&lt;/strong&gt; x &lt;strong&gt;n_features&lt;/strong&gt;. Since I have 9 features in X_scaled, &lt;strong&gt;min_samples is 18&lt;/strong&gt;. &lt;/li&gt;
&lt;li&gt;For the first model, use min_samples (i.e. 18) as n_neighbors in &lt;strong&gt;NearestNeighbors,&lt;/strong&gt; and &lt;strong&gt;call the model neigh&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fit&lt;/strong&gt; the neigh model to X_scaled.&lt;/li&gt;
&lt;li&gt;Use tuple unpacking to get the &lt;strong&gt;distances and indices of the k-neighbours&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The distances for each data point always start with 0 (the distance from itself), followed by the distances to its neighbours in ascending order. We need the &lt;strong&gt;distance to its 18th nearest neighbour,&lt;/strong&gt; which is the &lt;strong&gt;last column of the dist matrix.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Next, choose an &lt;strong&gt;eps value&lt;/strong&gt; (it is simply the maximum distance at which two points still count as neighbours).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;To find eps, plot these distances using matplotlib&lt;/strong&gt; to get an elbow-like chart, which tells us what the eps value should be for the final model. &lt;strong&gt;We’re looking for the point where the curve bends sharply upward&lt;/strong&gt; : below it, points are packed closely together. For my model, this turned out to be just after 1.5, so &lt;strong&gt;I chose eps=2&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl886fazyomqq75y5v31o.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl886fazyomqq75y5v31o.png" width="554" height="438"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;k-distance plot (18th-neighbour distance, zoomed to 0–5)&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Build the DBSCAN model&lt;/strong&gt; with basic params, &lt;strong&gt;eps=2 and min_samples=18&lt;/strong&gt; , and call it dbscan.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fit&lt;/strong&gt; this model on X_scaled&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Save dbscan.labels_ into queens_df[‘dbscan_clusters’]&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, let’s compare both models:&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi2bgvtxr6ca5gnn0cin7.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fi2bgvtxr6ca5gnn0cin7.png" width="800" height="254"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;KMeans clusters Vs DBSCAN clusters&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Shape of the data:&lt;/strong&gt; K-Means had to split Queens into 4 clusters and assign every listing to one, because it has no notion of noise. DBSCAN found only 2 clusters plus noise: one dense cluster holding 97.6% of listings, a tiny cluster of 0.8% (35 listings), and 1.7% noise (75 listings).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A hidden niche:&lt;/strong&gt; DBSCAN’s tiny cluster is very specific. All 35 listings are private rooms with a 30-night minimum, the lowest median price (~$39), the highest availability (239 days), almost no reviews (median 1), and hosts running ~103 listings each, which suggests one or a few large operators. K-Means found a related group (cluster 1, 219 listings, ~7 listings per host), but it was diluted with mixed room types and smaller hosts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Popular listings are the outliers:&lt;/strong&gt; the noise points have the most reviews (median 132 per listing, ~5.4 per month). They resemble K-Means cluster 3, but DBSCAN treats them as rare, scattered listings rather than a group of their own.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The typical Queens listing:&lt;/strong&gt; DB0’s hosts usually run a single listing (median 1), with ~14 reviews and a mix of private rooms (2,575), entire homes (1,710) and shared rooms (145).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;This was Day 5 of my 30 Days of Data Science writing challenge. It has been by far the most interesting build so far. I learnt something new about how these two clustering models behave by reading scikit-learn’s documentation.&lt;/p&gt;

&lt;p&gt;You can see the complete notebook on my GitHub: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_05.ipynb" rel="noopener noreferrer"&gt;https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_05.ipynb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>ai</category>
      <category>airbnbdata</category>
      <category>artificialintelligen</category>
    </item>
    <item>
      <title>AVG() on INT columns in SQL Server: the silent truncation you didn’t expect</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Sun, 08 Nov 2026 15:35:12 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/avg-on-int-columns-in-sql-server-the-silent-truncation-you-didnt-expect-1j7k</link>
      <guid>https://dev.to/rupaligauravaram/avg-on-int-columns-in-sql-server-the-silent-truncation-you-didnt-expect-1j7k</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq17rix3zwlacoeg6nqi1.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq17rix3zwlacoeg6nqi1.png" width="800" height="403"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When calculating averages in SQL Server using integer columns, standard queries can silently distort your metrics. For example, let’s take the following dataset on Employee data for various engineering roles, where the salary and rating columns are INT type. SQL Server evaluates the expression using integer division and silently drops the decimal portion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="c1"&gt;-- table structureCREATE TABLE EMPLOYEE (&lt;/span&gt;
&lt;span class="n"&gt;empId&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="n"&gt;dept&lt;/span&gt; &lt;span class="nb"&gt;VARCHAR&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt; &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="n"&gt;CK_EMPLOYEE_rating&lt;/span&gt; &lt;span class="k"&gt;CHECK&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rating&lt;/span&gt; &lt;span class="k"&gt;BETWEEN&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;-- sample records (first 4 of 27 rows; full script on GitHub)INSERT INTO EMPLOYEE (empId, name, dept, salary, rating) VALUES&lt;/span&gt;
&lt;span class="c1"&gt;-- Software Development Engineer (SDE)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Zaara'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SDE 1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1800000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Aarav'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SDE 2'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3800000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Priya'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'SDE 3'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6500000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Rohan'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Lead SDE'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8500000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So when we take the average of salary and rating columns, we see the following result displayed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;avg_salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;avg_rating&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;EMPLOYEE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjetvph1icwkq7pnmrpvg.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjetvph1icwkq7pnmrpvg.png" width="704" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Whereas in reality, the sum of all salaries divided by the number of employees generates a decimal number, the final result gets truncated, meaning the decimal portion gets dropped completely. Similarly, when we take the average of the rating column, its decimal portion gets dropped.&lt;/p&gt;

&lt;p&gt;Let’s fix this by altering the data types to DECIMAL (making sure to handle our constraints properly) and see the updated results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;EMPLOYEE&lt;/span&gt; &lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;COLUMN&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;-- drop the CHECK constraint so the column type can changeALTER TABLE EMPLOYEE DROP CONSTRAINT CK_EMPLOYEE_rating; ALTER TABLE EMPLOYEE ALTER COLUMN rating DECIMAL(3,2);ALTER TABLE EMPLOYEE ADD CONSTRAINT CK_EMPLOYEE_rating CHECK (rating BETWEEN 1 AND 5);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, recompute the average, the same as before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;avg_salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rating&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;avg_rating&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;EMPLOYEE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This time the output shows the accurate decimal portions as well:&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodnz2y45onl06pi14cmp.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fodnz2y45onl06pi14cmp.png" width="640" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What we see is that using DECIMAL gives us the actual average with the decimal part intact. While the difference between the two for avg_salary doesn’t seem like much on large numbers, there is a massive distortion in the average rating results. The actual average rating should have been 3.96, but it got truncated down to just 3.&lt;/p&gt;

&lt;p&gt;In real-world cases, where we deal with large volumes of records and aggregate metrics like performance scores or ratings, finding the exact average requires us to cast or store our numerical metrics with fractional precision (like DECIMAL or FLOAT) even if the raw inputs are integers.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have you ever noticed the unexpected difference between the results of an AVG() function for an INT versus a DECIMAL/FLOAT type column in MS SQL Server?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This was Day 4 of my 30 Days of Data Science writing challenge. While the prompt felt simple, it took some amount of research to understand how how SQL Server computes averages.&lt;/p&gt;

&lt;p&gt;You can see the complete SQL query on my GitHub: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_04-employee_data.sql" rel="noopener noreferrer"&gt;https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_04-employee_data.sql&lt;/a&gt;&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>artificialintelligen</category>
      <category>average</category>
      <category>compare</category>
    </item>
    <item>
      <title>Building ML metrics from scratch in NumPy</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Sat, 07 Nov 2026 18:32:21 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/building-ml-metrics-from-scratch-in-numpy-20hm</link>
      <guid>https://dev.to/rupaligauravaram/building-ml-metrics-from-scratch-in-numpy-20hm</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa6vhghkp5137i8ic1fmv.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fa6vhghkp5137i8ic1fmv.png" alt="prompt" width="800" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I recently did a customer churn prediction project that had a really high accuracy, but when I checked the classification report, I found that the model was missing almost every churner. That’s when I realised that it’s perfectly possible for a model to lazily predict and look very accurate when in reality it’s heavily misclassifying and missing the positive cases. This is especially the case when the classes are heavily imbalanced.&lt;/p&gt;

&lt;p&gt;For this prompt, I chose an Employee Attrition dataset with 460 records. As soon as I loaded it, I saw how messy it was: the same departments spelled in several different ways, incomes stored as text with commas, impossible values like negative ages, and missing data. I cleaned it and ended up with 427 rows: 291 employees who stayed and 136 who left.&lt;/p&gt;

&lt;p&gt;Since the prompt asks about a class imbalance where accuracy is 73%, I took random resamples of employees who stayed and concatenated them back to the dataset to recreate a 73:27 class imbalance (504 rows). In a real project you’d only resample the training data, never the data you evaluate on; here it’s just to recreate the 73:27 split.&lt;/p&gt;

&lt;p&gt;You can read the full code, including the data cleaning, on GitHub: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_03.ipynb" rel="noopener noreferrer"&gt;https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_03.ipynb&lt;/a&gt;&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp9afbf96byvv9v3pa00g.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fp9afbf96byvv9v3pa00g.png" alt="Before and after cleaning: a few rows of the raw and cleaned data" width="800" height="369"&gt;&lt;/a&gt;Before and after cleaning: a few rows of the raw and cleaned data.&lt;/p&gt;

&lt;p&gt;I then wanted to see the correlation between the various features and the target column (Attrition) using a seaborn heatmap. Most of the correlations are weak; the strongest was the ‘OverTime’ feature. So I decided to use that as the input and Attrition as the target, since the prompt asked me to build it with NumPy, without scikit-learn.&lt;/p&gt;

&lt;p&gt;Next, I had to build the confusion matrix. I wrote down all the formulas for accuracy, precision, recall, specificity and F1 score, and then realised I needed to compute the True Positive, True Negative, False Positive and False Negative values first. It took a while of scratching my head to see how I could get these values manually. Turns out I just needed y_true and y_preds first, so I was reverse engineering as I wrote the code, because who writes this stuff manually when we have beautiful packages that do it in a few simple lines of code?  &lt;/p&gt;

&lt;p&gt;To get the y_preds, as you can guess, I needed a model that predicts, or a for loop that behaves like one. So I wrote a simple for loop that goes through every OverTime value and makes a prediction from that one column: if OverTime is 1 (Yes), the employee is likely to leave; if it’s 0 (No), they’re probably happy to keep their job.&lt;/p&gt;

&lt;p&gt;I built a clean function to compute the metrics from two inputs (y_true and y_preds), the same way scikit-learn’s precision_score or recall_score would.&lt;/p&gt;

&lt;p&gt;Here’s what the numbers showed. The lazy model that predicts nobody leaves scored 73% accuracy but caught 0% of the employees who left. The OverTime rule scored lower, 65.9% accuracy, but caught 46% of them (recall 46.3%, precision 38.9%). Lower accuracy, far more useful.&lt;/p&gt;

&lt;p&gt;Then I had one last bit of the prompt left to complete: writing test cases.&lt;/p&gt;

&lt;p&gt;Considering how much time I’d already spent on the code, I was starting to feel frustrated, but I pushed myself to complete it anyway: if I want to become a really good developer, I need to write good test cases and check my code’s sanity the traditional way.&lt;/p&gt;

&lt;p&gt;Inside the function, an if check makes sure no denominator is 0 before dividing, so it doesn’t crash on divide-by-zero errors, which can happen when the denominator of any metric ends up being 0. The test cases then check that the function returns the right answers, including in that situation.&lt;/p&gt;

&lt;p&gt;The three test cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A normal model case&lt;/li&gt;
&lt;li&gt;A Perfect model case&lt;/li&gt;
&lt;li&gt;A lazy-model case
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="c1"&gt;# testsy_true_test = np.array([1,0,1,0])# 1. Normal caseacc, prec, rec, spec, f1 = get_metrics(y_true_test, np.array([1, 0, 0, 0]))assert rec == 0.5assert prec == 1.0# 2. Perfect caseacc, prec, rec, spec, f1 = get_metrics(y_true_test, y_true_test)assert acc == 1.0assert rec == 1.0# 3. edge: model predicts no positivesacc, prec, rec, spec, f1 = get_metrics(y_true_test, np.array([0, 0, 0, 0]))assert prec == 0    assert rec == 0print("All 3 tests passed")
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The takeaway: on imbalanced data, never trust accuracy alone. Check recall and precision too.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Have you ever built these metrics manually?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This was Day 3 of my 30 Days of Data Science writing challenge. This one was a real build: cleaning a messy dataset, writing the metrics from scratch in NumPy without scikit-learn, and adding test cases to check my own code.&lt;/p&gt;

&lt;p&gt;If you’d like to see the Python code for this post, you can read it at: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_03.ipynb" rel="noopener noreferrer"&gt;https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_03.ipynb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>How confident are you about Confidence Intervals?</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Thu, 05 Nov 2026 17:55:16 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/how-confident-are-you-about-confidence-intervals-2ng8</link>
      <guid>https://dev.to/rupaligauravaram/how-confident-are-you-about-confidence-intervals-2ng8</guid>
      <description>&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%2Fchaiandcode.wordpress.com%2Fwp-content%2Fuploads%2F2026%2F11%2Fimage-eb5334f3.png%3Fw%3D886" 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%2Fchaiandcode.wordpress.com%2Fwp-content%2Fuploads%2F2026%2F11%2Fimage-eb5334f3.png%3Fw%3D886" alt="" width="886" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The first time I came across the term Confidence Level of 95%, I misunderstood that it means there is a 95% probability that the true parameter falls inside this specific interval. This is a common misconception and it took quite a few attempts to get the concept right. So here’s my attempt at explaining it in simple terms using a chai analogy.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Before I get into the details, let’s understand why we have a Confidence Interval and not a confidence value in statistics. I recently read in Practical Statistics for Data Scientists that humans are naturally &lt;strong&gt;averse to uncertainty&lt;/strong&gt;, so we like single, confident numbers. But a single estimate from a sample hides how uncertain it is. &lt;strong&gt;A confidence interval gives a range of plausible values&lt;/strong&gt; instead, which is a more honest answer.&lt;/p&gt;

&lt;p&gt;In order to explain the concept of Confidence Intervals, I’ll use a simple example of a Chai dataset I created. There are two columns, personID and their milk-to-water preference ratio in tea. I have 60 records in the dataset – we will call this the original sample set. I’ll first have to explain a crucial factor of sampling.&lt;/p&gt;

&lt;p&gt;We take &lt;strong&gt;multiple resamples of the sample set with replacement&lt;/strong&gt;. I’ll explain what replacement means here in a minute. Imagine I pick a chit from a bowl of samples and each one has one person’s ID and milk-to-water ratio, I make a note and put that chit back and pick again, this is how resampling with replacement works. We need many rounds of resamples to be able to confidently give a result.&lt;/p&gt;

&lt;p&gt;So say we take the original chai samples (60 records), I make 1000 resamples using this set, each is of length 60 (the same length as the original sample set).&lt;/p&gt;

&lt;p&gt;These 1000 resamples we made, they’re called &lt;strong&gt;bootstrap samples.&lt;/strong&gt;  Each of these bootstrap samples has a mean of its own. The spread of the bootstrap means shows how much the average would vary from sample to sample.&lt;/p&gt;

&lt;p&gt;Fact: If you’re familiar with how Random Forest models work, you must have come across this term Bootstrap aggregation. RF models use this method of drawing samples too.&lt;/p&gt;

&lt;p&gt;Next, we choose a confidence level, usually 90% or 95%. So if we choose Confidence Level as 95%, we sort the 1,000 means and cut off the lowest 2.5% and highest 2.5% of the means. &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;bootstrap_means = []

for _ in range(1000):
    resample_df = resample(chai_df, replace=True, n_samples=len(chai_df))
    bs_mean = resample_df['Milk_water_ratio'].mean()
    bootstrap_means.append(bs_mean)

bootstrap_means = pd.Series(bootstrap_means)

# 95% confidence level: cut off the lowest 2.5% and highest 2.5% of the means
lower_lim = bootstrap_means.quantile(0.025)
upper_lim = bootstrap_means.quantile(0.975)

print(f'Lower limit of Confidence Interval is: {lower_lim}')
print(f'Upper limit of Confidence Interval is: {upper_lim}')
print(f'We are 95% confident (in the sense of the method) that the average milk-to-water ratio lies between {lower_lim} and {upper_lim}')

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

&lt;p&gt;If you visualise the above result using a histogram, you get something like this:&lt;/p&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%2Fchaiandcode.wordpress.com%2Fwp-content%2Fuploads%2F2026%2F11%2Fconfidence-interval.png%3Fw%3D851" 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%2Fchaiandcode.wordpress.com%2Fwp-content%2Fuploads%2F2026%2F11%2Fconfidence-interval.png%3Fw%3D851" alt="" width="851" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what is the 95% referring to?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After taking many (for example, 1,000) resamples, 95% of the bootstrap means lie between two points, the lower and upper limits we found earlier. Those two points form the confidence interval. For my &lt;strong&gt;chai data&lt;/strong&gt;, &lt;strong&gt;the Confidence Interval range came out as 1.24 to 1.53&lt;/strong&gt; (between the two dashed red lines of the histogram). &lt;/p&gt;

&lt;p&gt;So we can say, with 95% confidence, that the average milk-to-water preference of chai drinkers like the ones I surveyed lies between 1.24 and 1.53, even though an individual's preference ranges from 1 to 3.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;What are some real-world use cases where you’ve seen or used Confidence Intervals?&lt;/em&gt;&lt;/p&gt;





&lt;p&gt;This was Day 2 of my 30 Days of Data Science writing challenge. Writing about this topic required a lot of effort and creativity: to understand the concept, come up with a chai related analogy and explain it as plainly as possible. &lt;/p&gt;

&lt;p&gt;If you'd like to see the Python code for this post, you can read it at: &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_02.ipynb" rel="noopener noreferrer"&gt; https://github.com/Rupali-Gauravaram/dev-prompt-generator/blob/main/posts/post_02.ipynb&lt;/a&gt;&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>bootstrap</category>
      <category>confidenceintervals</category>
      <category>datascience</category>
    </item>
    <item>
      <title>Don’t trust a model’s accuracy alone: precision, recall and specificity explained</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Wed, 04 Nov 2026 18:29:56 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/dont-trust-a-models-accuracy-alone-precision-recall-and-specificity-explained-1alf</link>
      <guid>https://dev.to/rupaligauravaram/dont-trust-a-models-accuracy-alone-precision-recall-and-specificity-explained-1alf</guid>
      <description>&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F034jfc7fftyt38yi052t.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F034jfc7fftyt38yi052t.png" alt=" " width="799" height="324"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I’ve mixed up the different machine learning metrics while explaining them on more than one occasion. I found that quickly drawing a confusion matrix really helps until the concept sticks. Here’s a short conversation between a mother and her 12-year-old son, where she explains machine learning metrics in simple terms.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Raghav was rigorously preparing for a test that was less than a week away. His mother was making sure he was studying everything as per the syllabus, and decided to test him after he studied each chapter.&lt;/p&gt;

&lt;p&gt;Today, he went over the entire chapter in a hurry because of how long and boring the subject was, and went to his mother to be quizzed. She gave him a set of 20 true/false questions. He started answering them and saw that most of the answers were true; for the ones he wasn’t sure about, he guessed True, since most of the earlier answers had been True. When his mother cross-questioned him on the questions he got wrong, he confessed that he’d guessed because most answers were true.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Raghav, you can’t guess answers during exams. Does this mean you didn’t actually study the chapter well enough?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Ma, but it’s so difficult, the chapter is so long. I didn’t learn it properly, so I guessed some.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Okay, here’s the deal, take a small break. I’ll first tell you something about how machines learn and perform when tested, you might find this interesting.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Sure, tell me! I love computer science, this should be fun.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Imagine you have 100 bank transactions and you feed them into a machine. You want the machine to learn from this data so that it can correctly tell a genuine transaction from a fraudulent one in the future.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “In these 100 rows, you already know that only 5 are fraudulent; the rest are genuine.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Say the machine has learnt from this, and when we test it, its accuracy is 95%. Would you say the model is classifying the transactions correctly?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Obviously! It’s giving you an accuracy of 95%. Doesn’t that mean it’s performing well?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Well, not obviously. Here’s what happens when the classes are imbalanced…”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “What’s an imbalanced class?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “I’m just getting there. Of these 100 rows, how many are fraudulent and how many aren’t? You know ratios and proportions, tell me.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Umm, it’s 5:95.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Exactly. Do you see that the two classes, fraudulent and not fraudulent, are imbalanced?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Yes.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “When that happens and we don’t teach the machine to pay close attention to this imbalance, it learns poorly. When it starts predicting on new bank transactions, chances are it’s just guessing the majority answer, ‘genuine’, instead of learning patterns from the data.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Ohh, I see what you’re getting at. It performs badly because it’s guessing the most common answer, like I did, and not actually learning.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Something like that.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “But wait, if the accuracy is really good, how do you prove that the machine is guessing?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Before I get there, remember that Positive means fraudulent transactions and Negative means non-fraudulent ones.”&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu9s4kerqa40h2dhcysj0.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu9s4kerqa40h2dhcysj0.png" width="800" height="516"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Confusion Matrix by Author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Got it.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “There are a few other measures that tell us this. Precision tells us, ‘Of all the Positive, or fraudulent, predictions the machine made, how many were actually Positive?’ And Recall tells us, ‘Of all the fraudulent transactions, how many did the model catch?’”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “So back in our example, we had 100 transactions, of which 95 were non-fraudulent. The model mostly kept guessing ‘genuine’ on new transaction data and missed every chance to catch a fraudulent case. Had it learnt how important it is to catch even those 5, it would perform a lot better on new data.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Right, so accuracy wasn’t enough, because we were only looking at how often the model was right and not at what it got wrong. And Recall is the one that tells us about the missed chances.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “True. And Precision tells us how reliable the fraud predictions are: it guards against false alarms, when a model predicts that a case is fraudulent when it’s actually genuine.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “There’s just one more measure, called Specificity. It tells us, ‘Of all the negative, that is non-fraudulent, cases, how many did the machine identify correctly?’”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Amazing! It’s interesting how these machines make human-like mistakes.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Some ideas in machine learning were inspired by how our brains learn, so yes, some of it looks very similar to how humans think and learn.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “So cool! Will you teach me more about machine learning?”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amma:&lt;/strong&gt; “Yes, but first you’ll have to do well on your test. And don’t even think about guessing your way through it: really sit down, learn the concepts, practise, and test yourself every now and then.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Raghav:&lt;/strong&gt; “Yes, Amma, I’ll do that.”&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In your work, which mistake costs more: a missed positive or a false alarm?&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;This was Day 1 of my 30 Days of Data Science writing challenge. Writing an ML concept as a conversation was a fun experiment. Would you like to see more posts in this style?&lt;/p&gt;

</description>
      <category>30daysofdatascience</category>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>beginners</category>
    </item>
    <item>
      <title>I built a Python script that generates writing and coding prompts for my 30-day writing challenge</title>
      <dc:creator>Rupali Gauravaram</dc:creator>
      <pubDate>Tue, 03 Nov 2026 07:07:43 +0000</pubDate>
      <link>https://dev.to/rupaligauravaram/i-built-a-python-script-that-generates-writing-and-coding-prompts-for-my-30-day-writing-challenge-36e4</link>
      <guid>https://dev.to/rupaligauravaram/i-built-a-python-script-that-generates-writing-and-coding-prompts-for-my-30-day-writing-challenge-36e4</guid>
      <description>&lt;p&gt;Lately I’ve realised how much I use and depend on AI tools for basic daily tasks. Not so long ago, I could read articles, study material or novels for hours on end and not lose focus, I could sit down, manually scribble my ideas with pen and paper and write creative content without second guessing every single word I was writing. I feel like the hobbies I enjoyed so much had become a task that needed to be perfected, polished, and needed an AI agent’s approval at every step.&lt;/p&gt;

&lt;p&gt;It’s ironic to think, we hit approve every time an AI agent is getting a task done for us, whereas in reality, we have stopped doing anything without its approval or suggestions. We’ve stopped trusting that our brain can learn, store and retrieve massive amounts of information and knowledge. We’ve stopped believing that we can navigate simple mundane scenarios or solve problems without AI.&lt;/p&gt;

&lt;p&gt;“What you don’t use, you lose”, a phrase that’s been haunting me lately. How often have you caught yourself coming up with a brilliant idea but you immediately had to run it past an LLM to build the idea further or to see if it made sense, that abrupt stop after we get an amazing idea is preventing us from learning, creating and evolving further. I’ve been there too and found myself losing my flair and ability to think creatively. I wanted to change that.&lt;/p&gt;

&lt;p&gt;I’m an architect turned data scientist but I’m also a creative individual who loves a good challenge. I absolutely love writing, programming and building things, so for starters I built myself a Python script that generates writing prompts for my 30-day writing challenge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s how it works:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A list of 60 topics I’m learning as a data scientist, each tagged with a subject and a type (explain, build, compare, debug)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A list of writing rules: two that every post follows, plus two more picked at random to suit the topic’s type&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each run picks a topic I haven’t used yet and keeps a record so nothing repeats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then a simple “show_prompt” function displays the final prompt like in the following example.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuby6jkq4buul00r2d32l.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuby6jkq4buul00r2d32l.png" alt=" " width="800" height="387"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Example prompt generated by the author&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here are some things I found challenging while building the script:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How can I add variety to each consecutive prompt? Randomizing the topic and constraints meant that I had to randomly choose a topic, choose 2 constraints associated with the type of the topic selected (for example: if type was ‘Explain’, I would also need constraints associated with that type and not random constraints for the prompt to make sense). Then I had to combine the default constraints and current prompt constraints into one list and combine it with the selected topic.&lt;/li&gt;
&lt;li&gt;Was there a way to see a prompt but not use it up? Because each run uses up a prompt and saves its id in used, I had to use Python’s argparse module, which lets me add options like --peek that allows me to only “peek” at a prompt.&lt;/li&gt;
&lt;li&gt;What happens when all 60 prompts are used up? Is there a way to reset the generator? For this, I added an argparse option --reset, that allows me to reset the prompt generator to make all 60 prompts available again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This was Day 0 of posting about a tool I built to help myself reach my true potential. I’ll be posting 1 post every day for the next 30 days based on a prompt I get, strictly adhering to the constraints, no skipping it if it’s challenging and no AI to help me write or code.&lt;/p&gt;

&lt;p&gt;In my own way, this is a little revolt against the complacency we’ve willingly embraced in exchange for technological convenience.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Would you join this revolt?&lt;/em&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Rupali-Gauravaram" rel="noopener noreferrer"&gt;
        Rupali-Gauravaram
      &lt;/a&gt; / &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator" rel="noopener noreferrer"&gt;
        dev-prompt-generator
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A small Python script that picks my next data science writing topic, with constraints, for a 30-day challenge.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;dev-prompt-generator&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A small Python script that picks what I write about next. Each run draws one topic I haven't written about yet, from a list of everything I've been learning in data science, and adds a few writing constraints so every post is short and focused.&lt;/p&gt;
&lt;p&gt;I'm using it for a 30-day writing challenge: one post a day, starting 3 Nov 2026. The posts live in &lt;a href="https://github.com/Rupali-Gauravaram/dev-prompt-generator/posts/" rel="noopener noreferrer"&gt;&lt;code&gt;posts/&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How it works&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;topics.json&lt;/code&gt;: 60 topics, each with an &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;area&lt;/code&gt; (Python, SQL, Statistics, ML and more) and &lt;code&gt;type&lt;/code&gt; (explain, build, compare, debug).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;constraints.json&lt;/code&gt;: rules for every post (&lt;code&gt;always&lt;/code&gt;), plus rules picked at random for the topic's type (&lt;code&gt;by_type&lt;/code&gt;, &lt;code&gt;per_draw&lt;/code&gt; of them).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;used.json&lt;/code&gt;: the ids already drawn, so a topic never comes up twice. It is created on the first run and kept out of git.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Run it&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Run it from inside this folder…&lt;/p&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Rupali-Gauravaram/dev-prompt-generator" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>30daysofdatascience</category>
      <category>datascience</category>
      <category>python</category>
      <category>humanlearning</category>
    </item>
  </channel>
</rss>
