<?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" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Spandanbhoi on Medium]]></title>
        <description><![CDATA[Stories by Spandanbhoi on Medium]]></description>
        <link>https://medium.com/@spandanbhoi2004?source=rss-24c89239cd05------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LA4YRoDSdS5gJZcL</url>
            <title>Stories by Spandanbhoi on Medium</title>
            <link>https://medium.com/@spandanbhoi2004?source=rss-24c89239cd05------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 11:47:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@spandanbhoi2004/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Center Data Points and Plot Them in Python]]></title>
            <link>https://medium.com/@spandanbhoi2004/how-to-center-data-points-and-plot-them-in-python-1120e098c911?source=rss-24c89239cd05------2</link>
            <guid isPermaLink="false">https://medium.com/p/1120e098c911</guid>
            <dc:creator><![CDATA[Spandanbhoi]]></dc:creator>
            <pubDate>Wed, 15 Jan 2025 19:22:01 GMT</pubDate>
            <atom:updated>2025-01-16T05:27:04.794Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Introduction</strong></p><p>Centering data means adjusting it so that the average (mean) of each dimension is zero. This is often done before using the data in machine learning or data analysis tasks. In this post, we will learn how to center data points in Python using the <strong>NumPy</strong> library and visualize them with <strong>Matplotlib</strong>.</p><h4>Why is Centering Data Necessary?</h4><ol><li><strong>Improves Model Accuracy</strong>: Many algorithms (like PCA and Linear Regression) assume data is centered around zero, which enhances performance.</li><li><strong>Ensures Numerical Stability</strong>: Centering reduces large value discrepancies, improving the stability of calculations.</li><li><strong>Removes Bias</strong>: It removes the bias introduced by non-zero means, helping the model focus on actual patterns.</li><li><strong>Simplifies Visualization</strong>: Data centered around the origin is easier to visualize and understand.</li><li><strong>Speeds Up Optimization</strong>: Centered data helps models converge faster during training.</li></ol><pre>import numpy as np<br>import matplotlib.pyplot as plt<br>x=np.array([(4,1),(5,4),(6,3),(7,4),(2,-1),(-1,-2),(0,-3),(-1,-4)]).T<br>plt.scatter(x[0,:],x[1,:])<br>plt.axhline(0,color=&#39;k&#39;)<br>plt.axvline(0,color=&#39;k&#39;)<br>x_mean=x.mean(axis=1)<br>plt.scatter(x_mean[0],x_mean[1],color=&#39;r&#39;)<br>plt.grid()<br>plt.plot()</pre><p>This code does the following:</p><ol><li><strong>Creates 2D Data Points</strong>: Defines a set of (x, y) points as columns in a NumPy array and transposes it for easier plotting.</li><li><strong>Plots the Points</strong>: Displays the data points on a scatter plot.</li><li><strong>Adds Axes</strong>: Draws horizontal and vertical lines at y=0y=0y=0 and x=0x=0x=0 for reference.</li><li><strong>Calculates the Mean</strong>: Finds the mean of the points along the X and Y axes.</li><li><strong>Plots the Mean</strong>: Marks the mean as a red point on the scatter plot.</li><li><strong>Adds Grid</strong>: Displays a grid for better visualization.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*cMANoHFQa8NKlVuZBs0VFQ.png" /></figure><pre>def centered(x):<br>    return x-x.mean(axis=1).reshape(2,1)<br>d,n=x.shape<br>x_centered=centered(x)<br>import matplotlib.pyplot as plt<br>plt.scatter(x_centered[0,:],x_centered[1,:])<br>plt.axhline(0,color=&#39;k&#39;)<br>plt.axvline(0,color=&#39;k&#39;)<br>c_mean=x_centered.mean(axis=1)<br>plt.scatter(c_mean[0],c_mean[1],color=&#39;r&#39;)<br>plt.grid()<br>plt.plot()</pre><p><strong>1.Defines a Centering Function</strong>: The centered(x) function subtracts the mean of each row (X and Y coordinates) from the data points to center them around the origin.</p><p>2.<strong>Centers the Data</strong>: The input data x is centered by calling the centered(x) function.</p><p><strong>3.Plots the Centered Points</strong>: Displays the centered data points on a scatter plot.</p><p><strong>4.Calculates the Mean</strong>: Computes the mean of the centered data, which should be very close to (0,0)(0, 0)(0,0).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*QUFsDyfk4lk8PwDQH-1h-A.png" /></figure><p>By centering the data, we ensure that it is adjusted to have zero mean along each dimension. This is an important step in data preprocessing, and visualizing the result helps us better understand how the data is distributed. Try using this method with your own data and see how it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1120e098c911" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>