<?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>Forem: Sujit Mali</title>
    <description>The latest articles on Forem by Sujit Mali (@sujit_mali).</description>
    <link>https://forem.com/sujit_mali</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%2F782545%2Ff9cf98ce-63a3-4deb-81c5-af61a2f000dd.jpeg</url>
      <title>Forem: Sujit Mali</title>
      <link>https://forem.com/sujit_mali</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/sujit_mali"/>
    <language>en</language>
    <item>
      <title>A real-world walkthrough of regression using coffee, code, and actual data</title>
      <dc:creator>Sujit Mali</dc:creator>
      <pubDate>Wed, 20 May 2026 17:36:04 +0000</pubDate>
      <link>https://forem.com/sujit_mali/a-real-world-walkthrough-of-regression-using-coffee-code-and-actual-data-2250</link>
      <guid>https://forem.com/sujit_mali/a-real-world-walkthrough-of-regression-using-coffee-code-and-actual-data-2250</guid>
      <description>&lt;p&gt;I failed my first stats class in college.&lt;/p&gt;

&lt;p&gt;Not because the math was hard. Because every example in the textbook was about &lt;em&gt;iris flowers&lt;/em&gt; or &lt;em&gt;Boston housing prices&lt;/em&gt; and I couldn't figure out why anyone in real life would care. So the formulas just slid off my brain.&lt;/p&gt;

&lt;p&gt;Years later, I'm a backend dev in Mumbai with a serious filter coffee habit and an even more serious sleep deficit. One Sunday morning, somewhere between my second tumbler of decoction and a half-broken Saturday deploy, I asked myself a question I could actually feel in my body: &lt;strong&gt;does more coffee actually mean I write more code?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That question is what finally taught me linear regression. Not the textbook. Not the YouTube playlist. A Google Sheet, my git log, and 30 cups of filter coffee.&lt;/p&gt;

&lt;p&gt;Here's the whole thing, including the math by hand, the part where I got it wrong, and the Python at the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup (and why I think most tutorials skip it)
&lt;/h2&gt;

&lt;p&gt;Every linear regression tutorial I'd ever opened started with this line:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;y = mx + b&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And then immediately jumped into matrices. Cool. Useless.&lt;/p&gt;

&lt;p&gt;The thing tutorials skip is &lt;strong&gt;what problem are you even trying to solve&lt;/strong&gt;. Linear regression is, at its core, one question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If I know X, can I make a reasonable guess at Y?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's it. If I know the size of a flat in Malad, can I guess the rent? If I know how many standup minutes I sat through, can I guess how many I actually retained? If I know how much coffee I drank today, can I guess how many lines of code I'll commit?&lt;/p&gt;

&lt;p&gt;I'm going to answer that last one.&lt;/p&gt;

&lt;h2&gt;
  
  
  The data I actually collected
&lt;/h2&gt;

&lt;p&gt;For 30 weekdays I tracked two numbers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;X&lt;/strong&gt;: cups of filter coffee I drank that day (one tumbler = one cup, no chai counted)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Y&lt;/strong&gt;: lines of code I committed that day (net additions, from &lt;code&gt;git log --shortstat&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are the first 10 rows. The full 30 are at the bottom of this post if you want to play with them yourself.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Day&lt;/th&gt;
&lt;th&gt;Coffees (X)&lt;/th&gt;
&lt;th&gt;Lines of code (Y)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;287&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;210&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;160&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;40&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;250&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;195&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;360&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&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%2Fr3vnt9a0ihbnh9my75yi.jpeg" 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%2Fr3vnt9a0ihbnh9my75yi.jpeg" alt="scatter plot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before doing any math, Before doing any math, I dropped the numbers into a &lt;a href="https://scatterplotmaker.com" rel="noopener noreferrer"&gt;scatter plot maker&lt;/a&gt; and just sat with it for a minute. &lt;strong&gt;You should always do this first.&lt;/strong&gt; Eyeballs are a free regression model.&lt;br&gt;
 and just looked at it. &lt;strong&gt;You should always do this first.&lt;/strong&gt; Eyeballs are a free regression model.&lt;/p&gt;

&lt;p&gt;What I saw: a clear-ish upward smear. Not a perfect line — day 5 (5 coffees → 305 lines) and day 10 (6 coffees → 360 lines) sit a bit off the trend, and day 7 (zero coffee, 40 lines) was the day there was a 4-hour power cut and I worked off my laptop battery in a café. But overall, more coffee, more code.&lt;/p&gt;

&lt;p&gt;That smear is what linear regression turns into a number.&lt;/p&gt;
&lt;h2&gt;
  
  
  What we're actually trying to find
&lt;/h2&gt;

&lt;p&gt;We want to draw the &lt;strong&gt;single straight line&lt;/strong&gt; that fits this cloud of points as well as possible.&lt;/p&gt;

&lt;p&gt;A line has two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Slope (m)&lt;/strong&gt;: how many lines of code does one extra cup of coffee buy me?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Intercept (b)&lt;/strong&gt;: how many lines of code do I write on a day with zero coffee?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If I find good values for &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, then for any future day, I can plug in my coffee count and get a prediction.&lt;/p&gt;

&lt;p&gt;But "fits as well as possible" — what does that mean? This is the bit that took me embarrassingly long to internalize.&lt;/p&gt;
&lt;h2&gt;
  
  
  The "least squares" idea, explained without the squares
&lt;/h2&gt;

&lt;p&gt;Imagine I draw a random line through the cloud. For each real data point, there's a gap between where the point actually is and where my line &lt;em&gt;thinks&lt;/em&gt; it should be. That gap is called the &lt;strong&gt;residual&lt;/strong&gt; — basically, how wrong the line was for that day.&lt;/p&gt;

&lt;p&gt;If I add up all those gaps, I get a "total wrongness" score. The best line is the one with the smallest score.&lt;/p&gt;

&lt;p&gt;One catch: some gaps are positive (line predicted too low), some are negative (predicted too high). If you just add them, they cancel each other out and you get a line that looks correct on paper but is actually terrible.&lt;/p&gt;

&lt;p&gt;The fix is to &lt;strong&gt;square each gap&lt;/strong&gt; before adding them. Negatives become positives, big mistakes get punished more than small ones, and now you have a real "wrongness" number worth minimizing.&lt;/p&gt;

&lt;p&gt;That's why it's called &lt;strong&gt;least squares regression&lt;/strong&gt;. We're picking the line that makes the sum of squared gaps as small as possible.&lt;/p&gt;

&lt;p&gt;That's the whole intuition. The formulas below are just the calculus result of "find the m and b that minimize that sum."&lt;/p&gt;
&lt;h2&gt;
  
  
  Doing it by hand on 5 data points
&lt;/h2&gt;

&lt;p&gt;Let me use just 5 points so the numbers stay sane:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;Y&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;287&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;210&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 1: averages.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean of X: (2+4+1+3+5)/5 = &lt;strong&gt;3&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Mean of Y: (142+287+95+210+305)/5 = &lt;strong&gt;207.8&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: deviations and products.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For each row I compute &lt;code&gt;(X - meanX)&lt;/code&gt;, &lt;code&gt;(Y - meanY)&lt;/code&gt;, their product, and &lt;code&gt;(X - meanX)²&lt;/code&gt;.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;X&lt;/th&gt;
&lt;th&gt;Y&lt;/th&gt;
&lt;th&gt;X − 3&lt;/th&gt;
&lt;th&gt;Y − 207.8&lt;/th&gt;
&lt;th&gt;product&lt;/th&gt;
&lt;th&gt;(X−3)²&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;td&gt;−1&lt;/td&gt;
&lt;td&gt;−65.8&lt;/td&gt;
&lt;td&gt;65.8&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;287&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;79.2&lt;/td&gt;
&lt;td&gt;79.2&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;95&lt;/td&gt;
&lt;td&gt;−2&lt;/td&gt;
&lt;td&gt;−112.8&lt;/td&gt;
&lt;td&gt;225.6&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;210&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;2.2&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;305&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;97.2&lt;/td&gt;
&lt;td&gt;194.4&lt;/td&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Sums: products = &lt;strong&gt;565.0&lt;/strong&gt;, squared deviations = &lt;strong&gt;10&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: slope.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;m = sum of products / sum of squared deviations
m = 565 / 10
m = 56.5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4: intercept.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;b = meanY - m * meanX
b = 207.8 - 56.5 * 3
b = 207.8 - 169.5
b = 38.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So my fitted line is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;lines_of_code ≈ 56.5 * coffees + 38.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read in English: &lt;strong&gt;every extra cup of coffee buys me ~56 more lines of code, and on a zero-coffee day I'd still grind out about 38 lines.&lt;/strong&gt; That intercept matches my power-cut day pretty well (40 lines).&lt;/p&gt;

&lt;p&gt;I checked this against &lt;a href="https://scatterplotmaker.com/linear-regression-calculator" rel="noopener noreferrer"&gt;an online linear regression calculator&lt;/a&gt; and got the same numbers, which was nice — I'd been low-key worried I'd dropped a sign somewhere. (When you're learning this, do the by-hand version and then verify with a tool. Two methods agreeing is how you know you actually understand it, not just memorized it.)&lt;/p&gt;

&lt;h2&gt;
  
  
  The mistake I made the first time
&lt;/h2&gt;

&lt;p&gt;When I ran this on all 30 days, I got a slope of about 53 and an intercept of about 42. Close enough.&lt;/p&gt;

&lt;p&gt;But then I made a prediction:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"If I drink 15 cups of coffee, I'll write 53 × 15 + 42 = &lt;strong&gt;837 lines of code.&lt;/strong&gt;"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is wrong, and it's wrong in a way that's worth understanding. My data only ranged from 0 to 6 cups of coffee. Predicting for 15 cups is called &lt;strong&gt;extrapolation&lt;/strong&gt;, and a linear model has no idea that at 15 cups I would actually be in the ER, not in VS Code.&lt;/p&gt;

&lt;p&gt;The relationship is probably linear-ish &lt;em&gt;in the range I measured&lt;/em&gt;. Outside that range, all bets are off. Most real-world relationships curve, plateau, or break at some point. Linear regression is a &lt;strong&gt;local&lt;/strong&gt; approximation, not a universal law.&lt;/p&gt;

&lt;p&gt;This is the most common mistake I see beginners make, and honestly it's the most common mistake I see in production dashboards too. "Our user growth was linear for six months, so we'll hit ten lakh users by Q4." No you won't.&lt;/p&gt;

&lt;h2&gt;
  
  
  How good is my line, actually?
&lt;/h2&gt;

&lt;p&gt;A line that's "best" can still be terrible. Imagine if my data were a random cloud — there'd still be a best line, but it would predict nothing useful.&lt;/p&gt;

&lt;p&gt;The standard score for this is &lt;strong&gt;R²&lt;/strong&gt; (pronounced "R squared"). It's a number between 0 and 1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;R² = 1&lt;/strong&gt;: the line passes through every point. Perfect.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R² = 0&lt;/strong&gt;: the line is no better than just guessing the average.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R² = 0.7&lt;/strong&gt;: the line explains about 70% of the variation in Y.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For my 30-day coffee experiment, R² came out to about &lt;strong&gt;0.89&lt;/strong&gt;. That's strong — coffee really does seem to track my coding output. But correlation isn't causation, and here's where I have to be honest: on high-coffee days I was probably also more rested, more motivated, and not stuck in a 90-minute Outer Ring Road jam. The coffee might be a side effect of a productive day, not the cause of one.&lt;/p&gt;

&lt;p&gt;Linear regression will happily fit a line. It will not tell you what causes what. &lt;strong&gt;That's your job.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Python version (5 lines)
&lt;/h2&gt;

&lt;p&gt;Once you understand what's happening, the code is almost a letdown:&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="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&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="mi"&gt;4&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="mi"&gt;3&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;142&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;287&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;210&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;305&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;195&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;slope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;intercept&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;polyfit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;y = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;slope&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;x + &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;intercept&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want R² and the rest of the diagnostics, &lt;code&gt;scipy.stats.linregress&lt;/code&gt; is the friendlier version:&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="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.stats&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;linregress&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;linregress&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slope: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;slope&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;intercept: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;intercept&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;r-squared: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rvalue&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;p-value: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pvalue&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;p-value&lt;/code&gt; is asking: "what's the chance this slope is just noise?" Anything under 0.05 is the traditional cutoff for "probably real." Mine came in at 1e-14, which means: almost certainly not a coincidence. (Doesn't mean coffee &lt;em&gt;causes&lt;/em&gt; code. Just means the relationship is real, whatever it is.)&lt;/p&gt;

&lt;h2&gt;
  
  
  When to reach for linear regression in real life
&lt;/h2&gt;

&lt;p&gt;Honestly, more often than you'd think. Some boring-but-genuinely-useful examples from my own work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Estimating ticket resolution time&lt;/strong&gt; from ticket length. Helps with sprint planning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predicting cloud bill&lt;/strong&gt; from monthly active users. Helps when pricing a new tier — and trust me, the finance team will ask.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Figuring out at what page-load speed users start churning&lt;/strong&gt; on a landing page. The slope tells you how many sign-ups each extra 100ms costs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Calibrating a sensor&lt;/strong&gt;. If your IoT temperature reading drifts linearly off a reference thermometer, regression gives you the correction formula in two lines of Python.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pattern is always the same: you have an X you can measure cheaply, and a Y you actually care about, and you want a quick "if I move the dial on X by this much, what happens to Y?"&lt;/p&gt;

&lt;p&gt;It is not magic. It is a ruler. But it's a ruler that knows about uncertainty, which is more than most rulers can claim.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to try this week
&lt;/h2&gt;

&lt;p&gt;If you want this to actually stick, don't just read it. Pick something annoying in your life that has two numbers attached to it, and track it for two weeks.&lt;/p&gt;

&lt;p&gt;Some ideas to steal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hours of sleep vs. time-to-first-coffee (or chai) the next morning&lt;/li&gt;
&lt;li&gt;Number of standup attendees vs. how long it actually ran&lt;/li&gt;
&lt;li&gt;PRs opened that day vs. PRs you reviewed&lt;/li&gt;
&lt;li&gt;Daily commute minutes vs. how cranky you felt at the 6 PM standup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Plug it into any regression tool (I obviously used &lt;a href="https://scatterplotmaker.com/linear-regression-calculator" rel="noopener noreferrer"&gt;this one&lt;/a&gt;), look at the slope, and ask: &lt;em&gt;does this number match my gut?&lt;/em&gt; If yes, you've quantified your intuition. If no, you've found something interesting.&lt;/p&gt;

&lt;p&gt;That's the whole point of stats, when you strip away the textbook flavor. &lt;strong&gt;It's a tool for arguing with your own assumptions.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The full dataset
&lt;/h2&gt;

&lt;p&gt;If you want to reproduce what I got, here's all 30 days:&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="n"&gt;coffees&lt;/span&gt; &lt;span class="o"&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="mi"&gt;4&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="mi"&gt;3&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&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="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&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="mi"&gt;3&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="mi"&gt;1&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="mi"&gt;3&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="mi"&gt;4&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="mi"&gt;1&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="mi"&gt;4&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="mi"&gt;6&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="mi"&gt;4&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="mi"&gt;5&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;lines&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;142&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;287&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;210&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;305&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;195&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;170&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;225&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;260&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;330&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
           &lt;span class="mi"&gt;205&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;150&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;265&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;310&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;165&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;355&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;270&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;155&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;315&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;210&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;275&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drop those into the snippet above. You should get a slope around 53, intercept around 42, R² around 0.89.&lt;/p&gt;

&lt;p&gt;And then go track something of your own. That's when it actually clicks.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;If you spot a math mistake, please yell at me in the comments. I'd rather be embarrassed than wrong.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Scatter Plots: The "By Hand" Method vs. The 30-Second Shortcut</title>
      <dc:creator>Sujit Mali</dc:creator>
      <pubDate>Mon, 08 Dec 2025 06:14:29 +0000</pubDate>
      <link>https://forem.com/sujit_mali/python-scatter-plots-the-by-hand-method-vs-the-30-second-shortcut-21bk</link>
      <guid>https://forem.com/sujit_mali/python-scatter-plots-the-by-hand-method-vs-the-30-second-shortcut-21bk</guid>
      <description>&lt;p&gt;If you work with data in Python, matplotlib is basically muscle memory at this point. It is the grandfather of Python visualization libraries - powerful, flexible, and capable of doing almost anything if you have enough patience.&lt;/p&gt;

&lt;p&gt;But let’s be honest: sometimes you don't want to write 20 lines of code just to see if two columns of data are correlated.&lt;/p&gt;

&lt;p&gt;I wanted to share a quick refresher on the "standard" way to build a production-ready scatter plot in Matplotlib, and then share a quick browser-based utility I found for when you just need the chart now without firing up a Jupyter Notebook.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: The Matplotlib Way
&lt;/h2&gt;

&lt;p&gt;If you are building a pipeline or need something highly reproducible, you have to code it. Here is the boilerplate I use to get a scatter plot that doesn't look like it was made in 1995.&lt;/p&gt;

&lt;p&gt;We need to handle the data, the labels, the alpha (transparency), and the grid manually.&lt;br&gt;
&lt;/p&gt;

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

# 1. Generate some dummy data
# Let's pretend this is "Page Load Time" vs "User Bounce Rate"
np.random.seed(42)
x = np.random.rand(50) * 10
y = 2 * x + 1 + np.random.randn(50) * 2  # Positive correlation with noise

# 2. Create the figure
plt.figure(figsize=(10, 6))

# 3. The Scatter Plot command
# We add 'alpha' because overlapping points are misleading
# We add 'edgecolors' to make the dots pop
plt.scatter(x, y, color='dodgerblue', alpha=0.7, edgecolors='k', s=100)

# 4. The Styling (The part we always forget)
plt.title('Page Load Time vs. Bounce Rate', fontsize=16)
plt.xlabel('Load Time (seconds)', fontsize=12)
plt.ylabel('Bounce Rate (%)', fontsize=12)
plt.grid(True, linestyle='--', alpha=0.5)

# 5. Show it
plt.show()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works perfectly. But, to get that image, I had to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Spin up my environment.&lt;/li&gt;
&lt;li&gt;Remember the syntax for figsize (is it width, height or height, width?).&lt;/li&gt;
&lt;li&gt;Google how to set the transparency of the grid lines again.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Part 2: The "I Just Need a PNG" Way
&lt;/h2&gt;

&lt;p&gt;Sometimes, I’m just chatting with a PM or a client, and I have a CSV file. I don't want to open VS Code. I just want to visualize the relationship instantly.&lt;/p&gt;

&lt;p&gt;For those moments, I stopped coding it.&lt;/p&gt;

&lt;p&gt;I started using this &lt;a href="https://scatterplotmaker.com/" rel="noopener noreferrer"&gt;Scatter Plot Maker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s effectively a wrapper for the visualization process but without the coding overhead.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You paste your data.&lt;/li&gt;
&lt;li&gt;It handles the axis scaling automatically.&lt;/li&gt;
&lt;li&gt;You get the downloadable image.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I timed it: The Python script took me about 4 minutes to write and debug (mostly formatting the axis labels). The online tool took about 45 seconds.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Verdict?
&lt;/h2&gt;

&lt;p&gt;If you are building a dashboard for a client? &lt;strong&gt;Stick to Python&lt;/strong&gt;. If you just need to visualize a dataset for a presentation, a Slack message, or a quick sanity check? &lt;strong&gt;Save your brain cells and use the generator.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do you guys have any other "no-code" tools you use to skip the boilerplate? Let me know in the comments.&lt;/p&gt;

</description>
      <category>python</category>
      <category>matplotlib</category>
      <category>dataviz</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to import and export functions in JavaScript ?</title>
      <dc:creator>Sujit Mali</dc:creator>
      <pubDate>Wed, 15 Feb 2023 06:34:00 +0000</pubDate>
      <link>https://forem.com/sujit_mali/how-to-import-and-export-functions-in-javascript--1kkf</link>
      <guid>https://forem.com/sujit_mali/how-to-import-and-export-functions-in-javascript--1kkf</guid>
      <description>&lt;p&gt;In this blog, we will discuss how to import and export functions in JavaScript. &lt;/p&gt;

&lt;p&gt;In JavaScript, there are different ways to import and export functions. Here are 2 common ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Default Export&lt;/li&gt;
&lt;li&gt;Named Exports&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  1. Default Export
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// greet.js 
export default function greet(name) {  // EXPORT
  console.log(`Hello, ${name}!`);
}

// app.js
import greet from './greet.js';  // IMPORT
greet('Sam');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we're exporting a function using the export default syntax. This allows us to import the function using any name we want in the importing file, and it doesn't require us to use curly braces when importing. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The export default syntax allows you to export only a single value from a module as the default export.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Named Exports
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// math.js
export function add(a, b) {            // EXPORT
  return a + b;
}

export function subtract(a, b) {      // EXPORT
  return a - b;
}

// app.js
import { add, subtract } from './math.js'; // IMPORTS
console.log(add(3, 4));
console.log(subtract(5, 2));

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

&lt;/div&gt;



&lt;p&gt;In this example, we're exporting two functions (add and subtract) using the named exports syntax. To import these functions, we need to use curly braces and specify the names of the functions we want to import.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; While importing, the Name of the function should be the same as defined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OR&lt;/strong&gt; &lt;br&gt;
Export all function in one line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// math.js
function add(a, b) { 
  return a + b;
}

function subtract(a, b) {      
  return a - b;
}

export { add, subtract };      // EXPORT ALL FUNTION IN ONE LINE

// app.js
import { add, subtract } from './math.js'; // IMPORT

console.log(add(2, 3));
console.log(subtract(5, 3));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>ai</category>
      <category>learning</category>
      <category>career</category>
      <category>discuss</category>
    </item>
    <item>
      <title>How to make a line graph in google sheets?</title>
      <dc:creator>Sujit Mali</dc:creator>
      <pubDate>Fri, 20 Jan 2023 09:59:28 +0000</pubDate>
      <link>https://forem.com/sujit_mali/how-to-make-a-line-graph-in-google-sheets-4ebl</link>
      <guid>https://forem.com/sujit_mali/how-to-make-a-line-graph-in-google-sheets-4ebl</guid>
      <description>&lt;p&gt;To make a line graph in Google Sheets, follow these steps:&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Enter the data
&lt;/h2&gt;

&lt;p&gt;Enter your data in your sheets.&lt;br&gt;
E.g &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lzzkd8bh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4vky94fbyi1g2qyoike.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lzzkd8bh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4vky94fbyi1g2qyoike.png" alt="linegraph" width="364" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Select the data
&lt;/h2&gt;

&lt;p&gt;The second step after the step 1 is to selecting the data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u5iGWx2i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/393sjum213u76n9bpax7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u5iGWx2i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/393sjum213u76n9bpax7.png" alt="linegraph" width="402" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Click on Insert Chart
&lt;/h2&gt;

&lt;p&gt;Click on "Insert Chart" at top toolbar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Uss9mrZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/doxdbbml4kb3g1mhs214.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Uss9mrZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/doxdbbml4kb3g1mhs214.png" alt="linegraph" width="880" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Select the line chart.
&lt;/h2&gt;

&lt;p&gt;Select the chart you want to create. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5zA0UWoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qfnmy0i314sg7d71a9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5zA0UWoB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qfnmy0i314sg7d71a9o.png" alt="linegraph" width="880" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Customize
&lt;/h2&gt;

&lt;p&gt;Final step customize your chart such as Color, Point, Legend, Axis and Text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Iz0qSsxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx1i2z0gum80i2cv8qfc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Iz0qSsxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx1i2z0gum80i2cv8qfc.png" alt="linegraph" width="880" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Download
&lt;/h2&gt;

&lt;p&gt;First select your graph and click on three dots.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7u75GiLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsg2vhryc4e9fodfg93m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7u75GiLi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsg2vhryc4e9fodfg93m.png" alt="linegraph" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally download your graph as png, svg or pdf format.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6tEDRXqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l36k8dalc1x5dpjed2ef.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6tEDRXqz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l36k8dalc1x5dpjed2ef.png" alt="linegraph" width="880" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;OR &lt;br&gt;
You can try &lt;a href="https://linegraphmaker.co/"&gt;line graph maker&lt;/a&gt; to create graph easily.&lt;/p&gt;

</description>
      <category>googlesheet</category>
      <category>linegraph</category>
    </item>
    <item>
      <title>How to read a histogram?</title>
      <dc:creator>Sujit Mali</dc:creator>
      <pubDate>Fri, 20 Jan 2023 06:55:24 +0000</pubDate>
      <link>https://forem.com/sujit_mali/how-to-read-a-histogram-490b</link>
      <guid>https://forem.com/sujit_mali/how-to-read-a-histogram-490b</guid>
      <description>&lt;p&gt;A histogram is a graphical representation of the distribution of a dataset. It is an estimate of the probability distribution of a continuous variable. To read a histogram in detail, you should pay attention to the following elements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The x-axis represents the variable of interest, while the y-axis represents the frequency of that variable.&lt;/li&gt;
&lt;li&gt;The bars of the histogram show the frequency of observations within each class or bin. The height of each bar corresponds to the number of observations that fall within the corresponding class.&lt;/li&gt;
&lt;li&gt;The shape of the histogram can reveal information about the distribution of the data. For example, a symmetric histogram with a bell-shaped curve indicates a normal distribution, while a histogram with a long tail to the right or left indicates a skewed distribution.&lt;/li&gt;
&lt;li&gt;The number of classes or bins can also be important. A histogram with too few classes can make the data appear more variable than it really is, while a histogram with too many classes can make the data appear less variable than it really is.&lt;/li&gt;
&lt;li&gt;The histogram can also be used to identify patterns or outliers in the data by looking for gaps or clusters in the distribution.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Finally, it is important to keep in mind that histograms are just one way of visualizing data, and other types of plots such as box plots, scatter plots, etc might be better suited depending on the context and the question you want to answer.&lt;br&gt;
You can create histogram easily using &lt;a href="https://histogrammaker.co/"&gt;histogram maker.&lt;/a&gt;&lt;/p&gt;

</description>
      <category>chart</category>
      <category>graphs</category>
      <category>histogram</category>
    </item>
  </channel>
</rss>
