<?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 Akshay J1n on Medium]]></title>
        <description><![CDATA[Stories by Akshay J1n on Medium]]></description>
        <link>https://medium.com/@akshayjain_82011?source=rss-3caea8e91884------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Akshay J1n on Medium</title>
            <link>https://medium.com/@akshayjain_82011?source=rss-3caea8e91884------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:16:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshayjain_82011/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[Life’s Pretty easy with SCIKIT-LEARN]]></title>
            <link>https://medium.com/analytics-vidhya/lifes-pretty-easy-with-scikit-learn-5645484eeaa9?source=rss-3caea8e91884------2</link>
            <guid isPermaLink="false">https://medium.com/p/5645484eeaa9</guid>
            <category><![CDATA[tfidf-vectorizer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scikit-learn]]></category>
            <dc:creator><![CDATA[Akshay J1n]]></dc:creator>
            <pubDate>Sat, 11 Jul 2020 17:05:22 GMT</pubDate>
            <atom:updated>2020-07-13T05:05:01.403Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this article well try to implement a sklearn tf-IDF Vectorizer from scratch and cross check the output with the standard library output. SCIKIT-LEARN makes computing very easy by just executing a couple of lines to get the desired output.</h4><blockquote><strong>What does tf-IDF mean?</strong></blockquote><p>Tf-IDF stands for term frequency-inverse document frequency, tf-IDF weight may be a weight often employed in information retrieval and text mining. This weight is a probabilistic measure accustomed to evaluate how important a word is to a document in every collection or corpus. The preponderancy increases proportionally to the myriad times a word appears within the document but is offset by the frequency of the word within the corpus. Variations of the tf-IDF weighing scheme are often made use by search engines as a central tool in scoring and ranking a document’s relevance given a user query.</p><p>One of the best ranking functions is computed by aggregating the tf-IDF for every query term; more state of the art ranking functions are variants of this effortless model.<br> Tf-IDF is outstandingly used for stop-words filtering in various subject fields including text summarization and classification.</p><p><a href="http://www.tfidf.com/"><em>Standard definition take from below website</em></a></p><p><a href="http://www.tfidf.com/">Tf-idf :: A Single-Page Tutorial - Information Retrieval and Text Mining</a></p><blockquote><strong>How to compute?</strong></blockquote><p>Typically, the tf-IDF weight generally consists of two terms: the primary compute the normalized Term Frequency (TF), aka. the several times a word appears in an exceeding document, divided by the entire number of words in this document; the second term is that the Inverse Document Frequency (IDF), computed because of the logarithm of the quantity of the documents within the corpus divided by the number of documents where the particular term appears.</p><p><strong><em>TF:</em></strong> Term Frequency, which measures how customarily a term occurs in a document. Since every document is of different lengths, it is plausible that a term would appear much more time in long documents than shorter ones. Thus, the term frequency is commonly divided by the document length (aka. the overall number of terms within the document) as the simplest way of normalization:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*2Ncy-SAnfmIIoVyjIEIhpA.png" /></figure><p><strong>IDF:</strong> Inverse Document Frequency, which quantifies how cardinal a term is. While computing term frequency, all terms are considered equally pivotal. It is known that certain terms, such as “but”, “a”, and “these”, may appear a lot of times but have little importance. Thus we need to weigh down the recurring terms while scaling up the sparse ones, by computing the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*-G5_ajaApOHH7-MQ-jyD9Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*fLSF394O-h0aKTd3Kr1J_g.png" /></figure><p><strong><em>Example:</em></strong></p><p>Let’s take a review in a corpus having 100 words wherein the word book pops up 5 times. The term frequency for book is then (5 / 100) = 0.05. Now, assume we have 10 million documents in a corpus and the word book appears in one thousand of these. Then, the inverse document frequency is calculated as log(10,000,000 / 1,000) = 4. The tf-IDF weight is the upshot of these quantities: 0.05 * 4 = 0.20.</p><h3>Let’s build a TFIDF Vectorizer &amp; compare its results with Sklearn:</h3><blockquote>compare the results of your own implementation of the TFIDF vectorizer with that of sklearns implementation TFIDF vectorizer.</blockquote><h4>Sklearn does few more tweaks in the implementation of its version of TFIDF vectorizer, so to replicate the exact results you would need to add following things to your custom implementation of TF-IDF vectorizer:</h4><ol><li>Sklearn has its vocabulary generated from IDF sorted in alphabetical order</li><li>Sklearn formula of IDF is different from the standard textbook formula. Here the constant <strong>“1”</strong> is added to the numerator and denominator of the IDF as if an extra document was seen containing every term in the collection exactly once, which prevents zero divisions.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*OrjXken_fK9KtTQk0-Tp3g.png" /></figure><p>3. Sklearn applies L2-normalization on its output matrix.</p><p>4. The final output of the sklearn TF-IDF vectorizer is a sparse matrix.</p><h4>Steps to approach this task:</h4><blockquote>Let’s take a sample corpus:</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68789043fc53738f686974d7cef3a20b/href">https://medium.com/media/68789043fc53738f686974d7cef3a20b/href</a></iframe><ol><li>Write both fit and transform methods for your custom implementation of the TF-IDF vectorizer. Print out the alphabetically sorted vocab after you fit your data and check if its the same as that of the feature names from the sklearn TF-IDF vectorizer.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f9d980691d733ef8d5bd2626400b3e6/href">https://medium.com/media/0f9d980691d733ef8d5bd2626400b3e6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cecb6d60b6e6d5af4d9d7f1c2940877c/href">https://medium.com/media/cecb6d60b6e6d5af4d9d7f1c2940877c/href</a></iframe><p>2. Print out the IDF values from your implementation and check if its the same as that of sklearns TF-IDF vectorizer IDF values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b1f6bdf51a15abfd57e9fe5770075e92/href">https://medium.com/media/b1f6bdf51a15abfd57e9fe5770075e92/href</a></iframe><pre>[&#39;and&#39;, &#39;document&#39;, &#39;first&#39;, &#39;is&#39;, &#39;one&#39;, &#39;second&#39;, &#39;the&#39;, &#39;third&#39;, &#39;this&#39;]</pre><p>3. Once you get your vocab and IDF values to be the same as that of sklearns implementation of the TF-IDF vectorizer, Make sure the output of your implementation is a sparse matrix. Before generating the final output, you need to normalize your sparse matrix using L2 normalization. You can refer to this link <a href="https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.normalize.html">https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.normalize.html</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb77bf5f7315be7c729db2b1132c21d0/href">https://medium.com/media/eb77bf5f7315be7c729db2b1132c21d0/href</a></iframe><pre>[1.91629073, 1.22314355, 1.51082562, 1.0, 1.91629073, 1.91629073, 1.0, 1.91629073, 1.0]</pre><blockquote>Now let’s compare our results by using scikit-learn standard tf-IDF vectorizer function</blockquote><blockquote>scikit-learn really makes our lives easy just by adding a couple of lines of code and we get the same output as we observed above.</blockquote><h3>SKLearn Implementation</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a491003744dc400d810156581ee68dfa/href">https://medium.com/media/a491003744dc400d810156581ee68dfa/href</a></iframe><pre>[&#39;and&#39;, &#39;document&#39;, &#39;first&#39;, &#39;is&#39;, &#39;one&#39;, &#39;second&#39;, &#39;the&#39;, &#39;third&#39;, &#39;this&#39;]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd3dcb20e35d189f9f10117d25f32af2/href">https://medium.com/media/fd3dcb20e35d189f9f10117d25f32af2/href</a></iframe><pre>[1.91629073 1.22314355 1.51082562 1.         1.91629073 1.91629073<br> 1.         1.91629073 1.        ]</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5645484eeaa9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/lifes-pretty-easy-with-scikit-learn-5645484eeaa9">Life’s Pretty easy with SCIKIT-LEARN</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploratory data analysis using Seaborn]]></title>
            <link>https://medium.com/analytics-vidhya/exploratory-data-analysis-using-seaborn-99fec7d0bc4?source=rss-3caea8e91884------2</link>
            <guid isPermaLink="false">https://medium.com/p/99fec7d0bc4</guid>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[seaborn]]></category>
            <dc:creator><![CDATA[Akshay J1n]]></dc:creator>
            <pubDate>Fri, 12 Jun 2020 11:59:51 GMT</pubDate>
            <atom:updated>2020-06-19T16:07:43.157Z</atom:updated>
            <content:encoded><![CDATA[<p>Seaborn can be a Python data visualization library supported matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.</p><h3>The objective of data analysis:</h3><p>To predict whether the patient will survive after 5 years or not based upon the patient’s age, year of treatment and so the amount of positive lymph nodes.</p><h3>Attribute information:</h3><pre>1. Age of patient at time of operation (numerical)<br>2. Patient&#39;s year of operation (year - 1900, numerical)<br>3. Number of positive axillary nodes detected (numerical)<br>4. Survival status (class attribute) 1 = the patient survived 5 years or longer 2 = the patient died within 5 years</pre><h3>Data Description:</h3><pre>The Haberman&#39;s survival dataset contains cases from a study that was conducted between 1958 and 1970 at the University of Chicago&#39;s Billings Hospital on the survival of patients who had undergone surgery for breast cancer.</pre><h3>Keys Features</h3><ul><li>Seaborn is also a statistical plotting library</li><li>it has beautiful default styles</li><li>it’s also designed to work okay with Pandas data frame objects.</li></ul><h3>Installing and getting started</h3><p>To install the most recent release of seaborn, you’ll be able to use pip:</p><p><strong>pip install seaborn</strong></p><p>It’s also possible to put in the released version using conda:<br>conda install seaborn</p><p><strong>conda install seaborn</strong></p><p>Alternatively, you’ll use pip to put in the event version directly from GitHub:</p><p><strong>pip install git+https://github.com/mwaskom/seaborn.git</strong></p><p>Another option would be to clone the Github repository and install from your local copy:</p><p>pip install. Dependencies Python 2.7 or 3.5+</p><h3>Mandatory dependencies</h3><p>NumPy (&gt;= 1.9.3)<br>scipy (&gt;= 0.14.0)<br>matplotlib (&gt;= 1.4.3)<br>pandas (&gt;= 0.15.2)</p><h3>Recommended dependencies</h3><p>statsmodels (&gt;= 0.5.0)</p><p>In[1]:</p><p>libraries needed for analysis</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f5841e9b83d91c0ced8350071a916e92/href">https://medium.com/media/f5841e9b83d91c0ced8350071a916e92/href</a></iframe><p>In[2]:</p><p>load the dataset using pandas</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/612d343dcb021ec5ca6382a8c19c5dc9/href">https://medium.com/media/612d343dcb021ec5ca6382a8c19c5dc9/href</a></iframe><pre>&lt;bound method NDFrame.head of      age  year  nodes  status<br>0     30    64      1       1<br>1     30    62      3       1<br>2     30    65      0       1<br>3     31    59      2       1<br>4     31    65      4       1<br>..   ...   ...    ...     ...<br>301   75    62      1       1<br>302   76    67      0       1<br>303   77    65      3       1<br>304   78    65      1       2<br>305   83    58      2       2</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5aeeb965f1edcb10228d7d7129230858/href">https://medium.com/media/5aeeb965f1edcb10228d7d7129230858/href</a></iframe><pre>[306 rows x 4 columns]&gt;</pre><h3>Data Preparation:</h3><pre>print(cancer.info())</pre><pre>&lt;class &#39;pandas.core.frame.DataFrame&#39;&gt;<br>RangeIndex: 306 entries, 0 to 305<br>Data columns (total 4 columns):<br> #   Column  Non-Null Count  Dtype<br>---  ------  --------------  -----<br> 0   age     306 non-null    int64<br> 1   year    306 non-null    int64<br> 2   nodes   306 non-null    int64<br> 3   status  306 non-null    int64<br>dtypes: int64(4)<br>memory usage: 9.7 KB<br>None</pre><h3>Observations:</h3><ul><li>There are no missing values in the dataset. So no need for data imputation</li><li>The datatype “status” column is an integer. It has to be converted into categorical</li></ul><h3>High-level Statistics</h3><pre>age        year       nodes      status<br>count  306.000000  306.000000  306.000000  306.000000<br>mean    52.457516   62.852941    4.026144    1.264706<br>std     10.803452    3.249405    7.189654    0.441899<br>min     30.000000   58.000000    0.000000    1.000000<br>25%     44.000000   60.000000    0.000000    1.000000<br>50%     52.000000   63.000000    1.000000    1.000000<br>75%     60.750000   65.750000    4.000000    2.000000<br>max     83.000000   69.000000   52.000000    2.000000</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ec42d4c532d8727448f5bfac882b9f0/href">https://medium.com/media/2ec42d4c532d8727448f5bfac882b9f0/href</a></iframe><pre>target variable distribution<br>1    225<br>2     81<br>Name: status, dtype: int64<br>1    0.735294<br>2    0.264706<br>Name: status, dtype: float64</pre><h3>Observations:</h3><ul><li>The age of the patients range from 30(min) to 83(max) with a median of 52</li><li>Although the maximum number of nodes observed is 52 nearly 75% of the patients of have less than 5 nodes and nearly 25% of the patients have 0 nodes</li><li>The dataset contains only a small amount of data(306 rows)</li><li>the status column is biased with 73% of the values as yes i,e. (1)</li></ul><h3>2-D Scatter Plot</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*9Nj_Kc0K6AcY8kNIYytLXA.png" /><figcaption>the output of 2d scatter plot</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78c77e3656db6128c96c146a2411895b/href">https://medium.com/media/78c77e3656db6128c96c146a2411895b/href</a></iframe><h3>Observations:</h3><ul><li>using the scatter plot we cant distinguish much here</li></ul><h3>Multivariate Analysis</h3><pre>&#39;\nPair plot in seaborn plots the scatter plot between every two data columns in a given dataframe.\nIt is used to visualize the relationship between two variables\n&#39;</pre><h3>Pair Plot</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*Qc6iA6EmJ78TPha56s2hqA.png" /><figcaption>the output of the pair plot</figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/41fc70a48604f7b2e6d237b7a9fc2951/href">https://medium.com/media/41fc70a48604f7b2e6d237b7a9fc2951/href</a></iframe><h3>Observations:</h3><ul><li>By scattering the data points between year_of_treatment and positive_lymph_nodes, we can see the better separation between the two classes than other scatter plots.</li></ul><h3>Univariate analysis:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*5V_JyJjBEKWAj0fkrZqdJQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/089fb1b53adcbdb3051defbfcadd09e2/href">https://medium.com/media/089fb1b53adcbdb3051defbfcadd09e2/href</a></iframe><blockquote>#5.1 Distribution plots<br>“””<br>* Distribution plots are used to visually assess how the data points are distributed with respect to its frequency.<br>* Usually the data points are grouped into bins and the height of the bars representing each group increases with increase in the number of data points <br>lie within that group. (histogram)<br>* Probality Density Function (PDF) is the probabilty that the variable takes a value x. (smoothed version of the histogram)<br>* Here the height of the bar denotes the percentage of data points under the corresponding group<br>“””</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*9Qz6bEIcAG6StzBdGbS0YA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f96ff20d71848896c942100b225755a/href">https://medium.com/media/7f96ff20d71848896c942100b225755a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*jP_9RQkaqZcBmIJnWmYKsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*Vj-X47e50QIGyvKTdEGwyQ.png" /></figure><h3>CDF</h3><h3>CDF</h3><pre>[30.  35.3 40.6 45.9 51.2 56.5 61.8 67.1 72.4 77.7 83. ]<br>[0.05228758 0.08823529 0.1503268  0.17320261 0.17973856 0.13398693<br> 0.13398693 0.05882353 0.02287582 0.00653595]<br>[58.  59.1 60.2 61.3 62.4 63.5 64.6 65.7 66.8 67.9 69. ]<br>[0.20588235 0.09150327 0.08496732 0.0751634  0.09803922 0.10130719<br> 0.09150327 0.09150327 0.08169935 0.07843137]<br>[ 0.   5.2 10.4 15.6 20.8 26.  31.2 36.4 41.6 46.8 52. ]<br>[0.77124183 0.09803922 0.05882353 0.02614379 0.02941176 0.00653595<br> 0.00326797 0.         0.00326797 0.00326797]</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d680482e835ed4a838c7cab614a90a70/href">https://medium.com/media/d680482e835ed4a838c7cab614a90a70/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ScVbkysMmkgWeNb8Z36jw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*SPd1eBwdVteUov77uX8LNQ.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49cad5a3c22f5fbaa22bc55838838d7e/href">https://medium.com/media/49cad5a3c22f5fbaa22bc55838838d7e/href</a></iframe><h3>Box Plots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*8oQdyuReAz0JtnAXsOyewA.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4dbf94b3366deab6f33c59e0a1444c1b/href">https://medium.com/media/4dbf94b3366deab6f33c59e0a1444c1b/href</a></iframe><h3>Violin plots</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*g1Sbb1zML30-gO2ZTjRRzQ.png" /></figure><h3>Observation:</h3><ul><li>The number of positive lymph nodes of the survivors is highly dense from 0 to 5.</li><li>Almost 80% of the patients have less than or equal to 5 positive lymph nodes.</li><li>The patients treated after 1966 have a slightly higher chance to survive that the rest. The patients treated before 1959 have a slightly lower chance to survive that the rest.</li></ul><h3>Conclusion</h3><ul><li>By scattering the data points between year and nodes, we can see the better separation between the two classes than other scatter plots.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99fec7d0bc4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/exploratory-data-analysis-using-seaborn-99fec7d0bc4">Exploratory data analysis using Seaborn</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>