<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Pranjal's Blog]]></title><description><![CDATA[Pranjal's Blog]]></description><link>https://blog.pvcodes.in</link><generator>RSS for Node</generator><lastBuildDate>Mon, 27 Apr 2026 15:32:22 GMT</lastBuildDate><atom:link href="https://blog.pvcodes.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Predicting Bitcoin Prices with Linear Regression: A Beginner-Friendly Guide]]></title><description><![CDATA[Linear Regression is one of the most fundamental concepts in machine learning and an excellent starting point for beginners. In this blog, we’ll unpack what linear regression is, how it works, and then build a practical model to predict Bitcoin closi...]]></description><link>https://blog.pvcodes.in/bitcoin-price-prediction-linear-regression</link><guid isPermaLink="true">https://blog.pvcodes.in/bitcoin-price-prediction-linear-regression</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[linearregression]]></category><category><![CDATA[AI]]></category><category><![CDATA[Bitcoin]]></category><dc:creator><![CDATA[Pranjal Verma]]></dc:creator><pubDate>Sun, 28 Sep 2025 15:40:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759064375749/6c141d9f-0cff-49fc-aa83-9d87aa7dc89f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Linear Regression is one of the most fundamental concepts in machine learning and an excellent starting point for beginners. In this blog, we’ll unpack what linear regression is, how it works, and then build a practical model to predict Bitcoin closing prices using <strong>historical BTC price data</strong>.</p>
<p><em>Note: The python notebook is been attached, feel free to try it yourself.</em></p>
<hr />
<h2 id="heading-what-is-linear-regression">What is Linear Regression?</h2>
<p>Linear regression is a simple way to understand how one thing affects another. Imagine trying to predict a student’s exam score based on how many hours they study. Linear regression fits a straight line through data points, showing the relationship between study hours (independent variable) and exam scores (dependent variable). This helps predict what the score might be for a given number of study hours by using a simple formula like \(y =  w\cdot x + b\), where \(y\) is the score, \(x\) is the hours studied, \(w\) is how much the score changes with each hour, and \(b\) is the starting point when no hours are studied.</p>
<p>This technique is easy to use and understand, making it popular for many fields like business, healthcare, and tech. It helps you figure out how different factors are connected and predict future outcomes based on past data. Whether you’re using one factor or many, linear regression is a valuable tool to turn data into useful insights quickly and clearly.</p>
<p>More formally, Linear regression models the relationship between one dependent variable \(y\) and one or more independent variables \(x\). It “fits” a straight line (or a hyperplane for multiple features) that best predicts \(y\) from \(x\).</p>
<p>Linear regression models are categorized according to the number of input features (\(x\)) they use.</p>
<ol>
<li><strong>Simple Linear Regression (one feature):</strong></li>
</ol>
<p>$$y = mx+b$$</p><p>where,</p>
<ul>
<li><p>\(x\): feature (independent variable)</p>
</li>
<li><p>\(y\): target (dependent variable)</p>
</li>
<li><p>\(w\): slope parameter</p>
</li>
<li><p>\(b\): intercept</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759061232232/511b07c2-954c-4fca-8a2d-40a81ce4e994.jpeg" alt="Simple Regression Model" class="image--center mx-auto" /></p>
<ol start="2">
<li><p><strong>Multiple Linear Regression (many features):</strong></p>
<p> Multiple Linear Regression models the relationship between a dependent variable and two or more independent variables to understand how multiple factors together influence the outcome. It fits a linear equation that predicts the result based on the combined effects of all input features.</p>
</li>
</ol>
<p>$$y = \vec w \cdot \vec x + b$$</p><p>where,</p>
<ul>
<li><p>\(\vec x\): vector of input features \([x_1, x_2, …, x_n]\)</p>
</li>
<li><p>\(\vec w\): vector of learned weights \([w_1, w_2, …, w_n]\)</p>
</li>
<li><p>\(b\): bias (intercept)</p>
</li>
<li><p>\(y\): predicted output</p>
</li>
<li><p>\(\vec w \cdot \vec x\): the <a target="_blank" href="https://en.wikipedia.org/wiki/Dot_product">dot product</a> of \(\vec w\) and \(\vec x \)</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759061337877/2bcb260c-4a36-469a-a487-ba313b319b14.png" alt="Multiple Regression Model" class="image--center mx-auto" /></p>
<p>This above plot is the 3d representation of Multiple Linear Regression Model, having <code>wt</code>, <code>mpg</code> and <code>year</code> as the feature and target respectively, This images was sourced from - <a target="_blank" href="https://book.stat420.org/multiple-linear-regression.html">stat420.org</a>.</p>
<p>The objective is to find \(\vec w\) and \(b\) that minimize the difference between predicted values \(\hat y\) and actual values \(y\). <strong>So that for any feature variables</strong> (\(\vec x\)) <strong>we are able to predict/compute the target</strong> (\(y\)).</p>
<hr />
<h2 id="heading-measuring-fit-mean-squared-error-mse">Measuring Fit: Mean Squared Error (MSE)</h2>
<p>Mean Squared Error (MSE) is a common way to measure how well a linear regression model fits the data. It calculates the average of the squared differences between the actual values and the values predicted by the model, with lower MSE values indicating better prediction accuracy.</p>
<p>We evaluate how good the predictions are using <strong>Mean Squared Error (MSE):</strong></p>
<p>$$J(\mathbf{w}, b) = \frac{1}{2m} \sum_{i=1}^{m} \big(\hat{y}^{(i)} - y^{(i)}\big)^2$$</p><p>where,</p>
<ul>
<li><p>\(m\) is the number of examples.</p>
</li>
<li><p>\(\hat y\) is the predicted value from the model, \(\hat y=\vec w \cdot \vec x\)</p>
</li>
</ul>
<p>Minimizing this gives us the “best-fit” line.</p>
<hr />
<h2 id="heading-how-does-linear-regression-work">How Does Linear Regression Work?</h2>
<p>Linear regression works by finding the best-fitting straight line through a set of data points that relate an independent variable (input) to a dependent variable (output). This line is defined by an equation that predicts the output based on the input, and the model adjusts this line to minimize the difference between the actual and predicted values, often by using a method called least squares. The goal is to create a simple equation that accurately represents the relationship so it can be used to make predictions on new data.</p>
<p>The most common way to fit parameters is with the <strong>Least Squares Method</strong>, solved via <strong>Gradient Descent</strong>.</p>
<h3 id="heading-gradient-descent-in-a-nutshell">Gradient Descent in a Nutshell</h3>
<p>Gradient descent is an iterative algorithm that updates parameters step by step in the direction that decreases the cost function the fastest.</p>
<p>The updates are:</p>
<p>$$w = w - \alpha \cdot \frac{\partial J}{\partial w}, \quad b = b - \alpha \cdot \frac{\partial J}{\partial b}$$</p><ul>
<li><p>\(\alpha\): learning rate (step size)</p>
</li>
<li><p>\(\frac{\partial J}{\partial w}, \frac{\partial J}{\partial b}\): gradients</p>
</li>
</ul>
<p><strong>The loop continues until the error stabilizes (<em>convergence</em>).</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759061359714/d7a9e5ad-aaa9-4c66-aa1f-41773b21de47.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-why-vectorization-matters">Why Vectorization Matters?</h2>
<p>In machine learning, datasets can have millions of rows. Loops in Python quickly become inefficient. <strong>Vectorization</strong> leverages NumPy’s optimized operations to handle entire vectors or matrices in a single step, making code faster and cleaner.</p>
<ul>
<li><p><strong>Without vectorization (slow loop):</strong></p>
<pre><code class="lang-python">  y_hat = []  
      <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(m):
          pred = <span class="hljs-number">0</span>
          <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> range(n):  
               pred += w[j] * X[i, j]  
               y_hat.append(pred + b)
</code></pre>
</li>
<li><p><strong>With vectorization (fast &amp; concise):</strong></p>
<pre><code class="lang-python">  y_hat = np.dot(X, w) + b
</code></pre>
</li>
</ul>
<p><em>Note: Both produce the same result, but vectorization is significantly faster.</em></p>
<h2 id="heading-case-study-predicting-bitcoin-closing-prices">Case Study: Predicting Bitcoin Closing Prices</h2>
<p>We’ll now apply linear regression on Bitcoin’s historical price data (2014–2024). Explore the dataset for yourself <a target="_blank" href="https://www.kaggle.com/datasets/gallo33henrique/bitcoin-btc-usd-stock-dataset">Kaggle BTC-USD Stock Data</a>.</p>
<p>The dataset includes following features:</p>
<ul>
<li><p><strong>Open</strong> – price at the start of the day</p>
</li>
<li><p><strong>High / Low</strong> – daily maximum and minimum prices</p>
</li>
<li><p><strong>Close</strong> – target (end-of-day price)</p>
</li>
<li><p><strong>Adj Close</strong> – adjusted close; excluded to avoid leakage</p>
</li>
<li><p><strong>Volume</strong> – trading volume</p>
</li>
</ul>
<h3 id="heading-step-0-basic-setup-for-getting-started">Step 0 - Basic setup for getting started</h3>
<ul>
<li><p>Use <a target="_blank" href="https://colab.research.google.com/">Google Colab</a> or setup the Jupyter Notebook locally (<a target="_blank" href="https://jupyter.org/install">guide for local setup</a>).</p>
</li>
<li><p>We are using <code>Pandas</code> and <code>Numpy</code> libraries.</p>
</li>
<li><p>Let’s import these libraries</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> matplotlib.pyplot <span class="hljs-keyword">as</span> plt
</code></pre>
<h3 id="heading-step-1-load-amp-inspect-the-data">Step 1 — Load &amp; Inspect the Data</h3>
<pre><code class="lang-python">df = pd.read_csv(<span class="hljs-string">'BTC-USD_stock_data.csv'</span>)  
df[<span class="hljs-string">'Date'</span>] = pd.to_datetime(df[<span class="hljs-string">'Date'</span>])  
df.set_index(<span class="hljs-string">'Date'</span>, inplace=<span class="hljs-literal">True</span>)  
df.head()
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759053771161/115ffd52-1cb8-4c35-a9e7-7ee5b6163038.png" alt /></p>
<h4 id="heading-checks-before-modeling">Checks Before Modeling</h4>
<ul>
<li><p>Ensure numeric dtypes.</p>
</li>
<li><p>Handle missing values (<code>df.isna().sum()</code>).</p>
</li>
<li><p>Remove duplicates.</p>
</li>
</ul>
<p>Since our dataset is already cleaned, we do not have to worry abot the data sanity</p>
<hr />
<h3 id="heading-step-2-feature-selection-amp-normalization">Step 2 — Feature Selection &amp; Normalization</h3>
<p>We’ll use: <code>Open</code>, <code>High</code>, <code>Low</code>, <code>Volume</code>.<br />Exclude <code>Adj Close</code> (directly derived from <code>Close</code>).</p>
<h4 id="heading-why-normalize">Why Normalize?</h4>
<p>BTC prices and volume differ enormously in scale. Without scaling, training is inefficient. We apply <strong>z-score normalization</strong>:</p>
<p>$$z = \frac{x - \bar x}{\sigma}$$</p><p>where,</p>
<ul>
<li><p>\(\bar x\), mean of the \(x\) and</p>
</li>
<li><p>\(\sigma\), <a target="_blank" href="https://en.wikipedia.org/wiki/Standard_deviation">standard deviation</a> of \(x\).</p>
</li>
</ul>
<pre><code class="lang-python">df = (df - df.mean()) / df.std(ddof=<span class="hljs-number">0</span>)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759054243352/16203a1a-3fee-471f-bfac-91b43bbde05d.png" alt class="image--center mx-auto" /></p>
<p>For our model, the <code>Close</code> attribute in the dataset is the target (\(y\)). Let’s fetch that too.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Create target variable (next day's closing price)</span>
df[<span class="hljs-string">'Target'</span>] = df[<span class="hljs-string">'Close'</span>].shift(<span class="hljs-number">-1</span>)
df[<span class="hljs-string">'Target'</span>] = df[<span class="hljs-string">'Target'</span>].fillna(df[<span class="hljs-string">'Target'</span>].mean())
</code></pre>
<h3 id="heading-step-3-visualizing-trends">Step 3 — Visualizing Trends</h3>
<p>Plot 30-day rolling mean of closing prices:</p>
<pre><code class="lang-python">rolling = df[<span class="hljs-string">'Target'</span>].rolling(window=<span class="hljs-number">30</span>).mean()
plt.figure(figsize=(<span class="hljs-number">12</span>,<span class="hljs-number">4</span>))  
plt.plot(df.index, df[<span class="hljs-string">'Target'</span>], alpha=<span class="hljs-number">0.3</span>, label=<span class="hljs-string">'Close'</span>)  
plt.plot(df.index, rolling, color=<span class="hljs-string">'red'</span>, label=<span class="hljs-string">'30-day Rolling Mean'</span>)  
plt.title(<span class="hljs-string">'Close Price with Rolling Mean'</span>)  
plt.xlabel(<span class="hljs-string">'Date'</span>)  
plt.ylabel(<span class="hljs-string">'Close Price (Standardized)'</span>)  
plt.legend()  
plt.show()
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759054291029/7ec98290-86f8-482f-b8b8-f707c42965f6.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-step-3-extract-feature-and-target">Step 3 - Extract Feature and Target</h3>
<pre><code class="lang-python"><span class="hljs-comment"># Separate features and target</span>
features = df.loc[:, df.columns != <span class="hljs-string">'Target'</span>]
target = df[<span class="hljs-string">'Target'</span>]
print(<span class="hljs-string">f'Feature matrix shape: <span class="hljs-subst">{features.shape}</span>'</span>)
print(<span class="hljs-string">f'Target vector shape: <span class="hljs-subst">{target.shape}</span>'</span>)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759054255992/f019a91d-6cfc-412f-8bb1-4732ece013e6.png" alt /></p>
<h2 id="heading-step-4-building-the-model">Step 4 — Building the Model</h2>
<h3 id="heading-1-prediction-function">1. Prediction Function</h3>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">model_fn</span>(<span class="hljs-params">x, w, b</span>):</span>
    <span class="hljs-string">"""
    Linear regression prediction function.

    Args:
        x: Single Feature Datapoint (1 x n)
        w: Weight vector (n,)
        b: Bias scalar

    Returns:
        y_hat: Predicted values (m,)
    """</span>
    y_hat = np.dot(x, w) + b
    <span class="hljs-keyword">return</span> y_hat
</code></pre>
<p>for example:</p>
<p>\(\vec x = [-1.127270, -1.12714, -1.126278, -1.203614]\)</p>
<p>\(\vec w = [0.18435932, 0.19623844, 0.19707516, 0.20951568, 0.20951568, 0.00232556]\) (Random coefficients)</p>
<p>\(b = 0.000397\)</p>
<p>then,</p>
<p>\(\hat y = x_1 w_1 + x_2 w_2 + x_3 w_3 + x_5 w_5 + b\)</p>
<p>\(\hat y= (-1.127270 \cdot 0.18435932) + (-1.12714 \cdot 0.19623844) + (-1.126278 \cdot 0.19707516) + (-1.203614 \cdot 0.20951568) + 0.000397\)</p>
<p>or we can get the <strong><em>dot product</em></strong> of matrix of \(\vec w\) and \(\vec x\), i.e., \(\hat y= \vec w \cdot \vec x + b\)</p>
<p>\(\vec{x} = \begin{pmatrix} -1.127270 -1.12714 -1.126278 -1.203614 \end{pmatrix} \)</p>
<p>$$\vec{w} = \begin{pmatrix} 0.18435932 \\ 0.19623844 \\ 0.19707516 \\ 0.20951568 \\ 0.20951568 \\ 0.00232556 \end{pmatrix}$$</p><p>\(\vec{x} \cdot \vec{w} = (-1.127270 \cdot 0.18435932) + (-1.12714 \cdot 0.19623844) + (-1.126278 \cdot 0.19707516) + (-1.203614 \cdot 0.20951568) + 0.000397\)</p>
<h3 id="heading-2-cost-function">2. Cost function</h3>
<p>The purpose. is to measure of how bad predictions are using <strong>Mean Squared Error</strong> -</p>
<p>$$J(\mathbf{w}, b) = \frac{1}{2m} \sum_{i=1}^{m} \big(\hat{y}^{(i)} - y^{(i)}\big)^2$$</p><pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">cost_fn</span>(<span class="hljs-params">X, Y, w, b</span>):</span>
    <span class="hljs-string">"""
    Calculate Mean Squared Error cost.

    Args:
        X: Feature matrix
        Y: Target vector
        w: Weight vector
        b: Bias scalar

    Returns:
        cost: Mean squared error
    """</span>
    m = len(X)
    y_hat = model_fn(X, w, b)
    cost = np.sum((y_hat - Y) ** <span class="hljs-number">2</span>) / (<span class="hljs-number">2</span> * m)
    <span class="hljs-keyword">return</span> cost
</code></pre>
<h3 id="heading-3-gradient-computation">3. Gradient Computation</h3>
<p>If \(\hat y= \vec w \cdot \vec x +b\), and cost \(J = \frac {1}{2m} \sum (\hat y - y)^2\). then,</p>
<ul>
<li><p>Residual vector: \(r=\hat y − y = \vec w \cdot \vec x + b − y\), (shape: m,)</p>
</li>
<li><p>Gradient w.r.t. weights \(\vec w\)</p>
<p>  $$\frac{\partial J}{\partial w} = \frac{1}{m} X^\top r$$</p>
</li>
<li><p>Gradient w.r.t bias \(b\)</p>
<p>  $$\frac{\partial J}{\partial b} = \frac{1}{m} \sum_{i=1}^m r_i$$</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">compute_gradient</span>(<span class="hljs-params">X, Y, w, b</span>):</span>
    <span class="hljs-string">"""
    Compute gradients for weights and bias.

    Args:
        X: Feature matrix
        Y: Target vector
        w: Weight vector
        b: Bias scalar

    Returns:
        dl_dw: Gradient with respect to weights
        dl_db: Gradient with respect to bias
    """</span>
    m = len(X)
    y_hat = model_fn(X, w, b)

    <span class="hljs-comment"># Compute gradients</span>
    dl_dw = np.dot(X.T, (y_hat - Y)) / m
    dl_db = np.sum(y_hat - Y) / m

    <span class="hljs-keyword">return</span> dl_dw, dl_db
</code></pre>
<h3 id="heading-4-gradient-descent-algorithm">4. Gradient Descent Algorithm</h3>
<p><strong>Gradient descent core idea</strong></p>
<ul>
<li><p>Repeatedly move <code>w</code> and <code>b</code> in the direction that reduces the cost:</p>
<p>  $$w \leftarrow w - \alpha \cdot dl<em>{dw}, \quad b \leftarrow b - \alpha \cdot dl</em>{db}$$</p>
</li>
<li><p>\(\alpha\)(alpha), the learning rate controls step size:</p>
<ul>
<li><p>Too large → divergence (cost blows up).</p>
</li>
<li><p>Too small → very slow convergence.</p>
</li>
</ul>
</li>
<li><p><strong>Practical training notes</strong></p>
<ul>
<li><p><strong>Initialization</strong>: zeros are fine for linear regression.</p>
</li>
<li><p><strong>Iterations</strong>: monitor cost decrease; don’t blindly run 10k — stop when cost plateaus.</p>
</li>
<li><p><strong>Monitoring</strong>: store <code>cost_history</code> and plot it. Also look at the magnitude of gradients — if gradients are near zero early, learning rate may be too small; if gradients explode, rate is too large.</p>
</li>
<li><p><strong>Early stopping</strong>: stop if validation cost increases (overfitting) or if cost changes less than a small epsilon for many steps.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-step4-start-the-model-training">Step4: Start the model training</h2>
<pre><code class="lang-python"><span class="hljs-comment"># Convert to numpy arrays for efficient computation</span>
X_train = features.to_numpy()
y_train = target.to_numpy()
print(X_train[<span class="hljs-number">0</span>].shape)
<span class="hljs-comment"># Initialize parameters</span>
w_init = np.zeros_like(X_train[<span class="hljs-number">0</span>])
b_init = <span class="hljs-number">0.0</span>

<span class="hljs-comment"># Hyperparameters</span>
alpha = <span class="hljs-number">0.003</span>      <span class="hljs-comment"># Learning rate</span>
iterations = <span class="hljs-number">10000</span>

<span class="hljs-comment"># Train the model</span>
print(<span class="hljs-string">"Training Linear Regression Model..."</span>)
w_final, b_final, cost_history = gradient_descent(
    X_train, y_train, w_init, b_init, alpha, iterations
)

print(<span class="hljs-string">f"\nFinal parameters:"</span>)
print(<span class="hljs-string">f"Weights: <span class="hljs-subst">{w_final}</span>"</span>)
print(<span class="hljs-string">f"Bias: <span class="hljs-subst">{b_final:<span class="hljs-number">.6</span>f}</span>"</span>)
print(<span class="hljs-string">f"Final cost: <span class="hljs-subst">{cost_history[<span class="hljs-number">-1</span>]:<span class="hljs-number">.6</span>f}</span>"</span>)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759060969201/57574cf0-c165-4b87-ae2b-54d0195a8259.png" alt /></p>
<h3 id="heading-learning-curve-subplots-first-30-100-1000-iterations">Learning curve subplots (first 30 / 100 / 1000 iterations)</h3>
<ul>
<li><p><strong>First 30 iterations:</strong> you may see a tiny initial change — this is the model finding an initial descent direction.</p>
</li>
<li><p><strong>First 100 iterations:</strong> if the curve bends downward noticeably, gradient descent is making meaningful progress; verify cost is decreasing smoothly.</p>
</li>
<li><p><strong>First 1000 iterations:</strong> if this has flattened, the model is converging. If it’s still noisy or increasing, reduce the learning rate. <strong>Tip:</strong> plot <code>cost_history</code> on a log scale if values span orders of magnitude — that often makes convergence behavior easier to read.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759060979196/ad956d8d-cf51-4d76-b853-eb30391ed68b.png" alt /></p>
</li>
</ul>
<h3 id="heading-prediction-vs-actual-two-panel-explanation">Prediction vs Actual — two-panel explanation</h3>
<p>The below plot show scatter plot that compares the actual values against the predicted values generated by the linear regression model. Points clustering closely along the diagonal red dashed line indicate strong agreement between predicted and real values</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1759065137576/fafbdd8c-34ce-411a-bed8-3f2f0b03cd03.png" alt class="image--center mx-auto" /></p>
<p>The second panel presents a time series plot showing how the predicted and actual values evolve over time. By plotting standardized prices on the same timeline, it demonstrates how well the model tracks real-world changes, making it easier to observe periods of strong prediction and potential deviations. Together, these visualizations provide a comprehensive view of the model’s performance both in terms of point-by-point accuracy and temporal consistency.</p>
<hr />
<h3 id="heading-link-to-the-notebook">Link to the notebook:</h3>
<ul>
<li><p>Jupyter notebook - <a target="_blank" href="https://colab.research.google.com/github/pvcodes/ml/blob/main/btc_price_prediction.ipynb">pvcodes/bitcoin-price-prediction</a></p>
</li>
<li><p>HTML Version - <a target="_blank" href="https://github.com/pvcodes/ml/blob/main/btc_price_prediction.ipynb/">github/pvcodes/bitcoin-price-prediction</a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[What is ML? Supervised vs Unsupervised Learning]]></title><description><![CDATA[Why Does Machine Learning Matter in Today’s Landscape?
Machine learning powers many of the apps and services we rely on daily—from Uber’s dynamic pricing to Netflix’s personalized recommendations. Whether it’s Gmail’s spam filters, fraud detection in...]]></description><link>https://blog.pvcodes.in/what-is-ml-supervised-vs-unsupervised-learning</link><guid isPermaLink="true">https://blog.pvcodes.in/what-is-ml-supervised-vs-unsupervised-learning</guid><category><![CDATA[Machine Learning]]></category><category><![CDATA[Computer Science]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Pranjal Verma]]></dc:creator><pubDate>Fri, 19 Sep 2025 13:08:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758287502495/a2b2172c-ea40-465f-a92f-004de3fc92dd.avif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-why-does-machine-learning-matter-in-todays-landscape">Why Does Machine Learning Matter in Today’s Landscape?</h3>
<p>Machine learning powers many of the apps and services we rely on daily—from Uber’s <strong>dynamic pricing</strong> to Netflix’s <strong>personalized recommendations</strong>. Whether it’s Gmail’s <strong>spam filters</strong>, fraud detection in banking, or voice assistants like <strong>Siri and Alexa</strong>, ML quietly works behind the scenes to deliver smarter, faster, and more personalized experiences.</p>
<p>With the recent <strong>AI boom</strong>, terms like Artificial Intelligence (AI) and Machine Learning (ML) have become mainstream. But ML isn’t new—it has been evolving for decades, shaping how computers learn from data and improve over time.</p>
<p>At its core, machine learning is about teaching computers to <strong>learn from experience</strong> rather than relying solely on explicit programming. These techniques span everything from simple statistics to complex neural networks. For those interested, <a target="_blank" href="https://blog.bccresearch.com/brief-history-of-machine-learning?utm_source=chatgpt.com"><em>How Did We Get Here? A Brief History of Machine Learning</em></a> offers a historical perspective, while <a target="_blank" href="https://machinelearningbook.com"><strong>Fundamentals of Machine Learning for Predictive Data Analytics</strong></a> is a great textbook resource.</p>
<p>In practice, ML usually involves two steps:</p>
<ol>
<li><p><strong>Training</strong> a model with algorithms and example data, so it learns the relationship between inputs and outputs.</p>
</li>
<li><p><strong>Deploying</strong> the model into applications to make predictions or decisions in real-time and at scale.</p>
</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758286443429/f019e952-c730-4e3e-99fc-a10bae27b3ce.png" alt="Train a model" class="image--center mx-auto" /></p>
<p>This naturally leads us to two core branches of ML: <strong>Supervised</strong> and <strong>Unsupervised</strong> learning. But before we dive into them, let’s clarify some common terminologies.</p>
<h3 id="heading-terminologies-in-machine-learning">Terminologies in Machine Learning</h3>
<ol>
<li><p><strong>Dataset</strong> – A collection of data used to train and test models (e.g., patient records, emails, or images).</p>
</li>
<li><p><strong>Feature (Input Variable)</strong> – An attribute or characteristic used by the model (e.g., a person’s age, height, or income).</p>
</li>
<li><p><strong>Target (Label/Output Variable)</strong> – The value we want the model to predict (e.g., “spam” or “not spam,” house price).</p>
</li>
<li><p><strong>Model</strong> – The mathematical representation learned from data that maps inputs (features) to outputs (targets).</p>
</li>
<li><p><strong>Training</strong> – The process of feeding a dataset to the algorithm so it can learn patterns.</p>
</li>
<li><p><strong>Testing</strong> – Evaluating the model’s performance on unseen data to check how well it generalizes.</p>
</li>
</ol>
<hr />
<h3 id="heading-supervised-and-unsupervised-learning">Supervised and Unsupervised Learning</h3>
<p>When we talk about machine learning, most problems fall into two broad categories: <strong>supervised</strong> and <strong>unsupervised</strong> learning.</p>
<p><strong>Supervised Learning</strong> - Think of this like a teacher guiding a student. You provide the algorithm with <strong>input data</strong> and the <strong>correct answers (labels)</strong>, and the model learns to map one to the other. For example, if you feed in house features (size, location, number of rooms) along with actual house prices, the model will eventually learn how to predict the price of a new house.<br />Some common techniques here include <em>Linear Regression</em>, <em>Logistic Regression</em>, <em>Decision Trees</em>, and <em>Neural Networks</em>.</p>
<p><strong>Unsupervised Learning</strong> - Now imagine exploring a new city without a tour guide. You don’t have labels telling you what’s what — instead, you look for <strong>patterns and groupings</strong> on your own. That’s what unsupervised learning does: it takes unlabeled data and finds hidden structures within it. For example, given a pile of customer purchase histories, the algorithm might group customers with similar buying habits together — even if no one told it what those groups should look like.<br />Popular approaches include <em>Clustering</em>, <em>Dimensionality Reduction</em>, and <em>Association Rule Learning</em>.</p>
<hr />
<h3 id="heading-when-to-use-supervised-vs-unsupervised-learning">When to Use: Supervised vs. Unsupervised Learning</h3>
<ul>
<li><p><strong>Supervised Learning</strong> – Best for problems with <strong>known outcomes</strong> and labeled data.<br />  Examples: spam email classification, image recognition, stock price prediction.</p>
</li>
<li><p><strong>Unsupervised Learning</strong> – Best when the data is <strong>unlabeled</strong> and the goal is to explore patterns, group similar instances, or detect anomalies.<br />  Examples: organizing large data archives, building recommendation systems, customer segmentation.</p>
</li>
</ul>
<hr />
<h3 id="heading-summary-of-differences-supervised-vs-unsupervised-learning">Summary of Differences: Supervised vs. Unsupervised Learning</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Aspect</td><td>Supervised Learning</td><td>Unsupervised Learning</td></tr>
</thead>
<tbody>
<tr>
<td><strong>What is it?</strong></td><td>Train the model with input data <strong>paired with labeled outputs</strong>.</td><td>Train the model to <strong>discover hidden patterns</strong> in unlabeled data.</td></tr>
<tr>
<td><strong>Techniques</strong></td><td>Logistic Regression, Linear Regression, Decision Tree, Neural Networks.</td><td>Clustering, Association Rule Learning, Probability Density, Dimensionality Reduction.</td></tr>
<tr>
<td><strong>Goal</strong></td><td>Predict an output based on known inputs.</td><td>Identify relationships or patterns between input data points.</td></tr>
<tr>
<td><strong>Approach</strong></td><td>Minimize the error between predicted outputs and true labels.</td><td>Find patterns, similarities, or anomalies within the data.</td></tr>
</tbody>
</table>
</div><h3 id="heading-conclusion">Conclusion</h3>
<p>Machine learning is reshaping how we live and work—powering smarter apps, real-time decisions, and innovations across industries. With emerging trends like automated ML, explainable AI, and even quantum integration, its future impact will be even greater.</p>
<p>For professionals and businesses, understanding ML is no longer optional—it’s essential for staying relevant in a data-driven world.</p>
<p><em>Ever wondered how machines predict house prices or stock trends?</em> In the next blog, we’ll break it down with <strong>Linear Regression</strong>—one of the simplest yet most powerful ML techniques.</p>
<p>Sign up for the <a target="_blank" href="https://blog.pvcodes.in/newsletter">newsletter</a> to ensure you don't miss out on the next blog.</p>
]]></content:encoded></item></channel></rss>