<?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 Muhammed Berk Önder on Medium]]></title>
        <description><![CDATA[Stories by Muhammed Berk Önder on Medium]]></description>
        <link>https://medium.com/@berkmonder?source=rss-99dc223dcfa4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*gDfAo0QGaNmUkUtj9dwe4Q.jpeg</url>
            <title>Stories by Muhammed Berk Önder on Medium</title>
            <link>https://medium.com/@berkmonder?source=rss-99dc223dcfa4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:21:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@berkmonder/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[Simple Data Science Project Tutorial]]></title>
            <link>https://medium.com/@berkmonder/simple-data-science-project-tutorial-c75874243bdf?source=rss-99dc223dcfa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c75874243bdf</guid>
            <category><![CDATA[exploratory-data-analysis]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Muhammed Berk Önder]]></dc:creator>
            <pubDate>Sat, 25 Dec 2021 14:56:00 GMT</pubDate>
            <atom:updated>2021-12-25T14:56:00.875Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n2dXoQ2rbDEPKXKM" /><figcaption>Photo by <a href="https://unsplash.com/@andrewtneel?utm_source=medium&amp;utm_medium=referral">Andrew Neel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Purpose of this article</h3><p>This article will be a beginner friendly Data Science project guide; exploring basics of Web-Scraping, Exploratory Data Analysis(EDA) and Machine Learning Training(Linear Regression) for IMDb’s Top 250 Movies. Data Science newcomers are the primary audience, although it is expected that experienced scientists may also use the guide to recall and refresh their knowledge about the subject.</p><p>Because of my background and interest in science and programming, I think data science is perfect fit for me. But for a long time I didn’t know where to start, I knew I had to make a project, but I didn’t know how to make one. I still have tons of things to learn, but this is an adventure where, with its ups and downs, the experiences to gain along the way are great and abundant; although abundant, it can sometimes be daunting trying to learn more than one thing from multiple sources at once. For this reason, in this article, we will learn by talking about how to make a Simple Data Science Project.</p><h3>Web-Scraping</h3><p>First things first, let’s import our necessary libraries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/97838a5a40bd558b34f2aef80294a38b/href">https://medium.com/media/97838a5a40bd558b34f2aef80294a38b/href</a></iframe><p>Now let’s create a function that gets and parses any URL that we feed in, so we don’t have to get and parse every URL one by one.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b48b01b31b5de38484bf18b46d016f80/href">https://medium.com/media/b48b01b31b5de38484bf18b46d016f80/href</a></iframe><p>For the sake of it, let’s grab our data from IMDb’s Top 250 movie list. So we call our <em>getAndParseURL() </em>function from above and search and get each movie’s link and put them in a list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b65bd46dd14704073e4fa275ae697ff5/href">https://medium.com/media/b65bd46dd14704073e4fa275ae697ff5/href</a></iframe><p>It is important that we understand what this code does so let’s dissect and see what is going on in our for loop.</p><p>First let’s see what our <em>soup </em>variable returns.</p><pre>&lt;!DOCTYPE html&gt;<br><br>&lt;html xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot; xmlns:og=&quot;http://ogp.me/ns#&quot;&gt;<br>&lt;head&gt;<br>&lt;script type=&quot;text/javascript&quot;&gt;var ue_t0=ue_t0||+new Date();&lt;/script&gt;<br>&lt;script type=&quot;text/javascript&quot;&gt;<br>window.ue_ihb = (window.ue_ihb || window.ueinit || 0) + 1;<br>if (window.ue_ihb === 1) {<br><br>var ue_csm = window,<br>    ue_hob = +new Date();<br>(function(d){var e=d.ue=d.ue||{},f=Date.now||function(){return+new Date};e.d=function(b){return f()-(b?0:d.ue_t0)};e.stub=function(b,a){if(!b[a]){var c=[];b[a]=function(){c.push([c.slice.call(arguments),e.d(),d.ue_id])};b[a].replay=function(b){for(var a;a=c.shift();)b(a[0],a[1],a[2])};b[a].isStub=1}};e.exec=function(b,a){return function(){try{return b.apply(this,arguments)}catch(c){ueLogError(c,{attribution:a||&quot;undefined&quot;,logLevel:&quot;WARN&quot;})}}}})(ue_csm);</pre><p>-Hold up.. let me stop you right there.. It just types out the entire HTML code of the website!</p><p>So how are we going to find anything in all of this mess? We are going to use <em>tags</em> that indicates where we want to go in our HTML text. So let’s check where is our first movie nested in. Just right click and <em>Inspect</em> on to find what is it you are looking for. In our case we want to find the URL of the first movie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7OgC64KU8C7i0ahRRfBHw.jpeg" /></figure><p>As we take a quick look on our HTML text, we can see that there is only one <em>tbody</em> tag(or at least what we are looking for is the first <em>tbody</em> in our HTML code). So if we run <em>soup.tbody </em>it would go and print only the <em>tbody</em> tag that we specified it to do.<br>(Note: If there was more <em>tbody</em> tags below, <em>soup.tbody </em>would only return the first one)</p><p>So what are we looking for is that our HTML text is structured in a way that all of our movies are in a big <em>tbody </em>tag and after that there is one <em>tr </em>tag per movie. If we were to run <em>soup.tbody.tr </em>this would print the first ever movie, but we want to run a for loop to get every movie on the list. So this is what our 4th line is doing. It goes in <em>soup.tbody</em> and then finds All the <em>tr</em> tags; <em>soup.tbody.findAll(‘tr’) </em>and returns a list where every <em>tr </em>tag is an item.</p><p>After we get inside of each <em>tr</em> tag, we get to find the <strong>second</strong> <em>td </em>tag(because it returns a list, we take the [1] item) because that is where our movie’s link is nested, then we can get to use one more tag <em>a, </em>to finally reach the link that takes us to the movie’s original page! So we append every <em>href </em>that exists in our <em>a</em> tag and slam a <a href="https://www.imdb.com/"><em>https://www.imdb.com/</em></a><em> </em>before we save it to our <em>movie_urls</em> list.</p><p>So our <em>movie_urls</em> list looks like this.</p><pre>[&#39;https://www.imdb.com/title/tt0111161/&#39;,<br> &#39;https://www.imdb.com/title/tt0068646/&#39;,<br> &#39;https://www.imdb.com/title/tt0071562/&#39;,<br> &#39;https://www.imdb.com/title/tt0468569/&#39;,<br> &#39;https://www.imdb.com/title/tt0050083/&#39;,<br>...]</pre><p>Now that we have taken each and every movie’s URL from our list, let’s go in every movie’s page, roll up our sleeves and scrape our data. The best part is we just have to do it for one movie and iterate this through our list to make <em>python</em> do it for every movie!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0582fea5c6898ec867e18d17acd62b36/href">https://medium.com/media/0582fea5c6898ec867e18d17acd62b36/href</a></iframe><p>This will be the most exiting part of web-scraping where we try to literally scrape our data embedded in the web page. So we put our <em>movie_urls</em> list in a for loop to get each item and feed it to our <em>getAndParseURL()</em> function for every movie in the list. Let’s take a look at the first and the simplest scraping that is the <em>title</em> of our movies.</p><p>Like we did with <em>soup.tbody</em> which is equivalent to <em>soup.find(‘tbody’)</em> we want to specify which tag we are actually looking for. Because there might be lots of <em>h1</em> tags in this HTML text; we have to search with an <strong>attribute</strong> that is unique only to the section we want that keeps our data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fJMd76zN7rL7f8OYtCSIrw.jpeg" /></figure><p>There are some attributes that we could use like <em>class</em>, or maybe <em>textlength</em> but some other text might also have the same <em>textlength</em>, and this particular <em>class</em> attribute’s value “<em>TitleHeader__TitleText-sc-1wu6n3d-0 gxLYZW</em>” is only unique to this particular movie. So we can’t get other movie’s title’s with this attribute. Luckily, IMDb is doing us a solid here and gives the <em>h1</em> tag a <em>data-testid</em> attribute that we can easily use for every movie in our list!</p><pre>html.find(&#39;<strong>tag</strong>&#39;, {&quot;<strong>key of the attribute</strong>&quot;:&quot;<strong>value of the attribute</strong>&quot;}</pre><p>So;</p><pre>html.find(&#39;h1&#39;, {&quot;data-testid&quot;:&quot;hero-title-block__title&quot;}).text</pre><pre>(Note: .text is there to get the string value in the <em>h1</em> tag which is the title of the movie)</pre><p>There is no easy way of explaining these things really, you just have to dig in and explore it yourself.</p><p>Let’s look at some harder example which is number of votes for ratings. The hard part comes from the fact that they present the information in abbreviation. For example if a movie has 1.700.000 votes it is given to us like ‘1.7M’. So we have to go an extra mile and strip the M and multiply it with 1.000.000 for compensation. But what if it doesn’t have millions of votes, rather, say 1.000 votes; in which case it would have written like ‘1K’, and if it has neither million nor thousand vote, than we can take the value as is.</p><pre>if &#39;M&#39; in votes:<br>    votes = int(float(votes.split(&#39;M&#39;)[0])*1_000_000)                                     elif &#39;K&#39; in votes:<br>    votes = int(float(votes.split(&#39;K&#39;)[0])*1_000)                                     else:<br>    votes = int(votes)</pre><p>This code could have been written better, but the main purpose is to give an idea of how the process can be engineered.</p><p>As to how did we even get to the vote data; we used series of tags to reach to our destination. Which as we can see below, first comes the <em>div</em> tag with an attribute <em>data-testid</em>, next comes a link tag <em>a</em>, after that we have a two <em>div</em> tags back to back that contains tree more div tag inside and we have to take the second(item of the list[1]) <em>div</em> and inside that there are tree more <em>div</em> tags and our data is in the third one(so as in list item[2]) and then get it’s value as with .text, so;</p><pre>html.find(&#39;div&#39;, {&quot;data-testid&quot;:&quot;ero-rating-bar__aggregate-rating&quot;})<br>.a.div.div.findAll(&#39;div&#39;)[1].findAll(&#39;div&#39;)[2].text</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-UyCDdj179UHrH7i9RAfg.jpeg" /></figure><p>This process can be done to scrape every data your eyes can see on a web page. And we throw some <em>try:</em> and <em>except:</em> here and there so our scraping doesn’t get interrupted just because there was no budget data provided for the movie(I’m talking to you Babam ve Oğlum!).</p><p>After all that, we get to make a Data Frame out of our records using <em>pandas</em> and save it as a <em>csv</em> file so we don’t need to scrape everything every time we restart the notebook.</p><p>And now let’s take a look at our beautiful data frame!</p><pre>dfMovies.info()</pre><pre>&lt;class &#39;pandas.core.frame.DataFrame&#39;&gt;<br>RangeIndex: 250 entries, 0 to 249<br>Data columns (total 12 columns):<br> #   Column       Non-Null Count  Dtype         <br>---  ------       --------------  -----         <br> 0   Title        250 non-null    object        <br> 1   Revenues     241 non-null    float64       <br> 2   Budget       222 non-null    float64       <br> 3   Runtime      250 non-null    object        <br> 4   Certificate  250 non-null    object        <br> 5   ReleaseDate  250 non-null    datetime64[ns]<br> 6   Score        250 non-null    int64         <br> 7   Votes        250 non-null    int64         <br> 8   Directors    250 non-null    object        <br> 9   Writers      250 non-null    object        <br> 10  Stars        250 non-null    object        <br> 11  Genres       250 non-null    object        <br>dtypes: datetime64[ns](1), float64(2), int64(2), object(7)<br>memory usage: 23.6+ KB</pre><h4>This concludes the Web-Scraping part of our project.</h4><h3>Exploratory Data Analysis</h3><p>Coming soon.</p><h3>Modelling</h3><p>~</p><h3>Results</h3><p>~</p><h3>Conclusion</h3><p>~</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c75874243bdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>