<?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 Kosta Tzioumis on Medium]]></title>
        <description><![CDATA[Stories by Kosta Tzioumis on Medium]]></description>
        <link>https://medium.com/@kosta.tzioumis?source=rss-62ea1c30fdd0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1jcN4Yr0P034iYuL.jpg</url>
            <title>Stories by Kosta Tzioumis on Medium</title>
            <link>https://medium.com/@kosta.tzioumis?source=rss-62ea1c30fdd0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 15:32:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kosta.tzioumis/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[The Cold Foot Investor]]></title>
            <link>https://medium.com/analytics-vidhya/the-cold-foot-investor-82da6c0baff0?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/82da6c0baff0</guid>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[lending-club]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Tue, 07 Jan 2020 17:36:29 GMT</pubDate>
            <atom:updated>2020-01-09T12:50:16.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u9mz6yF7ar-zwkb_" /><figcaption>Photo by <a href="https://unsplash.com/@f7photo?utm_source=medium&amp;utm_medium=referral">Michael Longmire</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’m not <em>bad </em>with money but I’m not particularly good either. Like most people that live in New York City I have enough trouble just paying my rent so the whole concept of <em>investing </em>has an aspirational quality to it. That I could meet my immediate needs and somehow have <em>extra money?!</em> and that money could somehow become <em>even more extra money?! </em>would be fantastical if I weren’t so sure that, somehow, other people are doing it. But if I were to indulge that fantasy for a moment and become and <em>investor! </em>how would I even go about it?</p><p>The investing world is intimidating, there are a lot of ways to invest my imaginary extra money and like all novices I am terrified of making the wrong decisions but I’m also excited (and just a little bit greedy). But stock markets are volatile and property is unrealistic even for my imaginary extra money so, going slowly and carefully, I am going to use data science (with just add a dash of realism to wash the dollar signs from eyes) to take a hard look at <a href="http://www.lendingclub.com/">LendingClub</a>.</p><p>LendingClub is a peer-to-peer lending exchange. I wouldn’t be investing my imaginary money in faceless corporations that destroy the planet; I’d be lending it to real people that will use it to improve their lives (hopefully not by destroying the planet). More succinctly:</p><blockquote>LendingClub enables borrowers to create unsecured personal loans between $1,000 and $40,000. The standard loan period is three years. Investors can search and browse the loan listings on LendingClub website and select loans that they want to invest in based on the information supplied about the borrower, amount of loan, loan grade, and loan purpose. Investors make money from interest. LendingClub makes money by charging borrowers an origination fee and investors a service fee.<br>-<a href="https://en.wikipedia.org/wiki/LendingClub">Wikipedia</a></blockquote><p>Maybe a loan shark but a nice kind of loan shark.</p><p>LendingClub makes a large quantity of data available on past and current loans and repository of loan data spanning 2007 to 2018 is available from kaggle.com <a href="https://www.kaggle.com/wendykan/lending-club-loan-data">here</a>. So let me so what I’m imagining myself getting into.</p><p>The dataset contains<strong> 2.26 million </strong>loans with 145 features. The full feature list is expansive and goes into detail of the borrower’s financial situation as well as conditions of the loan and its repayment. I just care about how much imaginary money I‘m going to pretend to make, how can I figure that out?</p><p>The basic premise is simple enough I lend out my imaginary money, the pay it back with interest, the interest is my profit. The devil is <strong><em>ALWAYS</em> </strong>in the details. Loans come in 3 or 5 year terms and are graded that A-F with interest rate ranges that increase as the letter increases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*0emr_yh2Esg-bRYCbvQi8Q.png" /></figure><p>More interest means more profit and the expected total repayment on a loan can be calculated with the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*SvHoc8qc_chYOAwzNFICTw.png" /><figcaption>courtesy of <a href="http://www.1728.com/">1728.com</a></figcaption></figure><p>All the above components are known for each loan from the dataset features ‘int_rate’, ‘term’ and ‘loan_amnt’, so calculating my imaginary return is simple but is it realistic? Can I really just loan my imaginary money out and then 3 years later I have more imaginary money? Is that what has happened on LendingClub’s loans? Many of the loans represented in this dataset are still current, payments are still being made and the final return on the loan cannot be determined so I will only consider the loans with a finalized ‘loan_status’ feature of either “Charged Off” or “Fully Paid”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*x0387dGasRjGdtd4DyG9eA.png" /><figcaption>Completed Loans ONLY</figcaption></figure><p>Half of all are paid back with more than an 11% profit to the investor (Good!). On average the return is less impressive with just 3.36% profit to the investor from the loan. What is scary though is that some of the loans are not being paid back in full, some are not being paid back at all! Risk! Aaaaaaaaahhh!</p><p>Presuming that the loan is going to be paid back perfectly on time and with the interest is unfortunately idealistic and naive. Things happen, life is complicated, investing ALWAYS carries risk. But risk can be measured and minimized. So <em>which </em>loans are not all they’re cracked up to be?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*kfrjXsXlZGiqDe3R0usrXQ.png" /></figure><p>There is no perfect group of borrowers but loans are graded by their risk and shorter term loans perform better than longer term loans (less chance for things to go wrong?). Interestingly some of these loans return at a HIGHER rate than expected through our simple calculation. This could be due to late fees , loan extensions or temporary underpayment that eventually lead to the loan costing the borrower more than expected.</p><p>Generally though, A and B graded loans at 36 month terms are the closest performers to expectation. So lets look at the actual investment return for all of these loans and see what I can actually expect from my imaginary investment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*9Gk8Olw5Cff9g6DGYlYuGQ.png" /><figcaption>LendingClub promoted return from their <a href="https://www.lendingclub.com/investing/peer-to-peer">website</a></figcaption></figure><p>The high interest rate loans of grade G that could be so enticing are (unsurprisingly) a bad investment. Every loan grade and term has some loans that have a -100% return on the investment. Nothing was repaid and the investor is just left empty handed. This appears to be more rare on A and B grade loans where the interquartile range of the box and the mean and medians are nice and far from that 0% return line where I start losing my imaginary money. This is where it is important to note the LendingClub does not require you to fund all of an individual loan. They actually discourage it. LendingClub allows you to <em>diversify, </em>funding small fractions of many loans, called notes, spreading out the risk and offsetting any losses from loans not repaid in full.</p><p>This is all imaginary so I’m still on board and I’m willing to try it out! Even with my imaginary money I am a conservative investor, I am only going to take notes from A or B graded loans and I am going to diversify like crazy. 1 imaginary dollar (i$) each in to 1,000 loans. ( LendingClub requires a minimum of $25 (real dollars) per note but whatever, this is imaginary). I’m also going to try to be just slightly realistic. I am going to limit myself to loans originated in the year 2013 with a term of 36 months. These are relatively recent loans that all should have fully completed their repayment or been written off as a loss by the time this dataset was compiled at the end of 2018. There are 54,107 leans that fit my stringent criteria but I am only going to randomly select 1,000 and determine the total payment divided by the loan amount for each loan and sum the total.</p><blockquote>df_sim=df.loc[(df[‘issue_d’]&gt;’2013&#39;)&amp;(df[‘issue_d’]&lt;’2014&#39;)].loc[(df[‘grade’]==’A’)|(df[‘grade’]==’B’)].loc[df[‘term’]==36][[‘loan_amnt’,’total_pymnt’]].sample(n=1000,random_state=44)</blockquote><blockquote>((df_sim[‘total_pymnt’])/df_sim[‘loan_amnt’]).sum()</blockquote><p>i$1104.76!! An impressive return of over 10% from my initial i$1000 investment. My diversification strategy and high graded loans appears to have worked but also maybe this was just a fluke. So I’m going to try again, and again, and again. 1,000 times (just to be sure). Yes, I am performing a Monte Carlo simulation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*zvef6bRBmJiWO-RWfH7BtA.png" /></figure><p>My investment scenarios return a range of 8.5% to 11.4% return approximately normally distributed around a mean of 10.1%. It is important to note that this is not an annual return but a return over the course of the loan which in the above scenarios is 36 months. However, LendingClub do not make you wait that long and pay returns on notes purchased by investors on a monthly basis.</p><p>So, I think I’ve identified an investment strategy with a modest return rate and low risk that also includes a warm fuzzy feeling from helping people get loans that they need to improve their lives, start businesses, get married, consolidate debt and do all kinds of wonderful things. Now all I need to do is replace my imaginary money with real money!</p><p>Full python notebook linked below:</p><p><a href="https://github.com/ktzioumis/Lending-Club/blob/master/Cold-Foot-Investor.ipynb">ktzioumis/Lending-Club</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82da6c0baff0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/the-cold-foot-investor-82da6c0baff0">The Cold Foot Investor</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[Sentiment Analysis and Word Usage for KickStarter Blurbs]]></title>
            <link>https://medium.com/analytics-vidhya/sentiment-analysis-and-word-usage-for-kickstarter-blurbs-or-help-us-to-film-a-new-short-c89f04a696a0?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c89f04a696a0</guid>
            <category><![CDATA[sentiment-analysis]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[kickstarter]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Tue, 29 Oct 2019 19:44:56 GMT</pubDate>
            <atom:updated>2019-11-04T06:12:48.784Z</atom:updated>
            <content:encoded><![CDATA[<h4>or: Help Us to Film a New, Short, Documentary about a Tabletop Miniature Festival (which I am slightly unhappy about)</h4><p>The goal of this project was to perform sentiment and word usage analysis on successful and failed blurbs, to visualize the results and identify trends in blurb writing that may be useful for future Kickstarter blurb writers.</p><p>The dataset for this project contains the English blurb or description of 215513 KickStarter’s projects in 2017; 108310 successful and 107203 failed. All this data was collected by <a href="http://webrobots.io/">webrobots.io</a>, who performed the web scraping. They cleaned and tidied the scraped data, keeping just the two columns with blurbs in English and with final state of “successful” or “failed”. My analysis builds on this cleaned state.</p><p>Data Visualization performed using <a href="https://plot.ly/">Plotly</a></p><h3>Sentiment Analysis</h3><p><a href="https://www.nltk.org/_modules/nltk/sentiment/vader.html">NLTK’s Vader Sentiment Analyzer</a> is used to score blurbs on Positive, Neutral or Negative sentiment and a Compound score for overall sentiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*0udv_PjGk461ZdKvQIy1CQ.png" /></figure><p>Kickstarter blurbs tend to use positive language, even where the language is not identifiably positive it is more likely to be neutral than negative. Kickstarter blurbs are asking for money, so does it “pay” to be upbeat?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*mEnRe_Oq6Bmix_mZFwXKuw.png" /></figure><p>The difference is slight but Successful KickStarter blurbs actually have a higher proportion of negative and neutral blurbs that than Failed blurbs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*vosxZ4DMH4hlNhSK4hl0-A.png" /></figure><p>Although these donut charts represent different proportions of the total dataset there is an increase in the proportion of successful KickStarter blurbs from positive to neutral sentiment and a further increase from neutral to negative sentiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*HITxOf5DBKrlYcHytDbtbQ.png" /></figure><p>The Sentiment Distribution for Successful and Failed blurbs are show above, the spike at 0 reflects the Neutral Compound scored blurbs where no positive or negative sentiment was found. Both Successful and Failed KickStarter blurbs run the full positivity/negativity spectrum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*r0Z1YTvT_h2MTsuC-_DK1g.png" /><figcaption>Correlation Matrix</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70HwBo3D0dzwy10onIKeMg.png" /></figure><p>Correlation Matrix and Heatmap indicate a very slight negative correlation between compound sentiment and successful blurbs and slight slight positive correlation between negative and neutral sentiment and successful blurbs.</p><h3>Word Usage Analysis</h3><p>Sentiment analysis was certainly less than conclusive. To continue this investigation in to the KickStarter blurbs the texts of the blurbs is tokenized using NLTK’s Tokenizer tool. Stopwords, punctuation and numbers are all removed. Word Frequency is determined and compared for Successful and Failed blurbs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLHYEEEB2EH6NEezbbry6w.png" /></figure><p>The most commonly used words in successful blurbs has a lot of crossover with the most commonly used words in failed blurbs.</p><p>The words we are interested in are the words used more frequently by the successful blurbs than the failed blurbs. Two measures of this are below. The words with the highest net difference in usage by successful blurbs minus failed blurbs and the words with the highest ratio of usage by successful blurbs over failed blurbs (with a minimum usage of 500).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bZzF-JxoOM977_4N3nd6UQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O_z93Sg8i9og8kiEP-99jg.png" /></figure><p><em>Notes on word meanings:</em><br>“th” is most like a leftover from removing the numbers eg. “4th” becomes just “th”. From the above charts this would indicate successive campaigns i.e those that merits a 4th campaign have 3 prior successful campaigns and therefore are likely to have returning backers. “mm” may relate to miniatures and tabletop games, which are have very high success to failure differences and ratios.</p><h3>Conclusions</h3><p>The Sentiment of KickStarter blurbs is mostly positive, this may be <em>mildly </em>detrimental as the correlation with success runs in the opposite direction.<br>Interestingly, things that are “new” and “first” have high positive success differences and so do successive projects related to previous KickStarters i.e things that merit a ‘th’. Being both new AND repetitious are positive attributes!<br>“Tabletop”, “miniature” and “dice” have incredibly high success rates as do “film”, especially a “documentary”, as do “dance” projects.<br>“Us” and “We’re” both have significant positive differences and ratios indicating backers are in favour of group efforts.<br>Phrasing does appear to matter somewhat — “music” projects are mostly unsuccessful but “albums” are mostly successful.</p><p>If you want my recommendation: asking to <strong>“help us film a new, short, documentary about a tabletop miniature festival”</strong> is a sure-fire hit!</p><p>Checkout the github notebook here:</p><p><a href="https://github.com/ktzioumis/Kickstarter-NLP/blob/master/sentiment1.ipynb">ktzioumis/Kickstarter-NLP</a></p><p>Added Bonus!<br>All data visualization was performed in Plotly. Fork or clone the notebook and all the above graphs are interactive!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c89f04a696a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/sentiment-analysis-and-word-usage-for-kickstarter-blurbs-or-help-us-to-film-a-new-short-c89f04a696a0">Sentiment Analysis and Word Usage for KickStarter Blurbs</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[Choropleth Maps: Plotly & Folium]]></title>
            <link>https://medium.com/analytics-vidhya/choropleth-maps-plotly-folium-ba18350fb89e?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba18350fb89e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[choropleth-map]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[plotly]]></category>
            <category><![CDATA[folium]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Tue, 24 Sep 2019 18:56:19 GMT</pubDate>
            <atom:updated>2019-09-25T05:40:01.759Z</atom:updated>
            <content:encoded><![CDATA[<p>During a recent project based on <a href="https://github.com/ktzioumis/New-York-Restaurant-Guide">New York City Restaurants</a> I wanted to create some maps. It seemed to me like a useful thing to have on hand when talking about a city and they were very illustrative.The project ended up incorporating three choropleth maps based around New York Community Board Districts:</p><ul><li>Density of restaurants</li><li>Most popular types of restaurants,</li><li>Average health department inspection scores,</li></ul><p>All of these maps are made using the Folium library and I think they came out great. But there was one more map that I made but I didn’t end up using — Year on year changes in health dept inspection score averages. For a few reasons, including the overall sprawl over the project at this point, I did not end up including an analysis of time as a influencing factor on health department inspection scoring and grading. It was just as well because as much as I liked the idea behind that map, there were a few little nitpicking things I didn’t like about the the way it turned out.</p><p>You can view and interact with it here: <a href="https://ktzioumis.github.io/plotly-folium/m_ave_yronyr.html">https://ktzioumis.github.io/plotly-folium/m_ave_yronyr.html</a></p><p>The map displays the annual average health inspection score for each Community Board area for the years 2016 (from July), 2017,2018 &amp; 2019 (to July). Each year can be selected or deselected as an overlay for the OpenStreetMap. The map as it is linked above is functional and illustrates the data well but my quibbles are as follows:</p><ul><li>Selecting between choropleth maps does not deselect the other choropleths — makes it difficult to see changes from one map to the next, since they will either be overlayed as one is selected and the other deselected or the map goes blank in between selections</li><li>The colorbar for each choropleth is permanently displayed regardless of whether that choropleth is turned on</li></ul><p>Folium does not support a method to resolve either of these problems.</p><p>I no longer <em>needed</em> to make this map but I still <em>wanted</em> to able to make this map. The shortcomings of Folium were disappointing so I wanted to try out another plotting/mapping library — Plotly.</p><p><a href="https://plot.ly/python/mapbox-county-choropleth/">Plotly Choropleth tutorial</a></p><p>The choropleth tutorial is based on unemployment data for US counties and I used it as a starting point to make a layered choropleth map the way I wanted it to look.</p><p>The process of creating a dropdown menu for choropleth selection I have adapted from <a href="https://plot.ly/~empet/15237/choroplethmapbox-with-dropdown-menu/#/">this tutorial</a></p><p><a href="https://github.com/ktzioumis/plotly-folium/blob/master/Plotly_unemp_choro.ipynb">github jupyter notebook</a></p><p>Animated gif of the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*NdigtS6oeh3-Barx" /></figure><p>I love this result! And it addresses both my problems directly.</p><ul><li>The dropdown allows for selection of choropleth that is tuned to set the visibility of the other choroploeth (A third option in the dropdown could be set to have both the choropleths visible should it be required).</li><li>The colorbar displays only the scale for the selected choropleth.</li></ul><p>As a bonus because the colorbar is offset from the map to the right, the text for the xticks and label on the legend are not displayed in front of the map and are much more legible as a result. Folium does not allows for the legend position on the choropleth to be changed.</p><p>Definitely a win for Plotly</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba18350fb89e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/choropleth-maps-plotly-folium-ba18350fb89e">Choropleth Maps: Plotly &amp; Folium</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[What New York’s Health Inspections Have To Teach Us about Machine Learning]]></title>
            <link>https://medium.com/@kosta.tzioumis/what-new-yorks-health-inspections-have-to-teach-us-about-machine-learning-79d63a1c5330?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d63a1c5330</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[open-data]]></category>
            <category><![CDATA[matrix]]></category>
            <category><![CDATA[food-safety]]></category>
            <category><![CDATA[new-york]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Mon, 23 Sep 2019 15:36:01 GMT</pubDate>
            <atom:updated>2019-09-23T15:36:01.256Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Because we all gotta eat amirite?</em></p><p>I spent 3 years working in 2 Greenwich Village restaurants. As a line cook mostly, but also as a barista and a busser. I know from experience that the New York restaurant industry takes food safety inspections seriously. They have to, the thousands in fines are enough to drive a business struggling on razor thin margins over the edge but the real cost is having to put up that “Grade Pending” sign, or worse a big ol’ “B” . A “C” is just gross. My Food Safety Certification is, sadly, expired now and I’m not as quick with a pair of tongs as I used to be but taking this deep dive into the New York City Department of Health and Mental Hygiene’s open record of inspection results brought a lot of memories flooding back (Table 7, order up!).</p><p>Read my full analysis and machine learning on <a href="https://github.com/ktzioumis/New-York-Restaurant-Guide">Github</a></p><p><a href="https://github.com/ktzioumis/New-York-Restaurant-Guide">ktzioumis/New-York-Restaurant-Guide</a></p><p>As a part of the New York Open Data project all Department of Health inspections for the 3 years prior to the most recent inspection are made publicly available. The complete dataset can be found here: <a href="https://data.cityofnewyork.us/Health/DOHMH-New-York-City-Restaurant-Inspection-Results/43nn-pn8j">DOHMH New York City Restaurant Inspection Results</a>. This dataset is updated daily! <a href="https://opendata.cityofnewyork.us/">NYC Open Data</a> is an amazing resource for all data scientists and all New Yorkers and for people (like me!) who happen to be both it is also a fantastic way to get to know their own city.</p><p>This project involved the most extensive data cleaning I have done so far. The database consists of almost 400 thousand rows, each representing an individual citation to a restaurant for… something. The scope of this dataset was staggering, The Dept of Health performs multiple kinds of inspections some of which are graded and some of which are not. It was necessary to focus this dataset on what I was interested — Food. An interesting problem was renegotiating this data from its current format of individual citations to a form that made more sense to me making each row an inspection. Inspections could result in 0 or many (sometimes far too many for comfort) violations that that make up a score and determine the grade awarded to the restaurant. I was able to achieve this by creating a new index of CAMIS and date unique pairs and then reading in the violation results for the inspection that occurred that day. The database was further culled to a 3 year period from mid 2016 to mid 2019 and in the end I had a 65,932 inspection results with violation details, scores, restaurant information all neatly packaged in individual rows and most importantly GRADES.</p><p>An A is precious, anywhere even remotely upmarket in New York pretty much HAS to get an A. The initial inspection is not the end of the story when it comes to getting an A, you can argue the point in a Tribunal Hearing and you are entitled to a reinspection one week later but even to not be able to display that A for a single day can get notice. Per Se is one of the most well known (and expensive) restaurants in New York and when it got a bad score on an inspection in 2014 it became the subject of an <a href="https://www.businessinsider.com/per-se-grade-pending-2014-3">article on Business Insider </a>). So can we predict which restaurants will get an A and which will not?</p><p>Yes we can!</p><p>With 68% accuracy! And achieving this in two ways using XGBoost Classifiers raises an interesting comparison for machine learning construction.</p><p>My predictive models use restaurant characteristics that fall loosely into 3 categories:</p><ul><li>Location — Community Board</li><li>Type — Cuisine Description and Chain status</li><li>History — Previous Score and Previous Critical Flags</li></ul><p>The previous score, previous critical flags are numerical features are used the same for both classifiers. The chain status (whether or not the restaurant is part of chain with multiple locations) is a binary feature and is used the same for both classifiers Cuisine Description and Community Board are categorical features and this is where the two models diverge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/0*iKQifrp-B51N-U_r.png" /><figcaption><em>Starting Matrix</em></figcaption></figure><p>The first model used one-hot encoding to create a large sparse matrix with 156 columns that consist mostly of zeroes. It does quite well, the classification report is below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/0*5hgv2xsdHcp_E0aE.png" /><figcaption><em>Sparse Matrix Classification Report</em></figcaption></figure><p>The second model took a different approach to the categorical features. The summary statistics for each cuisine style and community board consisting of mean, standard deviation and count were derived in exploratory data analysis. For this second model I used the categorical features as key to the summary statistics stored in a separate dataframe and merged them together</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/0*bo1iGWNOAiJTPjeI.png" /><figcaption><em>Merging summary statistics into categorical features</em></figcaption></figure><p>This created a matrix of 9 numerical columns that I believe maintained the important information from the categorical features in a much smaller matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/871/0*UCX11oNtgsVUsFuQ.png" /><figcaption><em>Summary Statistics Matrix</em></figcaption></figure><p>The second model was just as accurate as the sparse matrix classifier!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*Y3TRHSJG8V9y4X5i.png" /><figcaption><em>Summary Statistics Matrix Classification Report</em></figcaption></figure><p>It also had one huge advantage; it trained in one tenth the time. Training the classifier on the sparse matrix took approximately 16 seconds per pass. Training the classifier on the summary statistics matrix took just 1.5 seconds per pass. The advantage in training is important because this is a continuously updated dataset. Inspections occur in New York City daily and will continue as long as there are restaurants (i.e. forever). An agile learning algorithm is important for keeping the model current. The model will need to be retrained to maintain accuracy as new data become available. If the dataset is expanded beyond the current 3 year period then this will also lead to longer training times that may make the sparse matrix unusable.</p><p>Substituting my categorical data for summary statistics greatly reduced training time while maintaining accuracy. In this instance it worked, the features described we can reasonably expect to be normally distributed and a mean and standard deviation provide a good description of distribution without having to one-hot encode it all. This may not work for everything but its certainly worth a shot</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d63a1c5330" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Seinfeld]]></title>
            <link>https://medium.com/analytics-vidhya/the-seinfeld-fc3c40d2910a?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc3c40d2910a</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[seinfeld]]></category>
            <category><![CDATA[classifier]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Mon, 23 Sep 2019 00:22:55 GMT</pubDate>
            <atom:updated>2019-09-30T13:45:36.602Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep Learning on Seinfeld</h3><p>Seinfeld is and always has been one of my all time favourite shows, so when I saw the complete <a href="https://www.kaggle.com/thec03u5/seinfeld-chronicles">‘Seinfeld Chronicles’</a> data set on Kaggle I was speechless and was at a loss of words.</p><p>github notebooks:</p><ul><li><a href="https://github.com/ktzioumis/The-Seinfeld/blob/master/The-Seinfeld.ipynb">ktzioumis/The-Seinfeld</a></li><li><a href="https://github.com/ktzioumis/The-Seinfeld/blob/master/Larry%20David.ipynb">ktzioumis/The-Seinfeld</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/0*CF7kPCrmf5hnuJR6.gif" /></figure><p>The idea of applying deep learning to Seinfeld seemed strange at first, starting out I was just happy to play around inside the data and discover interesting things like ‘Larry David wrote the most episodes of Seinfeld with 58 credits’ and ‘George speaks more than Elaine in every season except Season 6’ and ‘Superman is mentioned 24 time in in 17 episodes’.</p><p>But it was that Larry David fact that come back to and stuck in my mind. His number of writing credits greatly dwarfs the next most prolific writer (a tie between Peter Mehlman and Larry Charles on 19 each). Larry David’s role is especially crucial early in the series where ‘Seinfeld’ is not yet popular and is still finding its feet as a show. Larry David wrote 4 of the 5 episodes of the first season and 8 of the 12 episodes in the second season. In the third season his over all number of episodes increases to 14 but by this time the series has a full 23 episode run.</p><p>As a writer, Larry David effectively built the show into what it became and wrote who the characters were and who they would become.</p><h3>The Larry David Classifier</h3><p>Larry David’s contribution to Seinfeld is monumental. His amazing 58 episodes worth of writing credits is one third of the total episodes. His influence on the characters and style of the show is singular and immeasurable, or is it? If Larry David was so instrumental; in creating the characters, how much of Larry David can I extract from the the episodes that he himself wrote?</p><p>By using a Keras Deep Learning Model with Natural Language Processing the goal was to train a model to tell if Larry David wrote a given piece of dialogue.</p><p>Each piece of dialogue is flagged to create a ‘Larry’ feature based on its episode and season number and whether Larry David is credited in that episode</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/0*rTdlwerReVFAoVVd.png" /></figure><p>The individual snippets of dialogue are tokenized using only the 20000 most common words and converted to uniform length padded sequences.</p><pre>tokenizer = text.Tokenizer(num_words=20000)<br>tokenizer.fit_on_texts(list(scripts[&#39;Dialogue&#39;].values))<br>list_tokenized_train = tokenizer.texts_to_sequences(scripts.Dialogue.values)<br>X_t = pad_sequences(list_tokenized_train,maxlen=100)<br>y=scripts.Larry.values</pre><p>The data is split into 75% training set and 25% test set and from the training set the deep learning model is fit with a 10% holdout for validation. The best model created using just the labelled dialogue was a Bidirectional Gated Recurrent Unit (200 nodes) and three Densely connected layers (200, 100, 50 nodes) and Dropout (0.2) trained for 2 epochs. Which sounds like, and totally is, a whole mouthful. To break it down:</p><ul><li>Bidirectionality — Bidirectional layers process data sequentially in both directions, forwards and backwards, using half the nodes for each direction. This structure allows the model to have both forward and backward information about the sequence each step.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*U0RAvtwdfcvMiwAg.jpg" /><figcaption><em>Bidirectionality Diagram</em></figcaption></figure><ul><li>Gated Recurrent Unit — Gated recurrent unit is a type of cell that passes along some but not all information about its internal state across data steps.By constantly updating their internal state, they can learn what is important to remember, and when it is okay to forget it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*ZdnghRv8a-MlEJ0N.png" /><figcaption><em>Gated Recurrent Unit Diagram</em></figcaption></figure><ul><li>Densely connected layers — Neurons in a fully connected layer have full connections to all activations in the previous layer. Their activations can hence be computed with a matrix multiplication followed by a bias offset.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*Is9dM91EisHYQgcw.png" /><figcaption><em>Densely Connected neural network</em></figcaption></figure><ul><li>Dropout — Individual nodes are randomly selected to be dropped out of the network based on a selected probability. This prevents over-reliance on specific node pathways and overfitting</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*8jgIUNOrkNusIDuW.png" /><figcaption><em>Srivastava, Nitish, et al. ”Dropout: a simple way to prevent neural networks from overfitting”</em></figcaption></figure><ul><li>epoch — generally defined as “one pass over the entire dataset”, used to separate training into distinct phases, which is useful for logging and periodic evaluation.</li></ul><p>Yeah. You know , a deep learning neural network…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*8i9KchwKX2hjSduN.gif" /></figure><p>It worked though! The model is 70% accurate at predicting whether or not Larry David is the author of an unseen piece of dialogue.</p><p>From here I would like to perform further editing of the Seinfeld scripts in order to remove simple greetings and phrases, more complex language would be more distinctive and likely improve the model’s ability to predict authorship. Any writer could have written “hi”, I don’t want to know about “hi”, forget “hi”. Additionally, this model doesn’t take into account who is speaking, how Larry writes the individual character’s adds another dimension of complexity that could be addressed.</p><p>I very much hope that this is but part 1 of a series. As I keep coming back to Seinfeld in my own life, I hope to keep coming back to it in my career as a data scientist.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc3c40d2910a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/the-seinfeld-fc3c40d2910a">The Seinfeld</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[The Many Machine Learning Models of the LA-Bike Sharing Network]]></title>
            <link>https://medium.com/@kosta.tzioumis/the-many-machine-learning-models-of-the-la-bike-sharing-network-1dce344870ea?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dce344870ea</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Mon, 23 Sep 2019 00:17:22 GMT</pubDate>
            <atom:updated>2019-09-23T00:17:22.673Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction:</h3><p>So why did I choose this Los Angeles Metro Bike Share Trip Data<a href="https://www.kaggle.com/cityofLA/los-angeles-metro-bike-share-trip-data">https://www.kaggle.com/cityofLA/los-angeles-metro-bike-share-trip-data</a> ? Los Angeles is a city I have never visited (I live in New York, East Coast baby) and bicycling is a mode of transport I don’t particularly care for but I was drawn into a snapshot of a system at work anyway. I wanted to know how this little web was going to play out.</p><p>github notebook: <a href="https://github.com/ktzioumis/LA-Bike-Share/blob/master/student.ipynb">https://github.com/ktzioumis/LA-Bike-Share/blob/master/student.ipynb</a></p><h3>The Dataset:</h3><p>The dataset furnishes us with plenty of details, we even get we get something akin to the 5 Ws( <a href="https://en.wikipedia.org/wiki/Five_Ws">https://en.wikipedia.org/wiki/Five_Ws</a>):</p><ul><li>When — Timestamped Start and End times</li><li>Where — Start and End Stations with Latitude and Longitude</li><li>What — Trip Route Category: One-Way or Return Trip and Duration</li><li>Who — Passholder Types: Flex Pass, Monthly Pass, Walk-up</li><li>Why — So that they can ride a bike!</li></ul><p>The briefest of glances shows 762 Bikes ridden over 130 thousand times between 66 Bike stations between early July 2016 and the end of March 2017, the LA bike share network certainly looks like it was a hit!</p><p><strong>Behold the Network!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/0*_ALdnQt-eMdWk8Uj.jpg" /><figcaption>Bike Docks in Los Angeles. Inset: Downtown LA</figcaption></figure><p>Downtown LA is home to a dense network of bicycle stations, they are conveniently close-by for anyone in need of a ride or looking to drop-off at their destination. There are 2 additional stations outside the downtown area at Culver City and Venice by the beach. These stations only have rides attributed to them at the very end of our dataset’s time period and appear to represent new additions to the network.</p><h3>Learning Machines:</h3><p>The goal of this project was to apply a machine learning classifier model to some aspect of the chosen dataset but I wanted to go one better and I built two. To make it more interesting they had to be different as well, one was to be a discrete classifier and the other a regression model on a continuous variable.</p><p>After exploring the time series data I elected to break apart the starting datetime condition into some key components: an On-Peak/Off-Peak class, the day, the month and the rounded off hour of the day. Based on these starting conditions, I wanted to know how much could we predict about what the rider was going to do? I was ready to grab the tiger by the tail and try to model one of the ride components; the Duration.</p><p>Of course to model the ride duration it was important to pretend I don’t know about the end conditions of the ride, End Time is a proxy for duration and if we knew the end location of the ride then the ride is over and we know how long it went for. We’re doing this the hard way, damnit!</p><p>Now what modelling method should I choose? Maybe Decision Tree Regressor or maybe a Random Forest Regressor (even more trees!), why not both?! So I’m not doing 1 machine learning model for regression now, I’m doing 2!</p><p>And my classifier model I chose to do on the membership types, they all ride the same bikes but do they ride them <em>differently?</em> What kind of classifier to use here? Random Forest Classifier, ADABoost? XGBoost? ALL OF THEM?! I did indeed get a little carried away with building machine learning models and instead of making 1 I made 5….</p><p>Just 5?</p><p>I want the regressor to regress and I want the classifiers to classify but most importantly I want them to do it well! That’s where hyper parameters come in, using sklearn’s GridSearchCV I was able to automatically run and re-run these models with different hyper parameters to tune their performance aaaaand apply a 3 times cross-fold validation. So no it wasn’t 5 machine learning models after all it was…</p><p><strong>840 + 288 + 432 + 27 + 162 = 1749</strong></p><h3>1749 Models</h3><p>Well that was a bit of an effort wasn’t it, hope it was quick…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*LgbLMdhU3-wsw9LA.png" /></figure><p>Not exactly…..</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dce344870ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pandas , SQL and t-tests]]></title>
            <link>https://medium.com/analytics-vidhya/pandas-sql-and-t-tests-254af4ed82b2?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/254af4ed82b2</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[sqlite3]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[pandas]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Sat, 21 Sep 2019 18:05:49 GMT</pubDate>
            <atom:updated>2019-10-01T02:48:00.792Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pandas , SQL and t-tests</h3><p>Pandas is a powerful python library, SQL is an ubiquitous databasing language and t-tests are a eminently useful hypothesis testing tools. Each of these are incredible tools in their own right but this project has been about using all three in concert. And most importantly, using them to extract meaning and value from data.</p><p>Microsoft’s well known <a href="http://https//www.geeksengine.com/article/northwind.html">Northwind Traders Database</a> describes the company operations through a number of interconnected database’s like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0JSZLMHtL3plax3c" /><figcaption>Northwind Traders Schema</figcaption></figure><p>Information about the company is distributed across 13 interconnected tables with connections in each table linked by unique keys. Tables describe different areas of the company’s operation; for example, there’s a table for customers and a table for products and the two are linked by a third table where customers have placed orders for products. Making sense of it all separately is extracting one story from three separate books. SQL is how we take that story and give it its own book</p><p>Learning SQL was a challenge in its own way, but I was glad for an opportunity to use another language and see the way it differs from python. There’s no <strong>right </strong>way to build a query language or a coding language and every one has its strengths and weaknesses but most importantly it has its own structure its own commands. Learning SQL was a necessary reminder that things are sometimes just different, not better, not worse, just different. I look forward in future to broadening my aptitude with SQL and other langiuages to take my coding skills to another level of versatility.</p><p>Mating SQL with python can be performed through the <strong>sqlite3</strong> library which interacts very nicely with pandas to create DataFrames. Because, why should things be difficult when they could be easy? By using the pandas command <strong>pd.read_sql()</strong> and passing my (carefully constructed) SQL query I was able to create one DataFrame that extracted only the relevant information from multiple tables and nothing else. I got my story out of all those books and into one easy to read slim volume. An example is below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/0*gRG1qBbl8OVo5l0-.png" /><figcaption>Elegant, amirite?</figcaption></figure><p>Pandas, of course, shines when it come to data manipulation, visualisation and the Exploratory Data Analysis that is the first step to answering any question about data (check out this blog post about <a href="https://ktzioumis.github.io/visualizing">visualizing data</a>). The question is where the t-test comes in. t-tests are amazing, a t-test is <em>a type of inferential statistic used to determine if there is a significant difference between the means of two groups, which may be related in certain features.</em>(Thanks <a href="https://www.investopedia.com/terms/t/t-test.asp">Investopedia</a>!). Really this means that a t-test, much like this Big Bird gif, will tell you if one of these things is not like the other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*bwZx_c1P6BV7vCBg.gif" /></figure><p>Importantly, the t-test is a statistical measure. Not a yes-or-no, the outputs we take from the t-test is a probability — The likelihood that the sample means from the tested datasets are equal. It is up to us to determine whether or not the p-value is sufficient to reject or not-reject (important! we do not <strong>accept </strong>the null hypothesis, we fail to reject it) the null hypothesis. This determination is somewhat arbitrary, for this project I set that bar 0.05. This is a common threshold and means that there is 5% likelihood that the samples have the equal means. Where the t-test p-value is below this, I determine that a 5% chance is too low to accept that the the means are equal.</p><p>Being able to state with statistical confidence that groups of data <strong>are </strong>different is where we extract meaning and value. This ability has very broad potential for the (imaginary) business that I am analysing. In this project I use it to determine the answers to 4 questions:</p><p>1. Do discounts have a statistically significant effect on the number of products customers order? If so, at what level(s) of discount?<br>2. Do certain product categories sell better in the Americas or Europe?<br>3. Do late deliveries effect Customer’s ordering?<br>4. Does Number of Territories for each employee affect their sales figures?</p><p>Each of these questions touch on a different facet of the business:</p><p>1. Sales volume by price point<br>2. Sales volume by region<br>3. Supply chain logistics<br>4. Employee performance</p><p>And it is this versatility that is truly impressive. By chaining together an SQL query from the database of tables to create a pandas DataFrame and performing t-test analysis insights into widely varying aspects of the business, its operation and the performance of its customers, suppliers and employees is possible.</p><p><a href="https://github.com/ktzioumis/Northwind-Traders">ktzioumis/Northwind-Traders</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=254af4ed82b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/pandas-sql-and-t-tests-254af4ed82b2">Pandas , SQL and t-tests</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[Visualizing your Exploratory Data Analysis]]></title>
            <link>https://medium.com/analytics-vidhya/visualizing-cea6e3be6ad5?source=rss-62ea1c30fdd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cea6e3be6ad5</guid>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[seaborn]]></category>
            <dc:creator><![CDATA[Kosta Tzioumis]]></dc:creator>
            <pubDate>Sat, 21 Sep 2019 15:27:19 GMT</pubDate>
            <atom:updated>2019-09-27T11:07:03.750Z</atom:updated>
            <content:encoded><![CDATA[<p>This blog post will explore the visual aspect of exploratory data analysis using King’s County Housing Prices dataset.</p><p>explore the notebook on github: <a href="https://github.com/ktzioumis/dsc-1-final-project-online-ds-pt-112618/blob/master/student.ipynb">https://github.com/ktzioumis/dsc-1-final-project-online-ds-pt-112618/blob/master/student.ipynb</a></p><p>A big part of exploratory data analysis is visualisation. Thousands of rows of data can expressed simultaneously as points, lines, bars, areas and many other forms and this is very useful for identifying and exploring trends or important aspects of the data set. Once the data set has been cleaned of missing values, one of the first steps of exploratory data analysis that we have been shown is to generate histograms of each feature. Our visualisations so far have been generated by matplotlib.pyplot and some have used seaborn. Generating histograms for each feature of a dataset individually would be very repetitive, a for loop to repeat the steps automatically is great shortcut but even better when using pandas this can be done simply with the command df.hist()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*-hiF6z92zoV0p96k.png" /></figure><p>This is perfect, one short line of code for 18 histograms. The first step in visualizing our data and now we can make some decisions about what to do with it. The end goal of our project is an Ordinary Least Squares Regression model for the target feature price and the regression method we use has some assumptions, the first of which is normality. Does the data follow a normal distribution? The histograms we just generated are a great visual test for normality and skew. From this visualisation we can make transformations on our feature set to push the data into the shape that we want for the regression. Price is log transformed and so is sqft_living and new histograms can be generated to show off this distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*jSMWkIac3yr0penr34iH4w.png" /></figure><p>Much better fit for normal distribution and we can also plot the two features against each other for a visual representation of their relationship</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*DJv-ev4syIk4JDHU.png" /></figure><p>This scatter plot is generated using seaborn rather than matplotlib to take advantage of slight differences in their default settings. Seaborn employs white rings around blue circles as its default setting and matplotlib plots plain blue circles. The difference here is that when data is dense and overlapping the matplotlib version creates a solid blue mass whereas in the seaborn version each data point is still recognisable. There are other ways to make overlapping data more visible that could be employed. The ‘alpha’ setting when plotting allows for transparency of graphed features so overlapping datapoints can be seen as the overlap creates a more noticeable colour. This was utilised in another scatter plot of this data where color coding was used to make a 2D scatter plot representative of a 3rd feature, effectively adding a 3rd dimension.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*JPg5mzOjzKRSYxRU.png" /></figure><p>This is the same plot! Using matplotlib this time the same scatter plot was generated and the third feature/dimension, the ‘jones’ feature, was added to the colour determine colour of the data points. For this visualisation I was only concerned with whether the jones factor was positive or negative so the code for generating this plot reads</p><p>plt.scatter(log_sqft_living,price_log, alpha=0.6, c=jones&gt;0)</p><p>c being the colour scale mapping function. By passing the determination of jones&gt;0 rather than just the jones value itself I cut out the spectrum of colours to a binary selection of two colours: purple or yellow. And by passing an aplha value of 0.6, where these data points overlap is more visible especially in the region between the two red lines where there are a mix of both purple and yellow dots. The colour bar is added to the plot by passing the commad plt.colorbar() and it allows for a full spectrum of color differences for a more nuanced 3D understandung of the data but that was not desirable in this case and a full colour spectrum as a plot scale can be more confusing than enlightening when not used carefully. As a part of the determination of factors usd in the regression model a heatmap of the correlation factor of each feature was generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*UnVMZ-yZJb6u-Em_.png" /></figure><p>sns.heatmap(np.abs(corr),linewidths=2,mask=mask,cmap=cmap,annot=True)</p><p>When generating this heatmap I was conscious that usinig colour as a scale can be difficult. I’ve tried to add as much clarity as possible, the boxes are spaced out with a linewidth divider and the colour scale represents the absolute value of the correlation but still I felt it was necessary to annotate the boxes with their values. Taking the absolute value makes the data much more comparable by colour 0.8 and -0.79 are almost equally far from zero but if these were to be represented as red and green it would be impossible to tell which ‘is this more green than this is red?’. In the end though it was important to make a cutoff call when choosing features and if I want this graph to tell me what I want to know (which features are above my cutoff) quickly than there is a more simple way to do it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/0*VOxztAB3n7vRyrul.png" /></figure><p>Here it is, black and white. Again I have used a determination in the colour field, this time whether the absolute vale correlation factor was above 0.5</p><p>sns.heatmap(abs(corr)&gt;.5,mask=mask,linewidths=2)</p><p>This creates an easy at-a-glance version of the heatmap. It tells us less but it tells us what we need to know and nothing else. And that just might be the perfect kind of visualisation</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cea6e3be6ad5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/visualizing-cea6e3be6ad5">Visualizing your Exploratory Data Analysis</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>