<?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 BHANUPRAKASH PUJALA on Medium]]></title>
        <description><![CDATA[Stories by BHANUPRAKASH PUJALA on Medium]]></description>
        <link>https://medium.com/@pujalabhanuprakash?source=rss-fc6d83107958------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hsuRqSAY57XKc7vHctJzaQ.png</url>
            <title>Stories by BHANUPRAKASH PUJALA on Medium</title>
            <link>https://medium.com/@pujalabhanuprakash?source=rss-fc6d83107958------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:17:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pujalabhanuprakash/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[A Column with mystery]]></title>
            <link>https://medium.com/@pujalabhanuprakash/a-column-with-mystery-1ba7cb5107f7?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ba7cb5107f7</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Sun, 23 Jul 2023 05:37:26 GMT</pubDate>
            <atom:updated>2023-07-23T05:37:26.369Z</atom:updated>
            <content:encoded><![CDATA[<p>“In a given dataset, if a specific column contains 90 percent of zeros, would you drop the column entirely, or would you apply data processing techniques to handle the zeros? If your answer is yes, please explain your preferred approach for handling the data. Additionally, if you would not drop the column, justify your decision and explore alternative methods to process the column effectively.” ???</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tSn5BjKj32xKZkR1tPdbbQ.png" /></figure><p>In the given dataset, the column representing Base MSRP showed that approximately 90 percent of its values were zeros. To address this issue, we attempted to fill in the missing values using a method called VNR (Value Not Reported). Our approach involved utilizing four features — ‘Make,’ ‘Model,’ ‘Electric Vehicle Type,’ and ‘Clean Alternative Fuel Vehicle (CAFV) Eligibility’ — to deduce and fill in the values for that specific column.</p><pre>#Trying with 4 comination of models(Make Model Electric Vehicle Type)<br>data[&quot;flag_msrp&quot;]=np.where(data[&quot;Base MSRP&quot;]==0,1,0)<br>base_msrp_df=data[data[&quot;flag_msrp&quot;]==0].groupby([&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;,&#39;Clean Alternative Fuel Vehicle (CAFV) Eligibility&#39;])[&#39;Base MSRP&#39;].mean().reset_index()<br>base_msrp_df<br>base_msrp_df.rename(columns={&#39;Base MSRP&#39;:&#39;Base_MSRP_mean&#39;},inplace=True)<br>data=pd.merge(data,base_msrp_df,left_on=[&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;,&#39;Clean Alternative Fuel Vehicle (CAFV) Eligibility&#39;],right_on=[&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;,&#39;Clean Alternative Fuel Vehicle (CAFV) Eligibility&#39;],how=&#39;left&#39;)<br>data[&quot;Base MSRP&quot;]=np.where(data[&quot;flag_msrp&quot;]==1,data[&#39;Base_MSRP_mean&#39;],data[&#39;Base MSRP&#39;])</pre><p>Initially, we covered 10 thousand values by repeating the same process for each combination of the three features. However, after this step, we were still left with 40 thousand values to be imputed. During the analysis, we observed that certain combinations of ‘Make’ and ‘Model’ were not being filled successfully. To address this, we conducted additional research by searching for average values for those specific makers and models on the internet. Subsequently, we used these averages to fill in the missing values for the corresponding rows.</p><pre>#Trying with 3 comination of models(Make Model Electric Vehicle Type)<br>data[&quot;flag_msrp&quot;]=np.where(data[&quot;Base MSRP&quot;].isna(),1,0)<br>base_msrp_df=data[data[&quot;flag_msrp&quot;]==0].groupby([&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;])[&#39;Base MSRP&#39;].mean().reset_index()<br>base_msrp_df<br>base_msrp_df.rename(columns={&#39;Base MSRP&#39;:&#39;Base_MSRP_mean&#39;},inplace=True)<br>data=pd.merge(data,base_msrp_df,left_on=[&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;],right_on=[&#39;Make&#39;,&#39;Model&#39;,&#39;Electric Vehicle Type&#39;],how=&#39;left&#39;)<br>data[&quot;Base MSRP&quot;]=np.where(data[&quot;flag_msrp&quot;]==1,data[&#39;Base_MSRP_mean&#39;],data[&#39;Base MSRP&#39;])</pre><p>As a result of these steps, we were able to reduce the number of missing values to 25 thousand. At this stage, we checked for outliers within the data and found none. Consequently, we proceeded to fill in these 25 thousand remaining values using the mean value.</p><pre># Boolean indexing to filter rows with the specified conditions<br>condition = (data[&quot;Make&quot;] == &quot;TOYOTA&quot;) &amp; (data[&quot;Model&quot;] == &quot;RAV4 PRIME&quot;) &amp; (data[&quot;Model Year&quot;] == 2022)<br><br># Use fillna() to fill missing values in &quot;Base MSRP&quot; column for the specified rows<br>data.loc[condition, &quot;Base MSRP&quot;] = data.loc[condition, &quot;Base MSRP&quot;].fillna(47100)<br>data[&#39;Base MSRP&#39;].isna().sum()</pre><p>By following this approach, we were able to address the issue of the high proportion of zeros in the Base MSRP column effectively, resulting in a dataset with fewer missing values, and a more complete representation of the data for further analysis or modeling.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ba7cb5107f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Diagnostic Plots in Python.]]></title>
            <link>https://medium.com/@pujalabhanuprakash/creating-diagnostic-plots-in-python-6e71f53ffe9a?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e71f53ffe9a</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 11:17:24 GMT</pubDate>
            <atom:updated>2023-06-19T11:17:24.317Z</atom:updated>
            <content:encoded><![CDATA[<p>Diagnostic plots are widely used in data analysis and visualization. In this blog, we will discuss how to generate and interpret these plots using Python, specifically in Jupyter notebooks. We will explore the various types of diagnostic plots and understand their individual purposes. By the end of this blog, you will have a comprehensive understanding of how to effectively utilize diagnostic plots for data analysis in Python. Let’s dive in!</p><h3>what are diagnostic plots?</h3><p>In short, diagnostic plots help us determine visually how our model is fitting the data and if any of the basic assumptions of an OLS model are being violated. We will be looking at four main plots in this post and describe how each of them can be used to diagnose issues in an OLS model. Each of these plots will focus on the <strong>residuals</strong> — or errors — of a model, which is mathematical jargon for the difference between the actual value and the predicted value, i.e., ri=yi−¯yi.</p><p>These 4 plots examine a few different assumptions about the model and the data:</p><p>1) The data can be fit by a line</p><p>2) Errors are normally distributed with mean zero</p><p>3) Errors have constant variance, i.e., homoscedasticity</p><blockquote>homoscedasticity : In statistics, a sequence (or a vector) of random variables is <strong>homoscedastic</strong> .if all its random variables have the same finite variance; this is also known as <strong>homogeneity of variance</strong>. The complementary notion is called <strong>heteroscedasticity</strong>, also known as <strong>heterogeneity of variance.</strong></blockquote><p>4) There are no high leverage points</p><blockquote>high leverage points : A high leverage point, in simple terms, refers to an observation or data point that has a significant influence on the regression model. It is an outlier in the predictor space that can greatly affect the model’s estimated coefficients or predictions. High leverage points have extreme values or unusual combinations of predictor variables, leading them to have a disproportionate impact on the model’s overall fit. These points can distort the regression line, making it crucial to identify and examine them to assess their influence on the model’s results.</blockquote><p>The library or module used to create diagnostic plots in python is</p><pre>from statsmodels.graphics.gofplots import ProbPlot</pre><h3>Residuals vs Fitted</h3><p>First up is the <strong>Residuals vs Fitted</strong> plot. This graph shows if there are any nonlinear patterns in the residuals, and thus in the data as well. One of the mathematical assumptions in building an OLS model is that the data can be fit by a line. If this assumption holds and our data can be fit by a linear model, then we should see a relatively flat line when looking at the residuals vs fitted.</p><pre># model values<br>model_fitted_y = smLR.fittedvalues<br># model residuals<br>model_residuals = smLR.resid<br># normalized residuals<br>model_norm_residuals = smLR.get_influence().resid_studentized_internal<br># absolute squared normalized residuals<br>model_norm_residuals_abs_sqrt = np.sqrt(np.abs(model_norm_residuals))<br># absolute residuals<br>model_abs_resid = np.abs(model_residuals)<br># leverage, from statsmodels internals<br>model_leverage = smLR.get_influence().hat_matrix_diag<br># cook&#39;s distance, from statsmodels internals<br>model_cooks = smLR.get_influence().cooks_distance[0]<br><br>plot_lm_1 = plt.figure()<br>plot_lm_1.axes[0] = sns.residplot(x=model_fitted_y, y=dataframe.columns[-1], data=dataframe,<br>                          lowess=True,<br>                          scatter_kws={&#39;alpha&#39;: 0.5},<br>                          line_kws={&#39;color&#39;: &#39;red&#39;, &#39;lw&#39;: 1, &#39;alpha&#39;: 0.8})<br><br>plot_lm_1.axes[0].set_title(&#39;Residuals vs Fitted&#39;)<br>plot_lm_1.axes[0].set_xlabel(&#39;Fitted values&#39;)<br>plot_lm_1.axes[0].set_ylabel(&#39;Residuals&#39;);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*EaRRRkHrXWf4X3mFIPziDw.png" /><figcaption>Residuals vs Fitted</figcaption></figure><p>An ideal Residuals vs Fitted plot will look like random noise; there won’t be any apparent patterns in the scatterplot and the red line would be horizontal.</p><p>Examine the plot generated using the housing dataset. Notice the bow-shaped line in red? This is an indicator that we are failing to capture some of the non-linear features of the model. In other words, we are <em>underfitting</em> the model. Perhaps the variance in the data might be better captured using the <em>square</em> (or some other non-linear transformation) of one or more of the features. Which feature(s) specifically is beyond the scope of this post.</p><h3>Normal Q-Q Plot</h3><p>This plot shows if the residuals are normally distributed. A <strong>good</strong> normal QQ plot has all of the residuals lying on or close to the red line.</p><pre>QQ = ProbPlot(model_norm_residuals)<br>plot_lm_2 = QQ.qqplot(line=&#39;45&#39;, alpha=0.5, color=&#39;#4C72B0&#39;, lw=1)<br>plot_lm_2.axes[0].set_title(&#39;Normal Q-Q&#39;)<br>plot_lm_2.axes[0].set_xlabel(&#39;Theoretical Quantiles&#39;)<br>plot_lm_2.axes[0].set_ylabel(&#39;Standardized Residuals&#39;);<br># annotations<br>abs_norm_resid = np.flip(np.argsort(np.abs(model_norm_residuals)), 0)<br>abs_norm_resid_top_3 = abs_norm_resid[:3]<br>for r, i in enumerate(abs_norm_resid_top_3):<br>    plot_lm_2.axes[0].annotate(i,<br>                               xy=(np.flip(QQ.theoretical_quantiles, 0)[r],<br>                                   model_norm_residuals[i]));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*e9aLqkfSjjreCpWIZBaREA.png" /></figure><p>Looking at the graph above, there are several points that fall far away from the red line. This is indicative of the errors <strong>not</strong> being normally distributed, in fact our model suffers from “heavy tails”.</p><p>What does this say about the data? We are more likely to see extreme values than to be expected if the data was truly normally distributed.</p><p>In general, there is plenty of wiggle room in violating these assumptions, but it is good to know what assumptions about the data we are violating.</p><h3>Scale-Location</h3><p>This plot is a way to check if the residuals suffer from non-constant variance, aka heteroscedasticity.</p><pre>plot_lm_3 = plt.figure()<br>plt.scatter(model_fitted_y, model_norm_residuals_abs_sqrt, alpha=0.5);<br>sns.regplot(x=model_fitted_y,y= model_norm_residuals_abs_sqrt,<br>              scatter=False,<br>              ci=False,<br>              lowess=True,<br>              line_kws={&#39;color&#39;: &#39;red&#39;, &#39;lw&#39;: 1, &#39;alpha&#39;: 0.8});<br>plot_lm_3.axes[0].set_title(&#39;Scale-Location&#39;)<br>plot_lm_3.axes[0].set_xlabel(&#39;Fitted values&#39;)<br>plot_lm_3.axes[0].set_ylabel(&#39;$\sqrt{|Standardized Residuals|}$&#39;);<br><br># annotations<br>abs_sq_norm_resid = np.flip(np.argsort(model_norm_residuals_abs_sqrt), 0)<br>abs_sq_norm_resid_top_3 = abs_sq_norm_resid[:3]<br>for i in abs_norm_resid_top_3:<br>    plot_lm_3.axes[0].annotate(i,<br>                                 xy=(model_fitted_y[i],<br>                                     model_norm_residuals_abs_sqrt[i]));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*q0F1cLebwB9BLQokmCB1Zg.png" /></figure><p><em>This</em> particular plot (with the housing data) is a tricky one to debug. The more horizontal the red line is, the more likely the data is homoscedastic. While a typical heteroscedastic plot has a sideways “V” shape, our graph has higher values on the left and on the right versus in the middle. This might be caused by not capturing the non-linearities in the model (see Residuals vs Fitted plot) and merits further investigation or model tweaking. The two most common methods of “fixing” heteroscedasticity is using a weighted least squares approach, or using a heteroscedastic-corrected covariance matrix (hccm). Both of these methods are beyond the scope of this post.</p><h3>Residuals vs Leverage</h3><p>Leverage points are nasty buggers. Unlike outliers, which have an unusually large y� value, leverage points have extreme x� values. This may not seem so bad at face value, but it can have damaging effects on the model because the β� coefficients are very sensitive to leverage points. The purpose of the Residuals vs Leverage plot is to identify these problematic observations.</p><pre>plot_lm_4 = plt.figure();<br>plt.scatter(model_leverage, model_norm_residuals, alpha=0.5);<br>sns.regplot(x=model_leverage,y= model_norm_residuals,<br>              scatter=False,<br>              ci=False,<br>              lowess=True,<br>              line_kws={&#39;color&#39;: &#39;red&#39;, &#39;lw&#39;: 1, &#39;alpha&#39;: 0.8});<br>plot_lm_4.axes[0].set_xlim(0, max(model_leverage)+0.01)<br>plot_lm_4.axes[0].set_ylim(-3, 5)<br>plot_lm_4.axes[0].set_title(&#39;Residuals vs Leverage&#39;)<br>plot_lm_4.axes[0].set_xlabel(&#39;Leverage&#39;)<br>plot_lm_4.axes[0].set_ylabel(&#39;Standardized Residuals&#39;);<br><br># annotations<br>leverage_top_3 = np.flip(np.argsort(model_cooks), 0)[:3]<br>for i in leverage_top_3:<br>    plot_lm_4.axes[0].annotate(i,<br>                                 xy=(model_leverage[i],<br>                                     model_norm_residuals[i]));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*ma3p1uwK2sM0nyg2sW86BQ.png" /></figure><p>Fortunately, this arguably one of the easiest plots to interpret. Thanks to <a href="https://en.wikipedia.org/wiki/Cook%27s_distance">Cook’s Distance</a>, we only need to find leverage points that have a distance greater than 0.5. In this plot, we do not have any leverage points that meet this criteria.</p><p>In practice, there may be cases where we may want to remove points with a Cook’s distance of less than 0.5, especially if there are only a few observations compared to the rest of the data. I would argue that removing the point on the far right of the plot should improve the model. If the point is removed, we would re-run this analysis again and determine how much the model improved.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e71f53ffe9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gini Index and Entropy: Unveiling Two Faces of Impurity Measures]]></title>
            <link>https://medium.com/@pujalabhanuprakash/gini-index-and-entropy-unveiling-two-faces-of-impurity-measures-8244d5325a3f?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/8244d5325a3f</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Tue, 30 May 2023 08:11:04 GMT</pubDate>
            <atom:updated>2023-05-30T08:11:04.479Z</atom:updated>
            <content:encoded><![CDATA[<h4>Understanding Impurity Measures in Decision Trees.</h4><p>The Gini index and entropy are both measures used in decision tree algorithms and machine learning to evaluate the impurity or homogeneity of a set of data. While they serve similar purposes, there are differences in their calculations and interpretations. Let’s explore them with examples:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*hAwnSRhn19ECna6cSNTdnw.png" /></figure><h3>Entropy :</h3><blockquote>Entropy measures the impurity of a set by calculating the amount of information or uncertainty in the set. It ranges from 0 to 1, where 0 represents a pure or homogeneous set, and 1 represents a completely impure or heterogeneous set.</blockquote><blockquote><strong>Example: Consider a dataset with two classes, “A” and “B,” and we want to evaluate the impurity of a particular node in a decision tree. Suppose there are 80 instances classified as “A” and 20 instances classified as “B” in that node. To calculate the Gini index, we use the following formula</strong></blockquote><h4>Entropy = -p_A * log2(p_A) — p_B * log2(p_B)</h4><blockquote>Using the probabilities calculated earlier (p_A = 0.8 and p_B = 0.2), we find:</blockquote><blockquote>Entropy = -(0.8 * log2(0.8)) — (0.2 * log2(0.2)) ≈ 0.722</blockquote><h3>Gini Index:</h3><blockquote>The Gini index measures the impurity of a set of data by calculating the probability of misclassifying a randomly chosen element if it were labeled randomly according to the distribution of labels in the set. It ranges from 0 to 1, where 0 represents a pure or homogeneous set, and 1 represents a completely impure or heterogeneous set.</blockquote><blockquote>Example: Using the same dataset as above, to calculate the entropy, we use the following formula:</blockquote><h4>Gini Index = 1 — (p_A² + p_B²)</h4><blockquote>where p_A represents the probability of class A (80/100 = 0.8) and p_B represents the probability of class B (20/100 = 0.2).</blockquote><blockquote>Using the formula, we find:</blockquote><blockquote>Gini Index = 1 — (0.8² + 0.2²) = 0.32</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*EnKnXCoGT_jJGuiqGehEAA.png" /></figure><h4>Advantages and Differences:</h4><blockquote>Gini index is slightly faster to compute than entropy since it does not involve logarithmic calculations.</blockquote><blockquote>Gini index tends to favor splits that result in balanced class distributions, while entropy is more sensitive to imbalanced class distributions.</blockquote><blockquote>Gini index is a linear measure, while entropy is a logarithmic measure.</blockquote><blockquote>Both measures generally lead to similar results, but there may be small differences in the splitting decisions made by decision tree algorithms using Gini index or entropy.</blockquote><blockquote>In this post, we have compared the gini and entropy criterion for splitting the nodes of a decision tree.<br>On the one hand, the gini criterion is much faster because it is less computationally expensive.<br>On the other hand, the obtained results using the entropy criterion are slightly better.<br>Nevertheless, as the results are so similar, it <strong>does not seem to be worth the time invested in training when using the entropy criterion</strong>.</blockquote><h3>Conclusion :</h3><p>In summary, both Gini index and entropy are effective impurity measures, and the choice between them depends on the specific requirements of the problem at hand and the characteristics of the dataset being analyzed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8244d5325a3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The KNN Algorithm: A Lazy Genius]]></title>
            <link>https://medium.com/@pujalabhanuprakash/the-knn-algorithm-a-lazy-genius-f85332003ba0?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/f85332003ba0</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Fri, 19 May 2023 16:41:25 GMT</pubDate>
            <atom:updated>2023-05-19T16:41:25.044Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever thought that being lazy could be productive? Well, it can be with the KNN algorithm! KNN stands for k-nearest neighbors, and it’s a machine learning algorithm that can be used to make predictions. The best part about KNN is that it’s lazy, which means it doesn’t have to do any work until it’s needed. In this blog post, we’ll take a closer look at how KNN works and how it can be used to make predictions.</p><p>“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.” — Bill Gates<br>“I’m not lazy, I’m just on my energy-saving mode.”</p><p>let’s get into the KNN….</p><p>KNN stands for K-nearest neighbors. It is a supervised machine learning algorithm that can be used for both classification and regression tasks. The algorithm works by finding the k-nearest data points in the training dataset for a given new data point and then using the label of the majority of the k-nearest neighbors to predict the label of the new data point.</p><p>KNN classifies the new data points based on the similarity measure of the earlier stored data points. For example, if we have a dataset of tomatoes and bananas. KNN will store similar measures like shape and color. When a new object comes it will check its similarity with the colour (red or yellow) and shape.</p><p>In the k-nearest neighbors (KNN) algorithm, the “k” value refers to the number of nearest neighbors that are considered when making a prediction or classifying a new data point. It is a hyperparameter that needs to be specified before applying the KNN algorithm to a dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*waKQdAXEqI8e4_e92cSxFw.png" /></figure><h4>How does KNN work?</h4><ol><li>Calculate distances: For each data point in the dataset, calculate the distance to the new data point</li></ol><p>We usually use Euclidean distance to calculate the nearest neighbor. If we have two points (x, y) and (a, b). To calculate the distances between the points in the dimensional space we can use many methods. Some of important methods to calculate distance are:</p><p><strong>· Manhattan Distance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/0*rQrwFCNfOi8dW32a.png" /></figure><p><strong>· Euclidean Distance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/0*km46Ys9N_PPJiAXh.png" /></figure><p><strong>· Minkowski Distance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*SJUUK78Q2hmStD85.png" /></figure><p><strong>· Cosine Distance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/0*sewQ01BCHV001XGI.png" /></figure><p><strong>· Hamming Distance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/0*9mp2Tv0lJzn7uvic.png" /></figure><p>2. Sort the distances: Arrange the distances in ascending order, from the smallest to the largest.</p><p>3. Select the nearest neighbors: Choose the “k” data points with the smallest distances. These are the “k” nearest neighbors to the new data point.</p><h4>How to choose K?</h4><blockquote>In real-life problems where we have many points the question arises is how to select the value of K?</blockquote><blockquote>Choosing the right value of K is called parameter tuning and it’s necessary for better results. By choosing the value of K we square root the total number of data points available in the dataset.</blockquote><blockquote>a.<strong> K = sqrt (total number of data points).</strong></blockquote><blockquote>b. <strong>Odd value of K is always selected to avoid confusion between 2 classes.</strong></blockquote><blockquote>Choosing a small value for the “k” parameter in K-nearest neighbors (KNN) algorithm can lead to underfitting, while selecting a high value can lead to overfitting.</blockquote><p>4. Determine the class or value: For classification, count the occurrences of each class label among the “k” nearest neighbors and assign the class label that appears most frequently as the predicted class for the new data point. For regression, calculate the average or weighted average of the values associated with the “k” nearest neighbors and assign it as the predicted value.</p><p>5. Make predictions: Repeat steps 1 to 3 for each new data point in the dataset to make predictions or classify the data points.</p><p>6. Evaluate the model: Assess the performance of the KNN algorithm using appropriate evaluation metrics, such as accuracy or mean squared error, depending on the problem type (classification or regression).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*MnUujo24h1lfRrlRZQpXnA.png" /><figcaption>knn_flow chart</figcaption></figure><p>Here is an example code snippet that demonstrates the implementation of the K-nearest neighbors (KNN) algorithm for both classification and regression tasks using the scikit-learn library in Python.</p><p><a href="https://github.com/Bhanuprakashpujala/KNN_lagy_genious/blob/main/knn.ipynb">KNN_lagy_genious/knn.ipynb at main · Bhanuprakashpujala/KNN_lagy_genious</a></p><h4>Why is K-nearest neighbors (KNN) algorithm called a “lazy” algorithm?</h4><p>Certainly! In simple words, the K-nearest neighbors (KNN) algorithm is called &quot;lazy&quot; because it doesn&#39;t do much work during the training phase. It doesn&#39;t create a generalized model like other algorithms. Instead, it just stores the training data for later use.</p><p>When you want to make a prediction with KNN, it calculates the distances between the new data point and all the stored training data points. It then selects the &quot;k&quot; closest neighbors based on those distances. Finally, it uses the labels or values of those nearest neighbors to make the prediction.</p><p>So, KNN is called &quot;lazy&quot; because it delays most of its computations until prediction time, unlike other algorithms that do more work during the training phase.</p><p><strong>conclusion :</strong></p><p>The strengths of KNN include its simplicity, interpretability, and ability to handle multi-class problems. However, KNN’s performance can be sensitive to the choice of the “k” value and the distance metric used. It can also be computationally expensive for large datasets.</p><p>Overall, KNN is a useful algorithm, especially for smaller datasets or as a baseline model, but it may be outperformed by more advanced algorithms for complex problems with high-dimensional data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f85332003ba0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Magic of Categorical and Continuous Transformations]]></title>
            <link>https://medium.com/@pujalabhanuprakash/the-magic-of-categorical-and-continuous-transformations-94bd8ba37f54?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/94bd8ba37f54</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Sun, 07 May 2023 07:37:04 GMT</pubDate>
            <atom:updated>2023-05-07T07:57:55.421Z</atom:updated>
            <content:encoded><![CDATA[<h4>How They Can Unlock Hidden Patterns in Your Data????</h4><p><strong>Part-2 :</strong></p><blockquote>In the first part we discussed till normalization lets continue with other transformations.</blockquote><blockquote><strong>Robust scaling :</strong></blockquote><blockquote>Robust scaling, also known as median-mad scaling, is a normalization technique used to scale features that contain outliers. It is similar to standardization, but instead of subtracting the mean and dividing by the standard deviation, it subtracts the median and divides by the median absolute deviation (MAD).</blockquote><blockquote>The formula for Robust scaling is as follows:</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*r8FrPAcJnk7CZ04-Y5BEWg.png" /></figure><blockquote>where X is the feature column.</blockquote><blockquote>Robust scaling is robust to outliers because the median and MAD are less affected by outliers than the mean and standard deviation. It is particularly useful when the data contains extreme values, such as in financial data or in medical data with rare diseases.</blockquote><blockquote>Some important points to note about Robust scaling are:</blockquote><blockquote>It scales the data to the range [-1, 1] by default, but can also be customized to scale to other ranges.</blockquote><blockquote>It is computationally expensive compared to min-max and mean normalization, as it requires sorting and calculating the median and MAD.</blockquote><blockquote>It can be applied to both univariate and multivariate data.</blockquote><blockquote>It does not change the shape of the distribution, unlike other normalization techniques.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SAdSXT-_prFZoxLZJ-OC1Q.png" /></figure><h3>Transformers</h3><blockquote>In the context of data analysis and statistics, scaling and transformation are not the same thing, although they may be related.</blockquote><blockquote>Scaling refers to the process of rescaling a variable so that it fits within a specific range, typically between 0 and 1 or -1 and 1. This is often done to standardize variables that have different scales, such as variables measured in different units or with different ranges of values. Scaling does not change the shape of the distribution or the relationship between variables.</blockquote><blockquote>Transformation, on the other hand, refers to the process of applying a mathematical function to a variable in order to change its shape, distribution, or relationship with other variables. Common transformations include taking the logarithm, square root, or reciprocal of a variable. Transformations can be used to make data more normally distributed, to stabilize the variance, or to linearize relationships between variables.</blockquote><blockquote>There are 2 types of Transformations</blockquote><blockquote>Functional Transformation.</blockquote><blockquote>power Transformation.</blockquote><blockquote>let us look deep into every Transformation……</blockquote><h4>Functional Transformations</h4><blockquote>Functional transformations are used to transform the data distribution and can help improve the performance of machine learning models.</blockquote><h4><strong>Quantile Transformation :</strong></h4><blockquote>In statistics, a quantile is a value that separates a set of data into equal-sized subsets, where each subset contains an equal proportion of the data.</blockquote><blockquote>The Quantile Transformer is a method for transforming continuous variables to have a uniform or normal distribution(default will be uniform). It is a type of data normalization that is useful when the data has a skewed or non-normal distribution. The Quantile Transformer works by mapping the original distribution to a specified target distribution, such as a uniform or normal distribution. It does this by ranking(default 1000) the values of the original distribution and then transforming them based on the cumulative distribution function of the target distribution.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*byn0wyn4OKBNbkz3WUuEqg.png" /></figure><blockquote>The resulting transformed data will have the same range as the original data, but will have a more uniform or normal distribution. This can be useful for machine learning algorithms that assume normality or uniformity of the data, or for visualizations that require a more interpretable distribution. The Quantile Transformer is implemented in the scikit-learn library in Python, and has several parameters that can be adjusted to customize the transformation, such as the target distribution, the number of quantiles, and the output range.</blockquote><blockquote>One potential drawback of the Quantile Transformer is that it can be sensitive to outliers in the data, as the ranking of the data values can be affected by extreme values. In such cases, it may be necessary to use a more robust transformation method, such as the Robust Scaler.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7pvhP8JdSU4Yi7vAy1MZ9Q.png" /></figure><h4><strong>Power Transformer :</strong></h4><blockquote>power transformation is typically used to address skewness in the data, which is a common problem in machine learning where the distribution of the data is not symmetric. The power transformer is applied to the data to make the distribution more symmetrical, which can improve the performance of certain machine learning algorithms.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zw2n0P1LFZ-3iCL6QKGouw.png" /></figure><blockquote>The power transformer applies a power transformation of the form x to the power n, where n is a parameter that can be adjusted to achieve the desired transformation. The square function (n=2) is a common choice for the power transformation.</blockquote><blockquote>The power transformer can be used for both univariate and multivariate data. For multivariate data, the power transformation is applied to each feature independently.</blockquote><blockquote>It is important to note that the power transformer should only be applied to strictly positive data, as it will not work correctly with negative values. Additionally, the power transformer can be sensitive to outliers in the data, so it may be necessary to preprocess the data to remove or mitigate the effects of outliers before applying the power transformer.</blockquote><h4>Log Transformation :</h4><blockquote>It applies the natural logarithm function to the data, which can be useful in cases where the data has a skewed distribution. By taking the logarithm of the data, it can become more normally distributed, which can be beneficial for certain machine learning algorithms.</blockquote><blockquote>Here are some key points to keep in mind about the log transformer:</blockquote><blockquote>The logarithm function can be used to compress the range of a variable. This can be useful in cases where there is a large range of values, as it can help to make the differences between values more apparent.</blockquote><blockquote>The logarithm function can also be used to transform skewed distributions into more normal distributions. This is because the logarithm tends to compress larger values more than smaller values, which can help to reduce the impact of extreme values.</blockquote><blockquote>log(10) = 1</blockquote><blockquote>log(100) = 2, and</blockquote><blockquote>log(10000) = 4.</blockquote><blockquote>When using the log transformer, it’s important to ensure that the data is positive, as the logarithm function is undefined for negative values. If the data includes zero values, these can be problematic as well, as the logarithm of zero is undefined. In these cases, it may be necessary to add a small constant to the data before applying the log transformer.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*ftM13MHk6rkC2SOr92sZ_w.png" /></figure><blockquote>In some cases, it may be more appropriate to use other functional transformers, such as the Box-Cox transformer, which can handle a wider range of data distributions. However, the log transformer can be a simple and effective way to transform data in many cases.</blockquote><h3>Power Transformation</h3><blockquote>Power Transformer is a type of transformer used in machine learning to transform features or target variables to follow a Gaussian-like distribution. It helps in improving model performance, especially when the model is sensitive to the distribution of data.</blockquote><blockquote>The two common types of power transformers are Box-Cox and Yeo-Johnson.</blockquote><blockquote>Box-Cox Transformation</blockquote><blockquote>Yeo-Johnson Transformation</blockquote><blockquote>let us look deep into every Transformation……</blockquote><h4>Box-Cox Transformation:</h4><blockquote>Box-Cox transformation is a type of power transformation used to stabilize the variance of a dataset. It is commonly used in statistical modeling and machine learning to transform non-normal dependent variables into a normal distribution. The Box-Cox transformation is named after statisticians George Box and Sir David Cox.</blockquote><blockquote>The Box-Cox transformation involves applying a power function to the original data, where the power to be used is determined by a parameter lambda. The parameter lambda can take on any value, including negative values, and the optimal value of lambda is determined through maximum likelihood estimation.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*rUojVu1FrHjxHgsTBKM2Og.png" /></figure><blockquote>The Box-Cox transformation can be applied only positive data values, and it has the property that as lambda approaches zero, the transformed data approaches a natural logarithm transformation. The Box-Cox transformation is a useful technique for dealing with heteroscedasticity and can improve the performance of linear regression models.</blockquote><blockquote>One potential limitation of the Box-Cox transformation is that it assumes a monotonic relationship between the input and output variables, meaning that the relationship between the variables should be consistent across the entire range of values. If this assumption is violated, other types of transformations, such as the Yeo-Johnson transformation, may be more appropriate.</blockquote><blockquote>Yeo-Johnson Transformation</blockquote><blockquote>The Yeo-Johnson transformation is a variation of the Box-Cox transformation method that can handle both positive and negative data values. It applies a power transformation to the data, but uses a different formula for negative values compared to positive values. Specifically, for positive values x</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_db-jOerh47tVeneOQjMrg.png" /></figure><blockquote>where lambda is a parameter that is chosen to minimize the variance of the transformed data.</blockquote><blockquote>Like the Box-Cox transformation, the Yeo-Johnson transformation can be used to normalize data and make it more suitable for use with certain statistical models. It is often used when the data contains both positive and negative values and the Box-Cox transformation is not applicable.</blockquote><blockquote>Some points to keep in mind about the Yeo-Johnson transformation:</blockquote><blockquote>It is a power transformation method that can handle both positive and negative data values.</blockquote><blockquote>The transformation involves a parameter lambda that is chosen to minimize the variance of the transformed data.</blockquote><blockquote>It can be used to normalize data and make it more suitable for use with certain statistical models.</blockquote><blockquote>It is often used when the data contains both positive and negative values and the Box-Cox transformation is not applicable.</blockquote><blockquote>“Data scientists are well-versed in the art of transformations, using techniques like feature scaling and normalization to turn raw data into meaningful insights. But what about our own personal transformations?</blockquote><blockquote>As we journey through life, we undergo a multitude of changes and evolutions. Our experiences shape us, and we adapt and grow in response to the world around us. But how often do we stop to think about the patterns and trends in our own personal transformations?</blockquote><blockquote>“Absolutely! Just as we use machine learning to transform and analyze data, we can apply similar techniques to better understand our own personal transformations. By developing custom transformations that extract meaningful insights from our personal data, we can gain a deeper understanding of our own behavior, habits, and mindset.</blockquote><h4>Custom Transformation:</h4><blockquote>In machine learning, a custom transformation is a pre-processing step that involves modifying the original dataset to create a new set of features that are more useful for the model. Custom transformations are particularly useful when the standard pre-processing techniques, such as scaling or normalization, are not sufficient to prepare the data for modeling.</blockquote><blockquote>Custom transformations are typically created by data scientists who have a deep understanding of the problem domain and can develop specific transformations that are tailored to the problem at hand. These transformations can range from simple data cleaning steps, such as removing or imputing missing values, to more complex feature engineering steps, such as creating new features from existing ones.</blockquote><blockquote>One of the key advantages of custom transformations is that they can help to improve the accuracy of the model by creating new features that are more informative or relevant to the problem. For example, if we are working with text data, we might create a custom transformation that applies stemming or lemmatization to reduce the number of unique words in the dataset. This can help to improve the performance of the model by reducing the dimensionality of the data.</blockquote><blockquote>To create a custom transformation, data scientists typically follow a process that involves data exploration, feature engineering, and evaluation. This process involves identifying the most relevant features, experimenting with different transformations, and evaluating the performance of the model with the transformed data.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94bd8ba37f54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Magic of Categorical and Continuous Transformations]]></title>
            <link>https://medium.com/@pujalabhanuprakash/the-magic-of-categorical-and-continuous-transformations-351f1b03776?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/351f1b03776</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Tue, 25 Apr 2023 06:41:34 GMT</pubDate>
            <atom:updated>2023-04-25T06:56:24.989Z</atom:updated>
            <content:encoded><![CDATA[<h4>How They Can Unlock Hidden Patterns in Your Data????</h4><h4><strong>What is categorical and continuous and what exactly a Transformations is !!!!!</strong></h4><p>Categorical and continuous are two types of data that are commonly used in data analysis and machine learning.</p><p><strong>Categorical data</strong> is qualitative in nature and represents distinct categories or groups. Examples of categorical data include gender (male/female), race (Caucasian, African American, Asian, etc.), and education level (high school, college, graduate school). Categorical data can be further divided into nominal data, where there is no inherent order or ranking between categories, and ordinal data, where there is a clear ranking between categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*eILiiJWovTwiy6Yja5iZ8g.png" /></figure><p><strong>Continuous data</strong>, on the other hand, is quantitative in nature and represents a range of values that can take on any numeric value within a certain range. Examples of continuous data include height, weight, and temperature. Continuous data can be further divided into interval data, where there is no true zero point (e.g. temperature), and ratio data, where there is a true zero point (e.g. height or weight). <br>for complete information use this link <br><a href="https://medium.com/@pujalabhanuprakash/types-of-data-843d39d54fab">https://medium.com/@pujalabhanuprakash/types-of-data-843d39d54fab</a></p><p>In the context of data analysis or machine learning, transformation refers to the process of modifying or changing the original data to make it more suitable for analysis or modelling.</p><h4>Continuous Data Transformation :</h4><p>Continuous data transformation is the process of converting continuous numerical data, such as temperature or time, into a new form that is easier to analyse or interpret. This transformation may involve scaling the data to a new range, applying a mathematical function to the data, or converting the data to a different measurement unit. Continuous data transformation is useful because it can help to reveal patterns or relationships in the data that may not be immediately apparent. <br>let’s explore some different types of continuous data transformations that are commonly used in data analysis and machine learning.</p><h4><strong>Scaling</strong></h4><p>Scaling is a technique used to normalize the range of features (i.e., the input variables) so that they are on the same scale. When features are on different scales, it can lead to some features having a disproportionate impact on the model’s output, which can in turn negatively affect the model’s accuracy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z7CtD6-C5KTKP7Q8hZnNsg.png" /></figure><p>There are several different methods of feature scaling, including:</p><ol><li><strong>Standardization:<br> </strong>Standardization scaling technique used in machine learning to transform the features so that they have a <strong>mean of zero</strong> and a <strong>standard deviation of one</strong>. This is also known as <strong>“z-score normalization”</strong>. The process involves subtracting the mean of the feature values from each value, and then dividing by the standard deviation. This centers the data around zero and scales it to have a standard deviation of one. <br>The resulting values are called “standardized” or “normalized” values.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*zC0mwalU723ltOQFwLAMeQ.png" /><figcaption>Formula</figcaption></figure><p>Standardization is often used when the data has a normal distribution, but can also be used for non-normal data. It can help with data interpretation, as the resulting standardized values can be easily compared and interpreted across different features. It can also help with machine learning algorithms that assume features are normally distributed and have equal variances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPHnTde05bd3BoEL-sfaug.png" /><figcaption>Before and after Transformations</figcaption></figure><p>Standardization is used even when there are outliers in the data because it is a robust method of feature scaling that is not affected by extreme values as much as other methods like min-max scaling, which is sensitive to outliers.</p><p>When the data contains outliers, the mean and standard deviation may be influenced by those extreme values and may not accurately reflect the central tendency and variability of the data. However, standardization is based on the mean and standard deviation of the data, which are not heavily influenced by outliers, as they are based on the majority of the data. Therefore, standardization can still be effective in scaling the features to have a mean of zero and a standard deviation of one, even if the data contains outliers.</p><h4><strong>Normalization :</strong></h4><p>Normalization is the process of scaling numerical data to fit within a specific range, typically between 0 and 1. It is important in machine learning because it can improve the performance of certain algorithms that are sensitive to the scale of the input data, such as distance-based methods.<br>There are types of normalization let us look into them..</p><ol><li><strong>Min-max normalization :<br></strong>Min-max normalization is a type of normalization technique that is used to transform numeric data in a dataset to a specific range. The process of min-max normalization involves scaling the values of a feature to fit within a range of 0 to 1, where 0 represents the minimum value of the feature and 1 represents the maximum value of the feature.<br>This normalization technique is useful in cases where the range of values in a dataset varies widely, or when the distribution of the values is skewed towards one end of the range. Min-max normalization can be used to improve the performance of some machine learning algorithms that are sensitive to the scale of the input data.</li><li>The formula for min-max normalization is:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmFes4H0-rk6zdI5YQAM1w.png" /></figure><p>where:<br> . X_norm: the normalized value of X</p><ul><li>X: the original value of X</li><li>X_min: the minimum value of X in the dataset</li><li>X_max: the maximum value of X in the dataset</li></ul><p>Some key points to keep in mind about min-max normalization are:</p><ul><li>Min-max normalization can be applied to a single feature or to multiple features in a dataset.</li><li>The resulting range of values after normalization is always between 0 and 1, but the range of the original data may vary.</li><li>This technique is sensitive to outliers, as extreme values can affect the range of the normalized values.</li><li>Min-max normalization is easy to implement and is commonly used in machine learning applications.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kPHnTde05bd3BoEL-sfaug.png" /><figcaption>Before and after min-max scaling</figcaption></figure><p>2. <strong>Mean normalization :</strong><br>Mean normalization is a technique used to normalize the values of a feature/variable such that they have zero mean (average) and equal variance. This method is useful when the data has a large range and contains outliers, making standardization and min-max normalization not suitable.</p><p>The formula for mean normalization is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*vQkXeqFQAKe1cLbohF5uXg.png" /></figure><p>Here are some important points to know about mean normalization that are commonly asked in interviews:</p><ol><li>Mean normalization scales the data to have a mean of zero. This is achieved by subtracting the mean value from each data point.</li><li>After subtracting the mean, the data is divided by the range, or the maximum value minus the minimum value. This brings the range of the data to [-0.5, 0.5].</li><li>Mean normalization can be useful when dealing with sparse data or data with a large range, as it keeps the data within a similar scale.</li><li>Mean normalization can help improve the performance of algorithms that are sensitive to the scale of the input data.</li><li>One limitation of mean normalization is that it does not handle outliers well, as it does not change the range of the data.</li><li>Mean normalization can be applied to both single feature and multiple feature datasets.</li><li>In mean normalization, the resulting values can be negative, which may require additional handling depending on the application.</li><li>Mean normalization can also be combined with other normalization techniques such as standardization and min-max normalization for better results.</li></ol><p>There is no specific module for mean normalization so creating our own method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0ub24dQbcsQbHk91lDJasw.png" /></figure><p>3. <strong>Max absolute normalization :<br> </strong>It scales the data between -1 and 1 by dividing each value with the maximum absolute value in the data set. It is similar to min-max normalization, but instead of dividing by the range of the data, it divides by the maximum absolute value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/233/1*UofoszFGYdy9h4ViZwANWg.png" /></figure><p>Here are some important points about max absolute normalization that could be useful in interviews:</p><ul><li>Max absolute normalization is a scaling technique that transforms data values to fall between -1 and 1.</li><li>Max absolute normalization is useful when the range of the data is unknown or when there are extreme outliers in the data.</li><li>Unlike min-max normalization, max absolute normalization does not take into account the range of the data. This means that the same scaling factor is applied to all values, regardless of their distance from the minimum or maximum value.</li><li>Max absolute normalization is commonly used in image processing and computer vision applications.</li><li>A disadvantage of max absolute normalization is that it is sensitive to outliers in the data. If the maximum absolute value is an outlier, then the scaling factor will be large, which can cause the other values to be scaled down to very small values.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*OS_MwR0zVjhoSV_y7-3ivg.png" /></figure><p>“In summary, we covered a lot of topics in part 1, but there’s still more to learn. In part 2, we’ll focus on the most important and advanced things, so you can gain a better understanding of the subject. Stay tuned for more!”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=351f1b03776" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Impact of PIL on ML Models!!!]]></title>
            <link>https://medium.com/@pujalabhanuprakash/the-impact-of-pil-on-ml-models-6e0ba52b3f09?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e0ba52b3f09</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Sat, 22 Apr 2023 17:18:59 GMT</pubDate>
            <atom:updated>2023-04-22T17:18:59.326Z</atom:updated>
            <content:encoded><![CDATA[<h4>Exploring its Essential Features and Functions.</h4><h4>So, what exactly is PIL and how does it work? In this blog post, we’ll take a closer look at PIL and explore some of the different ways it can be used.</h4><blockquote>If you’re interested in image processing, you may already be familiar with PIL. PIL, short for Python Imaging Library, is a powerful and widely-used library for image processing tasks in Python. It provides a range of features and functions that make it easy to manipulate and enhance images, and it’s a popular choice for developers working on machine learning projects.</blockquote><blockquote>Python has several libraries for working with images, including Matplotlib and PIL. Matplotlib is a popular choice for data visualization, and it includes some basic image manipulation functionality. However, if you’re working on more complex image processing tasks, you may find that PIL is a better choice. In this post, we’ll take a closer look at PIL and explore some of the reasons why you might choose to use it.</blockquote><p><strong>Using matplotlib. image (small i) :</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*fJKf8m3EH31c-8lQRP8LNg.png" /><figcaption>importing the necessary libraries and reading the image using path and imread function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*kFtPUsyYYZ5zhOAM8vDXqQ.png" /><figcaption>showing the actual image using imshow and RGB values in numpy array.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8hWjhQdLXP2celIdwZ9QJQ.png" /><figcaption>“In this snippet, there are three images that demonstrate different colour schemes of RGB. The first image displays the colour red, the second image displays the colour green, and the third image displays a different shade of green.”</figcaption></figure><blockquote>One of the key advantages of PIL over Matplotlib is its support for more advanced image processing tasks. For example, PIL includes functions for blurring, sharpening, and adjusting the contrast of images. Additionally, PIL supports more specialized image processing tasks, such as morphological operations and histogram equalization.</blockquote><p><strong>using PIL module and Image library. (capital I)….</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*mDB9sgyp7rQkMW-CW5FSeg.png" /><figcaption>importing the PIL module and image library and loading the image.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*kFtPUsyYYZ5zhOAM8vDXqQ.png" /><figcaption>showing the image with imshow and RGB values of the image</figcaption></figure><p>lets’ s us look into some important advanced image processing tasks.</p><p><strong>Rotating the image :</strong></p><blockquote>One way that rotation can improve the accuracy of machine learning models is by increasing the amount of training data that is available. By rotating images by different angles, you can effectively generate new training examples that are similar to the original data but have slightly different orientations. This can help to improve the robustness of your model and reduce the risk of overfitting.</blockquote><blockquote>Another way that rotation can be helpful in image pre-processing is by aligning images that are not properly oriented.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/813/1*tI3rEUvJNa-2Iz2ch5ETag.png" /><figcaption>Rotating the image with rotate() method and for complete image using expand =True</figcaption></figure><blockquote>Overall, the rotate( ) method in the PIL library can be a useful tool for image pre-processing and improving the accuracy of machine learning models. However, it should be used carefully and with consideration for the specific needs of your project.</blockquote><p><strong>Transpose and filling the colour :</strong></p><blockquote>Transposing an image can be helpful in image pre-processing because it allows you to flip an image along its diagonal axis. This can be useful for situations where the orientation of an image may be important for classification or feature detection.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlwo_U5OSvUgw0IgeHjJEQ.png" /></figure><blockquote>Filling colour is another useful technique for image pre-processing. This technique involves adding a border around an image and filling the border with a specified colour. This can be helpful for situations where an image may not fully fill the frame or for adding padding around the edges of an image to ensure that all images in your dataset are the same size. Adding a border around an image can also help to improve the accuracy of machine learning models by ensuring that important features are not cut off or lost in the training data.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*DJ9ta6DmF6qsJU9hrQkDXg.png" /><figcaption>filling the colour for rotated image</figcaption></figure><p><strong>Adding the text to image :</strong></p><blockquote>Adding text to image is a fun by using PIL module using ImageDraw, ImageFont libraries. By using this we created memes. Creating memes is a fun activity that I enjoy in my free time. It’s a creative way to express personal feelings or ideas in a humorous way without hurting anyone. In my class, we created many memes and it was a great way to have fun and be creative.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*XvvuWKz4Iw2WA210cRzYBg.png" /><figcaption>adding text to the image using the novaOval text with white colour in the x and y coordinates meets point</figcaption></figure><blockquote>Text can also be used as an additional feature during pre-processing, allowing the model to better differentiate between similar images. For example, if two images are visually similar but have different text labels, the model can learn to distinguish between them more easily.<br><strong>Improved Image Recognition</strong>: Adding text to an image can provide additional context and information that may not be immediately apparent from the visual features of the image alone. For example, labeling the objects in an image can help the model recognize those objects more accurately.</blockquote><pre>[&#39;_Image__transformer&#39;,<br> &#39;__array_interface__&#39;,<br> &#39;__class__&#39;,<br> &#39;__copy__&#39;,<br> &#39;__delattr__&#39;,<br> &#39;__dict__&#39;,<br> &#39;__dir__&#39;,<br> &#39;__doc__&#39;,<br> &#39;__enter__&#39;,<br> &#39;__eq__&#39;,<br> &#39;__exit__&#39;,<br> &#39;__format__&#39;,<br> &#39;__ge__&#39;,<br> &#39;__getattr__&#39;,<br> &#39;__getattribute__&#39;,<br> &#39;__getstate__&#39;,<br> &#39;__gt__&#39;,<br> &#39;__hash__&#39;,<br> &#39;__init__&#39;,<br> &#39;__init_subclass__&#39;,<br> &#39;__le__&#39;,<br> &#39;__lt__&#39;,<br> &#39;__module__&#39;,<br> &#39;__ne__&#39;,<br> &#39;__new__&#39;,<br> &#39;__reduce__&#39;,<br> &#39;__reduce_ex__&#39;,<br> &#39;__repr__&#39;,<br> &#39;__setattr__&#39;,<br> &#39;__setstate__&#39;,<br> &#39;__sizeof__&#39;,<br> &#39;__str__&#39;,<br> &#39;__subclasshook__&#39;,<br> &#39;__weakref__&#39;,<br> &#39;_category&#39;,<br> &#39;_close_exclusive_fp_after_loading&#39;,<br> &#39;_copy&#39;,<br> &#39;_crop&#39;,<br> &#39;_dump&#39;,<br> &#39;_ensure_mutable&#39;,<br> &#39;_exclusive_fp&#39;,<br> &#39;_exif&#39;,<br> &#39;_expand&#39;,<br> &#39;_get_safe_box&#39;,<br> &#39;_getexif&#39;,<br> &#39;_getmp&#39;,<br> &#39;_getxmp&#39;,<br> &#39;_min_frame&#39;,<br> &#39;_new&#39;,<br> &#39;_open&#39;,<br> &#39;_reload_exif&#39;,<br> &#39;_repr_png_&#39;,<br> &#39;_repr_pretty_&#39;,<br> &#39;_seek_check&#39;,<br> &#39;_size&#39;,<br> &#39;alpha_composite&#39;,<br> &#39;app&#39;,<br> &#39;applist&#39;,<br> &#39;apply_transparency&#39;,<br> &#39;bits&#39;,<br> &#39;close&#39;,<br> &#39;convert&#39;,<br> &#39;copy&#39;,<br> &#39;crop&#39;,<br> &#39;custom_mimetype&#39;,<br> &#39;decoderconfig&#39;,<br> &#39;decodermaxblock&#39;,<br> &#39;draft&#39;,<br> &#39;effect_spread&#39;,<br> &#39;encoderconfig&#39;,<br> &#39;encoderinfo&#39;,<br> &#39;entropy&#39;,<br> &#39;filename&#39;,<br> &#39;filter&#39;,<br> &#39;format&#39;,<br> &#39;format_description&#39;,<br> &#39;fp&#39;,<br> &#39;frombytes&#39;,<br> &#39;get_format_mimetype&#39;,<br> &#39;getbands&#39;,<br> &#39;getbbox&#39;,<br> &#39;getchannel&#39;,<br> &#39;getcolors&#39;,<br> &#39;getdata&#39;,<br> &#39;getexif&#39;,<br> &#39;getextrema&#39;,<br> &#39;getim&#39;,<br> &#39;getpalette&#39;,<br> &#39;getpixel&#39;,<br> &#39;getprojection&#39;,<br> &#39;getxmp&#39;,<br> &#39;height&#39;,<br> &#39;histogram&#39;,<br> &#39;huffman_ac&#39;,<br> &#39;huffman_dc&#39;,<br> &#39;icclist&#39;,<br> &#39;im&#39;,<br> &#39;info&#39;,<br> &#39;layer&#39;,<br> &#39;layers&#39;,<br> &#39;load&#39;,<br> &#39;load_djpeg&#39;,<br> &#39;load_end&#39;,<br> &#39;load_prepare&#39;,<br> &#39;load_read&#39;,<br> &#39;map&#39;,<br> &#39;mode&#39;,<br> &#39;palette&#39;,<br> &#39;paste&#39;,<br> &#39;point&#39;,<br> &#39;putalpha&#39;,<br> &#39;putdata&#39;,<br> &#39;putpalette&#39;,<br> &#39;putpixel&#39;,<br> &#39;pyaccess&#39;,<br> &#39;quantization&#39;,<br> &#39;quantize&#39;,<br> &#39;readonly&#39;,<br> &#39;reduce&#39;,<br> &#39;remap_palette&#39;,<br> &#39;resize&#39;,<br> &#39;rotate&#39;,<br> &#39;save&#39;,<br> &#39;seek&#39;,<br> &#39;show&#39;,<br> &#39;size&#39;,<br> &#39;split&#39;,<br> &#39;tell&#39;,<br> &#39;thumbnail&#39;,<br> &#39;tile&#39;,<br> &#39;tobitmap&#39;,<br> &#39;tobytes&#39;,<br> &#39;toqimage&#39;,<br> &#39;toqpixmap&#39;,<br> &#39;transform&#39;,<br> &#39;transpose&#39;,<br> &#39;verify&#39;,<br> &#39;width&#39;]</pre><blockquote>These functions are supported by PIL and I found them using the dir() method, which provides a directory of all the available attributes and methods for the PIL image object.</blockquote><blockquote>Out of all the functions provided by PIL, the most useful functions for improving the accuracy of machine learning models will depend on the specific use case and requirements of our model.</blockquote><blockquote>However, some of the commonly used functions that can help to improve the accuracy of machine learning models are:</blockquote><blockquote><strong>resize( )</strong> : This function allows you to resize the image to a specific size, which can help to standardize the input size of images for the machine learning model. This is important because most machine learning models require consistent input sizes to produce accurate predictions.</blockquote><blockquote><strong>convert( )</strong>: This function can be used to convert the image to a specific colour mode, such as RGB or grayscale. This can be useful for standardizing the input colour mode for the model.</blockquote><blockquote><strong>crop( )</strong>: This function can be used to crop the image to a specific region of interest, which can help to remove any unnecessary background or noise from the image and focus on the relevant features.</blockquote><blockquote><strong>rotate( )</strong>: This function can be used to rotate the image by a specific angle, which can help to increase the diversity of the training data and prevent overfitting.</blockquote><blockquote><strong>transpose( ) </strong>: This function can be used to flip or transpose the image, which can also help to increase the diversity of the training data and prevent overfitting.</blockquote><blockquote><strong>convert(“L”) </strong>or <strong>convert(“l”)</strong>: These methods can be used to convert the image to grayscale or binary mode respectively. This can help to reduce the amount of information in the image and remove any unnecessary colours or features that may not be relevant to the model.</blockquote><p><strong>Overall, the most useful function for improving the accuracy of machine learning models will depend on the specific use case and requirements of the model. It is recommended to experiment with different image processing techniques and compare the results to determine which functions work best for your particular model.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e0ba52b3f09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Difference between Column Transformation and Pipeline in Scikit-Learn”]]></title>
            <link>https://medium.com/@pujalabhanuprakash/understanding-the-difference-between-column-transformation-and-pipeline-in-scikit-learn-4b7fb252b52e?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b7fb252b52e</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Wed, 19 Apr 2023 10:27:33 GMT</pubDate>
            <atom:updated>2023-04-19T10:27:33.703Z</atom:updated>
            <content:encoded><![CDATA[<p>When we want to build a machine learning model or algorithm the first and most important step is data cleaning, scaling and pre-processing. we have 2 types of data [categorical (ordinal, nominal) and numerical =(continuous, discrete) for each type of data we have different type of scaling and pre-processing techniques. It is ok When dealing with a small number of columns in a dataset, it can be reasonable to perform transformations and scaling manually. However, if the dataset has a large number of columns, performing transformations and scaling manually can become challenging and leading to confusion. In such cases, it is recommended to use the column transformation or pipeline functionality of Scikit-Learn, which can handle complex data preprocessing tasks more efficiently and accurately.</p><h3>Column Transformation :</h3><blockquote>Column transformation refers to the process of transforming one or more columns of a dataset to a different representation that may be more suitable for a machine learning model or other analysis. This can involve scaling, normalization, encoding, or other types of transformations.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITceydgsSoYrU6Bos989EQ.png" /></figure><p><strong>Syntax :-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*yol_5OBWoQqeet5HclwbvQ.png" /></figure><h3>Pipeline :</h3><blockquote>a pipeline in machine learning is a series of steps that are taken to process data and build a model. Each step takes input from the previous step and produces output that feeds into the next step. Pipelines are used to automate and streamline the process of building and deploying machine learning models. They help to ensure that the right steps are taken in the right order and that the final output is accurate and reliable.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QjM1LXGDwkt-Hf6hEZzwgQ.png" /></figure><h4>Syntax : -</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*ZZyGyD2JfHKOYq0sHMZXaQ.png" /></figure><p>“Since we already have the column transformer in Scikit-Learn, how does using a pipeline benefit our machine learning workflow?”</p><blockquote>There is difference between column transformer and pipeline</blockquote><blockquote>i.e., The column transformer is used to transform specific columns in a dataset independently, while the pipeline is used to combine multiple steps, including data pre-processing and model training, into a single object. The column transformer is useful for applying different transformations to specific columns, while the pipeline simplifies the machine learning workflow by combining data pre-processing and model training into a single object.<br>The column transformer is useful when dealing with datasets that have a mix of data types, as it allows you to apply different transformations to specific columns. The pipeline, on the other hand, is useful when you want to combine multiple data pre-processing steps and model training into a single object, which can simplify the machine learning workflow and make it easier to reproduce and deploy the model.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*AQ6l6lpDr9XS86xtElFTUA.png" /></figure><blockquote>In summary, the column transformer is used for feature engineering, while the pipeline is used for constructing and optimizing the entire machine learning workflow.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b7fb252b52e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Types of Data]]></title>
            <link>https://medium.com/@pujalabhanuprakash/types-of-data-843d39d54fab?source=rss-fc6d83107958------2</link>
            <guid isPermaLink="false">https://medium.com/p/843d39d54fab</guid>
            <dc:creator><![CDATA[BHANUPRAKASH PUJALA]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 15:35:37 GMT</pubDate>
            <atom:updated>2023-04-18T15:35:37.544Z</atom:updated>
            <content:encoded><![CDATA[<p>What is <strong>DATA</strong> !!!</p><blockquote>Data is a piece of information or fact that can be collected, organized, and analyzed. The data can be any form such as numbers, text, images, sounds, and more.</blockquote><blockquote>Data is broadly divided into two(2) types :</blockquote><h3>1.Qualitative Data.</h3><h3>2.Quantitative Data.</h3><blockquote><strong>Qualitative Data</strong> : Data which can’t be measured in numerical figures, that is descriptive in nature[good, bad, poor, high, low etc.-] called Qualitative data.<br><strong>Examples</strong> : <br>1. Beauty of people (she is so gorgeous).<br>2. Taste preferences (e.g., liking spicy food, preferring sweet desserts).<br>3. Emotions and moods (e.g., happiness, sadness, anxiety).<br>This again divided into 2 — types, <br>1.<strong>Nominal</strong> : is a type of qualitative data that puts things into categories or groups, but these categories don’t have any natural order or ranking.<br>EX :colors, names, city names.<br>2.Ordinal : is a type of qualitative data that has a natural order or ranking between the categories. In other words, ordinal data allows us to rank or order the different categories in terms of their relative position or importance.<br><strong>EX</strong> : <br>1.Educational levels (e.g., elementary school, high school, bachelor’s degree, master’s degree).<br>2.Income ranges (e.g., under $20,000, $20,000-$40,000, $40,000-$60,000, etc.).<br>3.Levels of agreement (e.g., strongly agree, agree, neutral, disagree, strongly disagree).<br>4.Satisfaction levels (e.g., very satisfied, somewhat satisfied, neither satisfied nor dissatisfied, somewhat dissatisfied, very dissatisfied).</blockquote><blockquote><strong>Quantitative Data</strong> : The data which is measured in numerical figures are called quantitative data.<br><strong>Examples</strong> :<br>1. Height, weight, and other physical measurements.<br>2. Test scores, grades, and academic performance data.<br>3. Sales figures, revenue, and profit margins.<br>This is also divided into two types :<br>1.<strong>Discrete</strong> : refers to a type of quantitative data that represents countable, distinct values or whole numbers. In other words, discrete data takes on values that can be counted, but not measured.<br><strong>EX</strong> :<br>1.The number of students in a classroom.<br>2.The number of cars in a parking lot.<br>3.The number of goals scored in a soccer match.<br>4.The number of pets in a household.<br>5.The number of books on a shelf.<br><strong>2.continious : </strong>refers to a type of quantitative data that can take on any value within a certain range or interval. In other words, continuous data can be measured and can have an infinite number of possible values within a given range.<br>EX : <br>1.Height and weight measurements<br>2.Temperature readings<br>3.Time durations<br>4.Distance traveled<br>5.Blood pressure levels</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=843d39d54fab" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>